美文网首页
macOS开发之Assertion failure in -NS

macOS开发之Assertion failure in -NS

作者: chasitu | 来源:发表于2021-03-10 11:47 被阅读0次

    今天遇到一个小bug,这个问题的内部原因其实也是很简单,但是这个报错看着有点陌生,简单记录一下吧

    问题

    Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], NSCell.m:1312

    报错明细

    2021-03-10 11:39:00.036817+0800 Tangce_macOS[1976:77113] *** Assertion failure in -[NSTextFieldCell _objectValue:forString:errorDescription:], NSCell.m:1312
    2021-03-10 11:39:00.037074+0800 Tangce_macOS[1976:77113] [General] Invalid parameter not satisfying: aString != nil
    2021-03-10 11:39:00.042603+0800 Tangce_macOS[1976:77113] [General] (
        0   CoreFoundation                      0x00007fff204a96af __exceptionPreprocess + 242
        1   libobjc.A.dylib                     0x00007fff201e13c9 objc_exception_throw + 48
        2   CoreFoundation                      0x00007fff204d2512 +[NSException raise:format:arguments:] + 88
        3   Foundation                          0x00007fff2128b6c9 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
        4   AppKit                              0x00007fff22c8610d -[NSCell _objectValue:forString:errorDescription:] + 258
        5   AppKit                              0x00007fff22c85f6b -[NSCell setStringValue:] + 44
        6   AppKit                              0x00007fff22cfeb17 -[NSControl setStringValue:] + 121
        7   Tangce_macOS                        0x000000010e710959 -[SHClassViewItem setStudentModel:] + 601
        8   Tangce_macOS                        0x000000010e74149c -[SHClassViewController collectionView:itemForRepresentedObjectAtIndexPath:] + 492
        9   AppKit                              0x00007fff22e5d8be -[_NSCollectionViewDataSourceAdapter collectionView:itemForRepresentedObjectAtIndexPath:] + 435
        10  UIFoundation                        0x00007fff239b4913 -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 100
        11  UIFoundation                        0x00007fff239b48a9 -[_NSCollectionViewCore _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31
        12  UIFoundation                        0x00007fff2399bf66 -[_NSCollectionViewCore _updateVisibleCellsNow:] + 4435
        13  UIFoundation                        0x00007fff23990281 -[_NSCollectionViewCore _layoutItems] + 285
        14  AppKit                              0x00007fff22e4dff2 -[NSCollectionView layout] + 343
        15  AppKit                              0x00007fff22ca15ad _NSViewLayout + 603
        16  AppKit                              0x00007fff22ca1043 -[NSView _layoutSubtreeWithOldSize:] + 392
        17  AppKit                              0x00007fff22ca11a2 -[NSView _layoutSubtreeWithOldSize:] + 743
        18  AppKit                              0x00007fff22ca11a2 -[NSView _layoutSubtreeWithOldSize:] + 743
        19  AppKit                              0x00007fff22ca11a2 -[NSView _layoutSubtreeWithOldSize:] + 743
        20  AppKit                              0x00007fff22ca11a2 -[NSView _layoutSubtreeWithOldSize:] + 743
        21  AppKit                              0x00007fff22ca11a2 -[NSView _layoutSubtreeWithOldSize:] + 743
        22  AppKit                              0x00007fff22ca04e3 -[NSView _layoutSubtreeIfNeededAndAllowTemporaryEngine:] + 1041
        23  AppKit                              0x00007fff22c9ffe3 -[NSWindow(NSConstraintBasedLayout) _layoutViewTree] + 148
        24  AppKit                              0x00007fff22d1cf43 -[NSWindow(NSConstraintBasedLayout) layoutIfNeeded] + 251
        25  AppKit                              0x00007fff22d1cd80 __NSWindowGetDisplayCycleObserverForLayout_block_invoke + 430
        26  AppKit                              0x00007fff22d1bff5 NSDisplayCycleObserverInvoke + 155
        27  AppKit                              0x00007fff22d1bb7f NSDisplayCycleFlush + 937
        28  QuartzCore                          0x00007fff26bb605a _ZN2CA11Transaction19run_commit_handlersE18CATransactionPhase + 92
        29  QuartzCore                          0x00007fff26bb4e00 _ZN2CA11Transaction6commitEv + 382
        30  AppKit                              0x00007fff22dcb9cb __62+[CATransaction(NSCATransaction) NS_setFlushesWithDisplayLink]_block_invoke + 285
        31  AppKit                              0x00007fff23515d0e ___NSRunLoopObserverCreateWithHandler_block_invoke + 41
        32  CoreFoundation                      0x00007fff2042ed9d __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
        33  CoreFoundation                      0x00007fff2042ec2d __CFRunLoopDoObservers + 549
        34  CoreFoundation                      0x00007fff2042e0dd __CFRunLoopRun + 838
        35  CoreFoundation                      0x00007fff2042d6be CFRunLoopRunSpecific + 563
        36  HIToolbox                           0x00007fff28699fd0 RunCurrentEventLoopInMode + 292
        37  HIToolbox                           0x00007fff28699dcc ReceiveNextEventCommon + 709
        38  HIToolbox                           0x00007fff28699aef _BlockUntilNextEventMatchingListInModeWithFilter + 64
        39  AppKit                              0x00007fff22c46f85 _DPSNextEvent + 883
        40  AppKit                              0x00007fff22c4574b -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1366
        41  AppKit                              0x00007fff22c37bda -[NSApplication run] + 586
        42  AppKit                              0x00007fff22c0bf31 NSApplicationMain + 816
        43  Tangce_macOS                        0x000000010e7172fd main + 141
        44  libdyld.dylib                       0x00007fff20352631 start + 1
        45  ???                                 0x0000000000000003 0x0 + 3
    )
    

    解决:主要原因是NSTextFieldCell赋值的时候模型的属性是空值导致的

    • Invalid parameter not satisfying: aString != nil重点就是明细里面的这句话,字符串赋值不能为空
    • 后端在接口上返回数据的时候因为该字段没有值直接就没有返回这个字段,json数据里面就没有这个字段,不知道是什么习惯,解析的时候就导致了空值,赋值的时候就崩溃了

    知道原因了之后大家应该会解决了哈,就是做一个非空判断就行

    相关文章

      网友评论

          本文标题:macOS开发之Assertion failure in -NS

          本文链接:https://www.haomeiwen.com/subject/sckwqltx.html