Domanda

Sono da un background di Flash ActionScript. Da dove vengo, posso impostare un dizionario-come oggetto in questo modo:

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

Quindi, venendo a Objective-C, sono stato sorpreso di scoprire che l'equivalente di questo sembra essere:

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

Sicuramente c'è un modo più semplice ... O è che in realtà il mio destino?

È stato utile?

Soluzione

Questo è il modo più breve solo mi viene in mente:

NSMutableDictionary *petalData = [NSMutableDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:5], @"startPoint", [NSNumber numberWithInt:12], @"endPoint", nil];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top