2013-08-25 3 views
-2

사용자 및 장치 정보를 보유 할 클래스를 만들었습니다. Account 클래스. 여기cant initilize 맞춤 클래스

#import <Foundation/Foundation.h> 
@interface Account : NSObject 
@property(strong, nonatomic) NSString *deviceID; 
@property(strong, nonatomic) NSString *accountID; 
@property(strong, nonatomic) NSString *oAuthCode; 
@property(strong, nonatomic) NSString *type; 
@property(strong, nonatomic) NSString *deviceToken; 
@property(strong, nonatomic) NSString *os; 
@property(strong, nonatomic) NSString *deviceName; 
@end 



#import "Account.h" 

@implementation Account 

@synthesize deviceID = _deviceID; 
@synthesize deviceName = _deviceName; 
@synthesize deviceToken = _deviceToken; 
@synthesize type = _type; 
@synthesize oAuthCode = _oAuthCode; 
@synthesize accountID = _accountID; 
@synthesize os = _os; 



-(NSString*)deviceID{ 
    return [ThinkerBell_OpenUDID value]; 
} 

-(NSString*)deviceToken{ 
    return [[NSUserDefaults standardUserDefaults]valueForKey:K_DEVICE_TOKEN]; 
} 

-(NSString*)os{ 
    return [[UIDevice currentDevice]systemVersion]; 
} 

-(NSString*)deviceName{ 
    return [[UIDevice currentDevice]model]; 
} 
@end 

내가 인스턴스를 생성하고 자신의 속성에 액세스하려고 : 내가하는 방법에 매개 변수로이 객체를 전달하고보다

_ac = [[Account alloc]init]; 
_ac.accountID = @"[email protected]"; 
_ac.type = @"[email protected]"; 
_ac.oAuthCode = @"[email protected]"; 
_ac.deviceName = @"[email protected]"; 
_ac.deviceToken = @"[email protected]"; 
_ac.deviceID = @"[email protected]"; 
_ac.os = @"[email protected]mmail.com"; 

여기 은 (ARC 프로젝트) 클래스 코드 :

[self appendAccount:_ac]; 

Account 인스턴스의 필드를 읽으려고 할 때.

-(void)appendAccount:(Account*)account{ 
    NSLog(@"%@",account); 
} 

아이디어가 있으십니까?

+0

이 코드가 어떻게 생각하는지 명확히하십시오 ... – Eiko

답변

1

클래스에 "설명"메소드가 구현되어 있지 않으므로 NSLog에 인쇄 할 수있는 것이 없습니다. 또한,

@implementation Account 

- (NSString *)description 
{ 
    return [NSString stringWithFormat:@"<Account ID %@>", self.accountID]; 
} 

@end 

을 코드, 그들은 일반적으로 필요하지 않습니다 이러한 행을 삭제하고 문제가 발생할 수 있습니다 :

@synthesize deviceID = _deviceID; 
@synthesize deviceName = _deviceName; 
@synthesize deviceToken = _deviceToken; 
@synthesize type = _type; 
@synthesize oAuthCode = _oAuthCode; 
@synthesize accountID = _accountID; 
@synthesize os = _os; 

(당신은 아마 기존의 것을 가지고 여기

당신이 그것을 할 수있는 방법 예제 코드, 더 최근의 뭔가를 찾는 것이 좋습니다.)

1

getters를 반영하는 세터가 없어서입니다. 값은 _deviceid에 기록되지만 thinkerbell에서 읽습니다.

+0

그래서 모든 getter에 setter도 써야합니까? –

+0

@orazran 아니오, 당신은 getter 또는 setter를 작성할 필요가 거의 없습니다. –

+0

@AbhiBeckert, topic starter가 합성 getter를 반영하지 않는 값을 반환하는 getter를 쓰면 _var에 쓰도록 setter를 호출하면 전혀 쓸모가 없습니다. –