0

When my project in debug mode ,everything work fine. But when I change to release mode, my app crash at

[_menuButton setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:kFontAwesomeFamilyName size:30.0],
                                     NSForegroundColorAttributeName:[UIColor whiteColor]
                                     } forState:UIControlStateNormal];

the error message is

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'

If I commented the code , it can run fine but all FontAwesome icon became question mark.

Any idea to fix it ? Please help , thanks a lot !

Mia
  • 125
  • 1
  • 5

1 Answers1

1

As you can see, the error message warns you something becomes nil while inserting, so you need to check which object is nil.

There is a high possibility reason:

[UIFont fontWithName:kFontAwesomeFamilyName size:30.0]

In release mode, kFontAwesomeFamilyName cannot be recognized, or the font file is not bundled into your app, so fontWithName returns nil.

Wingzero
  • 9,644
  • 10
  • 39
  • 80
  • It is a library , I drag the source file to my projects . Why it cannot be recognized only in release mode? – Mia Jun 02 '15 at 02:17
  • there could be lots of reasons, like compile rules are different in release and debug mode. can you try print out `[UIFont fontWithName:kFontAwesomeFamilyName size:30.0]` in release mode? – Wingzero Jun 02 '15 at 02:18
  • check out http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/ and http://stackoverflow.com/questions/21737788/custom-fonts-in-ios-7 – Wingzero Jun 02 '15 at 02:19
  • I find out my Info.plist and Info_debug.plist have different setting on Fonts provided by application . It works fine now ! Thank you so much !! – Mia Jun 02 '15 at 02:32