'Xcode'에 해당되는 글 3건

  1. 2012.05.04 [setting.bundle] multivalue 동적으로 추가하기
  2. 2011.10.13 window와 _window의 차이
  3. 2011.08.21 NS Collection

세팅 번들의 멀티밸류 값이 고정되어 있는 것이 아니라 사용자 필요에 의해 변경될 경우가 있다. 

나의 경우에는 길이나 넓이 단위를 사용자가 추가할 경우가 있는데, 이럴 경우 세팅 번들의 멀티 밸류항목에도 추가 시켜줘야하는 상황이 발생한다.  


hedar file  정의 : userDefaultSet.h

#import <Foundation/Foundation.h>


@interface UserDefaultSet : NSObject

{

    NSString *_strSettingBundlePath;

    NSMutableDictionary *_rootPList;

    

}


-(void) saveSettings;

-(void) loadSettings;


-(BOOL) setUserDefaultMultiValue:(NSString *)strID key:(id)keyArray value:(id)valueArray;

-(void) saveUserDefaultSet;


@end


 source file :UserDefaultSet.m

#import "UserDefaultSet.h"


@implementation UserDefaultSet


-(id) init

{

    if(self = [super init])

    {

        NSString* settingsBundle = [[[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"] stringByAppendingPathComponent:@"Root.plist"];

        _strSettingBundlePath = [[NSString alloc] initWithFormat:@"%@",settingsBundle];

        

        NSDictionary *settingsPropertyList = [NSDictionary dictionaryWithContentsOfFile:_strSettingBundlePath];

        _rootPList = [[NSMutableDictionary alloc] initWithDictionary:settingsPropertyList];

        

    }    

    return self;       

}


-(void) dealloc

{

    [_strSettingBundlePath release];

    [_rootPList release];

    

    [super dealloc];

 }


-(void) saveSettings

{

    

}

-(void) loadSettings

{

    

}


- (BOOL) setUserDefaultMultiValue:(NSString *)strID key:(id)keyArray value:(id)valueArray 

{

    NSMutableArray* specifiers = [_rootPList objectForKey:@"PreferenceSpecifiers"];

//    NSMutableDictionary *multiValueSpecifier = [[NSMutableDictionary alloc] init];

    NSDictionary *multiValueSpecifier;    

    

    for (NSDictionary *specifier in specifiers)

    {

        if ([[specifier objectForKey:@"Key"] isEqualToString:strID] == YES &&

            [[specifier objectForKey:@"Type"] isEqualToString:@"PSMultiValueSpecifier"] == YES)

        {

            multiValueSpecifier = specifier;    

            break;

        }

    }

    

    if (multiValueSpecifier == nil)

        return FALSE;

    

    [multiValueSpecifier setValue:valueArray forKey:@"Values"];

    [multiValueSpecifier setValue:keyArray forKey:@"Titles"];

    

    NSLog(@"=== rootPlist:%@", _rootPList);    

    

    return [_rootPList writeToFile:_strSettingBundlePath atomically:YES];    

}


'아이폰개발 > Tip &amp; Tech' 카테고리의 다른 글

[XCode] bounds와 fame의 차이  (0) 2012.02.10
mainWindow.xib 사용하지 않고 어플 개발하기  (0) 2011.12.07
window와 _window의 차이  (0) 2011.10.13
FlipView구현 및 Toolbar 넣기  (0) 2011.10.13
NS Collection  (0) 2011.08.21
Posted by 꿈을펼쳐라
,

기존 XCode 3.x대에서 작성되었던 소스파일을 갖고 와서 XCode 4.x에서 작업을 하는데, 컴파일까지는 잘되는데 의도된 데로 실행되지 않는 경우가 발생하여 2시간 여를 끙끙 앓다가 해결된 문제다 .

[선언]
@interface
 TestAppDelegate : NSObject <UIApplicationDelegate> {

    IBOutlet UIWindow*          window;    => 기존 XCode 3.x에서 선언한 변수

}

@property (nonatomicretainIBOutlet UIWindow *window;

@end



[구현]

@synthesize window=_window;       => XCode 4.x Template

@synthesize viewController;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    // 윈도우 표시

    [_window addSubview:viewController.view];

    [self.window makeKeyAndVisible];


위에서 구현부에서 사용했던, _window나  self.window는 결국 내가 선언한 window변수가 아닌 iOS내부변수인 _window를 사용하고 있는 듯하다. 

결국 이 문제는 선언부에서 "IBOutlet UIWindow*          _window;"로 수정하면서 말끔히 해결 됐다. 

 

@synthesize window=_window;  으로 선언했다면  

self.window를 통해  _window 변수에 접근하겠다는 선언이다.  
Posted by 꿈을펼쳐라
,
NSArray류의 Collection은 NSObject에서 상속받은 객체만 넣을 수 있다.


1. NSObject에서 상속 받은 객체만을 담을 수 있음 
  - 일반 자료형이나 구조체, 클래스는 넣을 수 없음
  - int 형을 넣기위한 방법

NSNumber *a = [NSNumber alloc] initWithInt:100];

NSArray *array = [NSArray arrayWithObjects: a, nil];

[a release];


2. 메모리 해제
  [NSArray arrayWithObject:...] 컨비넌스 컨스트럭터

[NSArray alloc] init...]으로 만든 객체는 개발자가 직접 release 주어야 하는 것과는 달리, 컨비년스 컨스트럭터로 생성한 객체는 Auto Release Pool이라는 곳에 등록되기 때문에 나중에 자동으로 해제가 됩니다.

임시 객체 용도로 간단하게 사용하기 위해 사용한다고 생각하면 됩니다. (Auto release Pool 던져지니 수동으로 release하면 안됩니다!)


'아이폰개발 > Tip &amp; Tech' 카테고리의 다른 글

window와 _window의 차이  (0) 2011.10.13
FlipView구현 및 Toolbar 넣기  (0) 2011.10.13
[아이폰 시뮬레이터] 물리적 파일 위치  (0) 2011.08.15
Mac 단축키 정리  (0) 2011.07.30
[Object-C] 화면 캡쳐 방법  (0) 2010.07.30
Posted by 꿈을펼쳐라
,