1

An argument of my dictionary looks to be nil but i have no idea why... I've browsed SOF and all propositions are like this.

CGSize size;
if ([[[UIDevice currentDevice] systemVersion] 
                compare:@"7.0" options:NSNumericSearch] == NSOrderedAscending) {
    // here it works
    size = [string sizeWithFont:[UIFont fontWithName:@"HelveticaNeue-Italic" 
                                                size:15.0f]];
} else {
    // here it crashes
    size = [string sizeWithAttributes:
       [NSDictionary dictionaryWithObject:[UIFont fontWithName:@"HelveticaNeue-Italic" 
                                     size:15.0f] forKey:NSFontAttributeName]];
}

// console output

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: 
attempt to insert nil object from objects[0]'
Nat
  • 12,032
  • 9
  • 56
  • 103
  • 2
    See also [What happened to “HelveticaNeue-Italic” on iOS 7.0.3](http://stackoverflow.com/questions/19527962/what-happened-to-helveticaneue-italic-on-ios-7-0-3) – Martin R Nov 14 '13 at 08:24
  • @MartinR than you for your comment. If you post it as an answer I'll accept it. Or the question may be closed as a duplicate. – Nat Nov 14 '13 at 08:35
  • Err, no. Duplicate questions don't require an accepted answer. – trojanfoe Nov 14 '13 at 08:39
  • @trojanfoe That's why i wrote 'or' ;) Anyway, voted to close my question. – Nat Nov 14 '13 at 08:41

1 Answers1

2
[UIFont fontWithName:@"HelveticaNeue-Italic" size:15.0f]

returns nil (no longer available) hence you are essentially doing

[NSDictionary dictionaryWithObject:nil forKey:NSFontAttributeName];

which raises an exception.

jbat100
  • 16,757
  • 4
  • 45
  • 70
  • 2
    Why not simply vote for the dupe indicated my @MartinR? – trojanfoe Nov 14 '13 at 08:27
  • I have, just adding the reason for the exception when creating the dictionary, which may not be obvious to the OP given how he phrased the question... – jbat100 Nov 14 '13 at 08:29
  • After reading the attached link i saw what happened and didn't need more explanation. Your comment is rather harsh given that i simply asked a question and got the response. The answer from @MartinR is enough for everyone. – Nat Nov 14 '13 at 08:35
  • I really meant no offence. – jbat100 Nov 14 '13 at 08:35