2

我来自 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"];

当然有更简单的方法......或者这真的是我的命运吗?

4

1 回答 1

3

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

NSMutableDictionary *petalData = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"startPoint", [NSNumber numberWithInt:12], @"endPoint", nil];
于 2010-08-12T12:16:18.227 回答