-1

我创建了一个包含用户和设备信息的类。类称为Account. 这是课程代码(ARC项目):

#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 = @"rf@gmmail.com";
_ac.type = @"rf@gmmail.com";
_ac.oAuthCode = @"rf@gmmail.com";
_ac.deviceName = @"rf@gmmail.com";
_ac.deviceToken = @"rf@gmmail.com";
_ac.deviceID = @"rf@gmmail.com";
_ac.os = @"rf@gmmail.com";

比我将此对象作为方法的参数传递:

    [self appendAccount:_ac];

当我试图读取Account实例时,他的字段是。

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

有任何想法吗 ?

4

2 回答 2

1

这是因为您没有设置器来反映吸气剂。该值写入 _deviceid,但从 thinkerbell 读取...

于 2013-08-25T11:36:56.983 回答
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;

(你可能是从旧的示例代码中得到的,我建议找一些更新和最新的东西)

于 2013-08-25T12:05:06.063 回答