Pergunta

Eu sou de um fundo flash ActionScript. De onde eu sou, posso definir um objeto semelhante ao dicionário como este:

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

Então, chegando ao Objective-C, fiquei surpreso ao descobrir que o equivalente a isso parece ser:

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

Certamente há uma maneira mais fácil ... ou esse é realmente o meu lote?

Foi útil?

Solução

Esta é a única maneira mais curta que consigo pensar:

NSMutableDictionary *petalData = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"startPoint", [NSNumber numberWithInt:12], @"endPoint", nil];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top