iEngineer
iEngineer

Reputation: 1319

iOS 8: NSDictionary 0 key/value pairs

Believe me or not, it's the real case. I'm creating a simple NSDictionary in my app and it was working fine. Today I installed Xcode 6 beta and try to run my app with iOS 8. NSDictionary returns 0 key/value pairs while I can see same dictionary works fine in iOS 6 and in iOS 7. Here is the code of that dictionary,

NSDictionary *croppedPhoto = [[NSDictionary alloc] initWithObjectsAndKeys:myImageView.image,@"original",imageView.image,@"cropped", nil];  

NOTE: myImageView and imageView both are UIImageView and I can see the image there in debug mode.
I don't know if something changed in iOS 8 regarding NSDictionary. Appreciate any kind of help in advance. Thanks.

Upvotes: 1

Views: 2376

Answers (2)

Fogmeister
Fogmeister

Reputation: 77661

Change to this code and see what happens...

NSDictionary *croppedPhoto = @{
    @"original" : myImageView.image,
    @"cropped"  : imageView.image
};

You should be using this format anyway. It has been around for 2 years now.

Also, it includes run time validation that all the objects are not nil.

If myImageView.image is nil then your code will return a dictionary with no keys or objects, this modern syntax will crash showing you that it is nil.

Upvotes: 4

Cyrille
Cyrille

Reputation: 25144

Does it work if you use modern syntax?

NSDictionary *croppedPhoto = @{
    @"original": myImageView.image,
    @"cropped":  imageView.image
}

(Which is, admit it, much more readable).

Upvotes: 1

Related Questions