これは目に見える問題なく動作します。このコードに問題はありますか?
データ オブジェクト
#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