简体   繁体   English

NSInvalidArgumentException - [__ NSCFString unsignedLongLongValue]:发送到实例的无法识别的选择器

[英]NSInvalidArgumentException -[__NSCFString unsignedLongLongValue]: unrecognized selector sent to instance

While using JSONModel to parse my models I found this Exception. 在使用JSONModel解析我的模型时,我发现了这个异常。

NSInvalidArgumentException -[__NSCFString unsignedLongLongValue]: unrecognized selector sent to instance 0x1782210c0

The problem got place inside JSONModel.m because it depends on [NSObject setValue:forKey:] . 问题出现在JSONModel.m因为它依赖于[NSObject setValue:forKey:]

I found a way to easily reproducing it. 我找到了一种轻松复制它的方法。

@property NSUInteger uintegerProperty;
[...]
[self setValue:@"1" forKey:@"uintegerProperty"];

This works on 32 bits because setValue ends up calling longLongVaue defined in NSString , but in the case of 64 bits it's calling unsignedLongLongValue which is undefined in NSString . 这适用于32位,因为setValue最终调用在NSString定义的longLongVaue ,但在64位的情况下,它调用unsignedLongLongValue ,这在NSString中是未定义的。

In my particular case, the problem is this enum used in a model. 在我的特定情况下,问题是模型中使用的这个enum

typedef NS_ENUM(NSUInteger, kNotificationTypeEnum)
{
    kNotificationTypeResponse = 1,
    kNotificationTypeAlert = 2
};

What is the best way to handle this situation? 处理这种情况的最佳方法是什么?

Stack trace 堆栈跟踪

2014-12-31 17:48:43.789 mobile-iOS[17851:613] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString unsignedLongLongValue]: unrecognized selector sent to instance 0x10f1feeb0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000111b99495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001118f099e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000111c2a65d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000111b8ad8d ___forwarding___ + 973
    4   CoreFoundation                      0x0000000111b8a938 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x000000010ff2449b _NSSetUnsignedLongLongValueForKeyWithMethod + 63
    6   Foundation                          0x000000010fed5530 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    7   mobile-iOS                          0x000000010ee1834c -[AppDelegate application:didFinishLaunchingWithOptions:] + 140
    8   UIKit                               0x000000011051b3d9 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 264
    9   UIKit                               0x000000011051bbe1 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1605
    10  UIKit                               0x000000011051fa0c -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 660
    11  UIKit                               0x0000000110530d4c -[UIApplication handleEvent:withNewEvent:] + 3189
    12  UIKit                               0x0000000110531216 -[UIApplication sendEvent:] + 79
    13  mobile-iOS                          0x000000010eedf48b -[MMApplication sendEvent:] + 331
    14  UIKit                               0x0000000110521086 _UIApplicationHandleEvent + 578
    15  GraphicsServices                    0x0000000112df671a _PurpleEventCallback + 762
    16  GraphicsServices                    0x0000000112df61e1 PurpleEventCallback + 35
    17  CoreFoundation                      0x0000000111b1b679 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
    18  CoreFoundation                      0x0000000111b1b44e __CFRunLoopDoSource1 + 478
    19  CoreFoundation                      0x0000000111b44903 __CFRunLoopRun + 1939
    20  CoreFoundation                      0x0000000111b43d83 CFRunLoopRunSpecific + 467
    21  UIKit                               0x000000011051f2e1 -[UIApplication _run] + 609
    22  UIKit                               0x0000000110520e33 UIApplicationMain + 1010
    23  mobile-iOS                          0x000000010ee2af23 main + 243
    24  libdyld.dylib                       0x000000011230b5c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Signal: 6 (signal SIGABRT)

The finish solution to solve this problem: 解决此问题的完成解决方案:

@implementation NSString (UnsignedLongLongValue)

- (unsigned long long)unsignedLongLongValue {

    return self.longLongValue;
}

@end

Thanks! 谢谢!

The easiest way is probably to just use a shorter integer type for the property, like uint32_t. 最简单的方法可能是为属性使用较短的整数类型,如uint32_t。 The second easiest would be to add a category on NSString that provides the missing method. 第二个最简单的方法是在NSString上添加一个提供缺失方法的类别。

We had a similar error with iPhone 5 except that instead of unsignedLongLongValue we got longValue error. 我们在iPhone 5遇到了类似的错误,除了我们得到longValue错误而不是unsignedLongLongValue So we have used same category approach with following code: 所以我们使用了相同的类别方法和以下代码:

@implementation NSString (LongValue)

- (long)longValue {
    return (long) self.longLongValue;
}

@end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'NSInvalidArgumentException',原因:'-[__ NSCFString encodeString:]:无法识别的选择器已发送到实例 - 'NSInvalidArgumentException', reason: '-[__NSCFString encodeString:]: unrecognized selector sent to instance 'NSInvalidArgumentException',原因:'-[__ NSCFString objectAtIndex:]:无法识别的选择器已发送到实例 - 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 终止应用程序-'NSInvalidArgumentException',原因:'-[NSCFString objectForKey:]:无法识别的选择器已发送到实例 - Terminating app - 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance UIPickerView NSInvalidArgumentException',原因:“-[__ NSCFString超级视图]:无法识别的选择器已发送到实例 - UIPickerView NSInvalidArgumentException', reason: '-[__NSCFString superview]: unrecognized selector sent to instance NSInvalidArgumentException:无法识别的选择器发送到实例 - NSInvalidArgumentException: unrecognized selector sent to instance NSInvalidArgumentException无法识别的选择器已发送到实例 - NSInvalidArgumentException unrecognized selector sent to instance 无法识别的选择器已发送到实例('NSInvalidArgumentException') - Unrecognized selector sent to instance ('NSInvalidArgumentException') NSInvalidArgumentException:“无法识别的选择器发送到实例” - NSInvalidArgumentException: “Unrecognized selector sent to instance” NSInvalidArgumentException || 无法识别的选择器已发送到实例 - NSInvalidArgumentException || Unrecognized selector sent to instance 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:-[__ NSCFString方案]:无法识别的选择器已发送到实例 - Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: -[__NSCFString scheme]: unrecognized selector sent to instance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM