Runtime errors when using with swift
dcunited001 opened this issue · 6 comments
However, I'm still getting runtime errors with FontAwesomeKit. The following crashes on the first line. I posted my setup information in #46
let playIcon = FAKFontAwesome.playIconWithSize(15)
print(playIcon.attributedString())
self.btnPlay.titleLabel?.attributedText = playIcon.attributedString()
Is this something that can be easily addressed? I need to get my app running in the simulator again, I'll post the error message soon.
here's the line of code causing the crash:
icon.mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:code attributes:@{NSFontAttributeName: [self iconFontWithSize:size]}];
here's the crash i'm getting in the simulator:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010b1559b5 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010cf7adeb objc_exception_throw + 48
2 CoreFoundation 0x000000010b0589de -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 318
3 CoreFoundation 0x000000010b06ad2b +[NSDictionary dictionaryWithObjects:forKeys:count:] + 59
4 FontAwesomeKit 0x000000010a6d300a +[FAKIcon iconWithCode:size:] + 189
5 Voxxel 0x000000010a42d919 _TToFC6Voxxel16RecordController11viewDidLoadfS0_FT_T_ + 745
6 UIKit 0x000000010bd1ed05 -[UIViewController loadViewIfRequired] + 877
7 UIKit 0x000000010bd24e33 -[UIViewController __viewWillAppear:] + 120
8 UIKit 0x000000010bd51cba -[UINavigationController _startCustomTransition:] + 1177
9 UIKit 0x000000010bd612f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
10 UIKit 0x000000010bd621ad -[UINavigationController __viewWillLayoutSubviews] + 57
11 UIKit 0x000000010bef42d1 -[UILayoutContainerView layoutSubviews] + 248
12 UIKit 0x000000010bc45a3b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710
13 QuartzCore 0x0000000111c6936a -[CALayer layoutSublayers] + 146
14 QuartzCore 0x0000000111c5dbd0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
15 QuartzCore 0x0000000111c5da4e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
16 QuartzCore 0x0000000111c521d5 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
17 QuartzCore 0x0000000111c7f9f0 _ZN2CA11Transaction6commitEv + 508
18 UIKit 0x000000010bb93556 _UIApplicationHandleEventQueue + 7183
19 CoreFoundation 0x000000010b081b21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x000000010b077a4c __CFRunLoopDoSources0 + 556
21 CoreFoundation 0x000000010b076f03 __CFRunLoopRun + 867
22 CoreFoundation 0x000000010b076918 CFRunLoopRunSpecific + 488
23 GraphicsServices 0x0000000111b30ad2 GSEventRunModal + 161
24 UIKit 0x000000010bb9899e UIApplicationMain + 171
25 Voxxel 0x000000010a3f2505 main + 117
26 libdyld.dylib 0x000000010e46092d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
i think this error has something to do with the lazy-loading issues mentioned in the Known Issues. However, I have my podfile setup to use_frameworks in my project, so I'm not sure I can set the the compile time DISABLE_FONTAWESOME_AUTO_REGISTRATION
directive. I might be able to define that in my bridging header, but i still don't know how to manually register the icon fonts.
I've tried adding the following to my AppDelegate application didFinishLoading, but i still get the same crash when I try to use the font in my Controller.
FAKFontAwesome.iconFontWithSize(1)
If you look at the code in +[FAKIcon iconWithCode:size:]
, the likely culprit is that +iconFontWithSize:
is returning a nil
font. Since you also mention you're using frameworks, my guess is that you're hitting a bug that was fixed in January of this year, but for some reason there has not been a release since then. If you install via Cocoapods and don't reference a specific commit, you will still crash. The problem is that the buggy code is trying to load the font file via the main bundle, but when using frameworks, those fonts are in the framework's bundle.
Try replacing your pod reference with this:
pod 'FontAwesomeKit/FontAwesome', :git => 'https://github.com/PrideChung/FontAwesomeKit', :commit => 'ac17a6c'
@PrideChung: have you considered releasing a new version so the bundle loading fix is more easily available?
@sjmadsen Yes, I do planning a new version to fix this problem but still can't make it work on watchOS.
I just ran into this issue too. Thank you for the fix. Hope to see a new release soon.
I tried using 2.2.0, and it seems to have this issue still when using it with frameworks. I took the known issues into account. Has this been migrated to 2.2.0?