试图在 NSDictionary 中存储值并检索它
对象
#import <Foundation/Foundation.h>
@class ATTTEstOBJ;
@interface ATTTEst : NSObject
@property (nonatomic, retain) NSString *string1;
@property (nonatomic, retain) NSString *string2;
@property (nonatomic, retain) ATTTEstOBJ *obj1;
@end
@interface ATTTEstOBJ : NSObject
@property (nonatomic, retain) NSString *string3;
@property (nonatomic, retain) NSString *string4;
@property (nonatomic, retain) NSString *array1;
@end
我知道它需要正确编码才能保存和检索值。但在这种情况下,它是一个复合对象,我不知道如何处理它。
- (void) encodeWithCoder: (NSCoder *)coder
所以 TLDR ,如何将复合值保存到字典中并检索回来
我想存储ATTTest
到字典中并取回它。
编辑:详细说明
ATTTEst *test=[[ATTTEst alloc]init];
test.string1=@"a";
test.string2=@"b";
ATTTEstOBJ *obj=[[ATTTEstOBJ alloc]init];
obj.string3=@"c";
obj.string4=@"d";
test.obj1=obj;
NSMutableDictionary *dict=[[NSMutableDictionary alloc]initWithCapacity:3];
[dict setObject:test forKey:@"test"];
NSLog(@"%@",dict);
ATTTEst *tester=[dict objectForKey:test];
NSLog(@"%@",tester.obj1.string3);
IT 显示 null.as 输出我想将值作为 c 获取tester.obj1.string3