5

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

enter image description here

Here's how it looks in Xcode before:

enter image description here

Then when I Step over:

enter image description here

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?

Community
  • 1
  • 1
Snowcrash
  • 80,579
  • 89
  • 266
  • 376

3 Answers3

3

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.)

Hot Licks
  • 47,103
  • 17
  • 93
  • 151
0

0x00000001 indicates an invalid memory address. What version of Xcode are you using? You may need to switch from lldb to gdb

JoeCortopassi
  • 5,083
  • 7
  • 37
  • 65
0

I have seen 0x00000001 in lldb when im stepping through code like this:

labelAttrs = [self someMethod];

If you print labelAttrs, before having evaluated the -someMethod, then it will be assigned to 0x00000001.

neoneye
  • 50,398
  • 25
  • 166
  • 151