我从Flash ActionScript中的背景很。我来自哪里,我可以设置一个类似于字典的这样的对象:

var data:Object = {startPoint:5, endPoint:12};

所以来的Objective-C,我惊讶地发现,相当于这似乎是:

NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data setObject:[NSNumber numberWithInt:5] forKey:@"startPoint"];
[data setObject:[NSNumber numberWithInt:12] forKey:@"endPoint"];

当然还有一个更简单的方法...或者是真的我的很多吗?

有帮助吗?

解决方案

这是唯一的短方式我能想到的:

NSMutableDictionary *petalData = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"startPoint", [NSNumber numberWithInt:12], @"endPoint", nil];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top