这工作没有明显的问题。这段代码有什么问题吗?
数据对象
#import <Foundation/Foundation.h>
@interface CustomDataObject : NSObject
@property (strong, nonatomic) NSString *name;
@property (strong, nonatomic) NSDictionary *additionalProperties;
@end
#import "CustomDataObject.h"
@implementation CustomDataObject
- (id)init
{
self = [super init];
if (self)
{
self.name = @"FirstName LastName";
self.additionalProperties = @{@"amount" : @"1000",
@"state" : @"happy"};
}
return self;
}
@end
类别
#import "CustomDataObject.h"
@interface CustomDataObject (additionalProperties)
@property (assign, nonatomic, readonly) NSString *amount;
@property (assign, nonatomic, readonly) NSString *state;
@end
#import "CustomDataObject+additionalProperties.h"
@implementation CustomDataObject (additionalProperties)
-(NSString *)amount
{
return [self.additionalProperties objectForKey:@"amount"];
}
-(NSString *)state
{
return [self.additionalProperties objectForKey:@"state"];
}
@end
VIEWCONTROLLER 和输出
CustomDataObject *myObject = [[CustomDataObject alloc] init];
NSLog(@"%@", myObject.name);
NSLog(@"%@", myObject.amount);
NSLog(@"%@", myObject.state);
-----
2013-07-25 15:44:01.790 CatTest[30911:c07] FirstName LastName
2013-07-25 15:44:03.487 CatTest[30911:c07] 1000
2013-07-25 15:44:03.984 CatTest[30911:c07] happy