[__NSCFString charValue]: unrecognized selector sent to instance?

My app uses FMDB and Mantle, everything works fine after iPhone 5 simulator, but crash before iPhone 5s, it looks like Bool Variable is the cause. But I can't figure out why everything works fine on iPhone 5, 6 and 6 plus.

@property (nonatomic, assign) BOOL isMyFan;
@property (nonatomic, assign) BOOL isMyFollow;
@property (nonatomic, assign) NSInteger cityID;
@property (nonatomic, assign) NSInteger provinceID;
@property (nonatomic, assign) NSInteger locationID;

2015-07-14 21:33:17.264 ATOMPSGod[48894:607] -[__NSCFString charValue]: unrecognized selector sent to instance 0x79fb7700
2015-07-14 21:33:17.268 ATOMPSGod[48894:607] *** Caught exception setting key "isMyFollow" : -[__NSCFString charValue]: unrecognized selector sent to instance 0x79fb7700
2015-07-14 21:33:17.277 ATOMPSGod[48894:607] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString charValue]: unrecognized selector sent to instance 0x79fb7700'
*** First throw call stack:
(
    0   CoreFoundation                      0x026201e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x022ba8e5 objc_exception_throw + 44
    2   CoreFoundation                      0x026bd243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
    3   CoreFoundation                      0x0261050b ___forwarding___ + 1019
    4   CoreFoundation                      0x026100ee _CF_forwarding_prep_0 + 14
    5   Foundation                          0x01f3eb39 _NSSetCharValueForKeyWithMethod + 67
    6   Foundation                          0x01ee727f _NSSetUsingKeyValueSetter + 256
    7   Foundation                          0x01ee6731 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 267
    8   ATOMPSGod                           0x0020f1a7 MTLValidateAndSetValue + 311
    9   ATOMPSGod                           0x0020ef19 -[MTLModel initWithDictionary:error:] + 697
    10  ATOMPSGod                           0x0020eb9e +[MTLModel modelWithDictionary:error:] + 126
    11  ATOMPSGod                           0x000e3d54 -[MTLFMDBAdapter initWithFMResultSet:modelClass:error:] + 6836
    12  ATOMPSGod                           0x000e20fb +[MTLFMDBAdapter modelOfClass:fromFMResultSet:error:] + 139
    13  ATOMPSGod                           0x00139746 __25+[ATOMUserDAO fetchUser:]_block_invoke + 246
    14  ATOMPSGod                           0x00299cec __30-[FMDatabaseQueue inDatabase:]_block_invoke + 108
    15  libdispatch.dylib                   0x03c124d0 _dispatch_client_callout + 14
    16  libdispatch.dylib                   0x03bff740 _dispatch_barrier_sync_f_invoke + 58
    17  libdispatch.dylib                   0x03bff3ea dispatch_barrier_sync_f + 89
    18  libdispatch.dylib                   0x03bff90b dispatch_sync + 37
    19  ATOMPSGod                           0x00299c15 -[FMDatabaseQueue inDatabase:] + 341
    20  ATOMPSGod                           0x0013954e +[ATOMUserDAO fetchUser:] + 286
    21  ATOMPSGod                           0x00133c9e -[ATOMCurrentUser fetchCurrentUserInDB:] + 190
    22  ATOMPSGod                           0x0002e9f7 -[AppDelegate application:didFinishLaunchingWithOptions:] + 663
    23  UIKit                               0x02c3314f -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
    24  UIKit                               0x02c33aa1 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1810
    25  UIKit                               0x02c38667 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
    26  UIKit                               0x02c4cf92 -[UIApplication handleEvent:withNewEvent:] + 3517
    27  UIKit                               0x02c4d555 -[UIApplication sendEvent:] + 85
    28  UIKit                               0x02c3a250 _UIApplicationHandleEvent + 683
    29  GraphicsServices                    0x050cff02 _PurpleEventCallback + 776
    30  GraphicsServices                    0x050cfa0d PurpleEventCallback + 46
    31  CoreFoundation                      0x0259bca5 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
    32  CoreFoundation                      0x0259b9db __CFRunLoopDoSource1 + 523
    33  CoreFoundation                      0x025c668c __CFRunLoopRun + 2156
    34  CoreFoundation                      0x025c59d3 CFRunLoopRunSpecific + 467
    35  CoreFoundation                      0x025c57eb CFRunLoopRunInMode + 123
    36  UIKit                               0x02c37d9c -[UIApplication _run] + 840
    37  UIKit                               0x02c39f9b UIApplicationMain + 1225
    38  ATOMPSGod                           0x00112cba main + 138
    39  libdyld.dylib                       0x03e466d9 start + 1
)

      

libc ++ abi.dylib: exit with an uncaught exception of type NSException (lldb)

updated with the kind of variable:

key __NSCFString *  @"isMyFollow"   0x79e50400
obj ATOMUser *  0x79e46e30  0x79e46e30
ATOMBaseModel   ATOMBaseModel       
_boundWeibo BOOL    NO  '\0'
_boundWechat    BOOL    NO  '\0'
_isMyFan    BOOL    NO  '\0'
_isMyFollow BOOL    NO  '\0'
_uid    int 0   0
_cityID NSInteger   0   0
_provinceID NSInteger   0   0
_locationID NSInteger   0   0
_mobile NSString *  nil 0x00000000
_nickname   NSString *  nil 0x00000000
_avatar NSString *  nil 0x00000000
_backgroundImage    NSString *  nil 0x00000000
_sex    NSInteger   0   0
_attentionNumber    NSInteger   11  11
_fansNumber NSInteger   0   0
_praiseNumber   NSInteger   0   0
_uploadNumber   NSInteger   0   0
_replyNumber    NSInteger   0   0
_proceedingNumber   NSInteger   0   0
_attentionUploadNumber  NSInteger   0   0
_attentionWorkNumber    NSInteger   0   0
forceUpdate BOOL    YES '\x01'
value   __NSCFString *  @"0"    0x79e3e140
error   NSError **  NULL    0x00000000
validatedValue  __NSCFString *  @"0"    0x79e3e140

      

+3


source to share


1 answer


ORIGINAL ANSWER: . If it works on iPhone 5S and up, it looks like a 32/64 bit issue, since all iPhones with 5S are 64 bit. More precisely, for a 32-bit system BOOL

there is signed char

, while under a 64-bit system - BOOL

.

You can read more here.

UPDATE: I am guessing your problem is dealing with the storage of BOOL values โ€‹โ€‹in collections. BOOL values โ€‹โ€‹stored in obj-c collections are wrapped in an NSNumber object since collections can only contain objects. You should use it like this:



NSDictionary *dict = @{@"BOOL_Key": [NSNumber numberWithBool:YES]};
BOOL myBool = [[dict objectForKey:@"BOOL_Key"] boolValue];

      

Or you can use @(YES)

instead [NSNumber numberWithBool:]

. If you don't use it boolValue

, you may get unpredictable results. Hope it helps.

+7


source







All Articles