_SwiftValue ctFontRef无法识别的选择器发送到实例

时间:2016-11-04 08:50:25

标签: ios swift nsmutableattributedstring

这是代码:

let sub1 = subsessions[0]
let titleText = NSMutableAttributedString(string: String(format: "%@\n%@", session.Title, sub1.Subtitle))
titleText.addAttribute(NSFontAttributeName, value: UIFont(name: "AppleGaramond-Italic", size: 23), range: NSMakeRange(0, session.Title.characters.count))
titleText.addAttribute(NSFontAttributeName, value: UIFont(name: "AppleGaramond-BoldItalic", size: 23), range: NSMakeRange(session.Title.characters.count + 1, sub1.Subtitle.characters.count))
titleText.addAttribute(NSForegroundColorAttributeName, value: UIColor.white, range: NSMakeRange(0, titleText.length))
label_title.attributedText = titleText 

我从来没有在这段代码中得到异常,但是当我继续调试时,我得到了崩溃。 当我用NSFontAttributeName注释行时,异常永远不会出现。所以这绝对是这两条线的问题 我正在Swift 3上运行。

Stack backtrace:

enter image description here

* thread #1: tid = 0x20b0e, 0x25237c5c libsystem_kernel.dylib`__pthread_kill + 8, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
    frame #0: 0x25237c5c libsystem_kernel.dylib`__pthread_kill + 8
    frame #1: 0x252ddb46 libsystem_pthread.dylib`pthread_kill + 62
    frame #2: 0x251cc0c4 libsystem_c.dylib`abort + 108
    frame #3: 0x24d427dc libc++abi.dylib`abort_message + 108
    frame #4: 0x24d5b6a0 libc++abi.dylib`default_terminate_handler() + 268
    frame #5: 0x24d67098 libobjc.A.dylib`_objc_terminate() + 192
    frame #6: 0x24d58e16 libc++abi.dylib`std::__terminate(void (*)()) + 78
    frame #7: 0x24d588f6 libc++abi.dylib`__cxa_rethrow + 102
    frame #8: 0x24d66f46 libobjc.A.dylib`objc_exception_rethrow + 42
    frame #9: 0x254b824e CoreFoundation`CFRunLoopRunSpecific + 650
    frame #10: 0x254b7fbc CoreFoundation`CFRunLoopRunInMode + 108
    frame #11: 0x26ad4af8 GraphicsServices`GSEventRunModal + 160
    frame #12: 0x29bf2434 UIKit`UIApplicationMain + 144
  * frame #13: 0x000b8298 PPOnlineClient`main + 172 at AppDelegate.swift:13
    frame #14: 0x25164872 libdyld.dylib`start + 2

0 个答案:

没有答案