In the course of following a howto online, I came across the following code:
NSDictionary *address = @{
(NSString *)kABPersonAddressStreetKey: _address.text,
(NSString *)kABPersonAddressCityKey: _city.text,
(NSString *)kABPersonAddressStateKey: _state.text,
(NSString *)kABPersonAddressZIPKey: _zip.text
};
Which will not compile in XCode 4.5.1. I get two errors:
What am I missing here? Also, where do I find documentation on this shortcut declaration of an NSDictionary object? It's awfully hard to Google syntax like this.
This is part of Obj-C Literals, introduced since LLVM 4.0. Make sure you are using the right version of iOS as well. Translated into original pre-llvm 4.0 language, the NSDictionary assignment would look like this:
NSDictionary *address = [[NSDictionary alloc] initWithObjectsAndKeys:
(NSString *)kABPersonAddressStreetKey, _address.text,
(NSString *)kABPersonAddressCityKey, _city.text,
(NSString *)kABPersonAddressStateKey, _state.text,
(NSString *)kABPersonAddressZIPKey, _zip.text,
nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With