Doing some debugging I printed out the description of an NSDictionary variable which gives this:
(NSDictionary *) labelAttrs = 0x00000001
Can someone clarify why this is 1
?
I'd understand nil
or an object pointer but why 1
?
UPDATE
The code:
NSDictionary *labelAttrs = @{NSForegroundColorAttributeName:[UIColor darkGrayColor]};
It crashes when run on iOS5 but not iOS6 but this:
Are the new object literals backwards compatible with iOS 5?
seems to say that you can use the new literals with iOS5 (as long as you build against iOS6 and use Xcode >= 4.5 and compile with latest LLVM - e.g see screen grab). And, according to Apple, I should be OK to use them: https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/ObjCAvailabilityIndex/index.html
Here's how it looks in Xcode before:
Then when I Step over:
Note: this gives me the same crash:
NSDictionary *labelAttrs = [NSDictionary dictionaryWithObjectsAndKeys:[UIColor darkGrayColor], NSForegroundColorAttributeName, [UIFont fontWithName:CUSTOMFONT size:size], NSFontAttributeName, [NSNumber numberWithInt:0], NSStrokeWidthAttributeName, nil];
Removing this (and the following 2 lines of code) means the app runs without crashing. But obviously no attributed strings.
UPDATE: resolved. Attributed strings aren't available on iOS5 (at least for UILabel's): Is NSAttributedString available before iOS 6?
The problem is that the NSAttributedString UIKit additions is not available until iOS 6. This means that the constants NSForegroundColorAttributeName et al are not defined. So the creation of the dictionary blows up trying to reference these.
(The way to debug this -- short of checking the reference for the wrong iOS version (;)) -- is to break up the statement:
UIColor* value1 = [UIColor darkGrayColor];
NSString* key1 = NSForegroundColorAttributeName;
UIFont* value2 = [UIFont fontWithName:CUSTOMFONT size:size];
NString* key2 = NSFontAttributeName;
NSNumber* value3 = [NSNumber numberWithInt:0];
NSString* key3 = NSStrokeWidthAttributeName;
NSDictionary *labelAttrs0 = [NSDictionary dictionaryWithObjectsAndKeys:nil];
NSDictionary *labelAttrs1 = [NSDictionary dictionaryWithObjectsAndKeys:value1, key1, nil];
NSDictionary *labelAttrs2 = [NSDictionary dictionaryWithObjectsAndKeys:value2, key2, nil];
NSDictionary *labelAttrs3 = [NSDictionary dictionaryWithObjectsAndKeys:value3, key3, nil];
Then see what fails. In this case you probably would have gotten a failure on assigning labelAttrs1. If you then were to NSLog value1 and key1 you would have gotten an error on key1.)
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