Objective c NSDictionary为键返回空值

Objective c NSDictionary为键返回空值,objective-c,ios,xcode,Objective C,Ios,Xcode,我很难理解为什么以下代码在控制台/终端中显示“第一个键=(null)”: 以下是界面: #import <UIKit/UIKit.h> @interface TestingViewController : UIViewController @property (nonatomic, strong) NSMutableArray *namesArray; @property (nonatomic, strong) NSDictionary *myDictionary; @end

我很难理解为什么以下代码在控制台/终端中显示“第一个键=(null)”:

以下是界面:

#import <UIKit/UIKit.h>

@interface TestingViewController : UIViewController

@property (nonatomic, strong) NSMutableArray *namesArray;
@property (nonatomic, strong) NSDictionary *myDictionary; 

@end

提前谢谢

您尚未分配词典。现在是
nil
,向nil发送消息没有任何作用

如果使用ARC,则将其改为此

self.myDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
如果不是这样的话

self.myDictionary = [[[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil] autorelease];

你还没有分配你的字典。现在是
nil
,向nil发送消息没有任何作用

如果使用ARC,则将其改为此

self.myDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
如果不是这样的话

self.myDictionary = [[[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil] autorelease];

工作!谢谢你今天给我上了非常宝贵的一课!工作!谢谢你今天给我上了非常宝贵的一课!