开发者

Adding data to an NSDictionary... SRSLY? Isn't there a quicker way?

开发者 https://www.devze.com 2023-01-11 12:05 出处:网络
I\'m from a Flash ActionScript background. Where I\'m from, I can set a dictionary-like object like this:

I'm from a Flash ActionScript background. Where I'm from, I can set a dictionary-like object like this:

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

So coming to Objective-C, I was surpr开发者_StackOverflowised to discover that the equivalent to this appears to be:

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

Surely there's an easier way... Or is that really my lot?


This is the only shorter way I can think of:

NSMutableDictionary *petalData = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"startPoint", [NSNumber numberWithInt:12], @"endPoint", nil];
0

精彩评论

暂无评论...
验证码 换一张
取 消