0

I think it is from userDefaults, but not sure why?

-[__NSCFData _getCString:maxLength:encoding:]: unrecognized selector sent to instance 0x61100002ffc0

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData _getCString:maxLength:encoding:]: unrecognized selector sent to instance 0x61100002ffc0'

*** First throw call stack:
(
    0   CoreFoundation                      0x0000000103a69d4b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x0000000102fc721e objc_exception_throw + 48
    2   CoreFoundation                      0x0000000103ad9f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00000001039ef005 ___forwarding___ + 1013
    4   CoreFoundation                      0x00000001039eeb88 _CF_forwarding_prep_0 + 120
    5   CoreFoundation                      0x00000001039a389b CFStringGetCString + 171
    6   CoreFoundation                      0x00000001039b377d CFLocaleCreateCanonicalLocaleIdentifierFromString + 77
    7   CoreFoundation                      0x00000001039b3327 _CFLocaleCopyCurrentGuts + 487
    8   CoreFoundation                      0x00000001039b3109 +[NSLocale currentLocale] + 9
    9   Foundation                          0x0000000102a8a376 -[NSUserDefaults(NSUserDefaults) init] + 1637
    10  Foundation                          0x0000000102a89cb5 +[NSUserDefaults(NSUserDefaults) standardUserDefaults] + 81
    11  UIKit                               0x00000001048098df ___UIApplicationMainPreparations_block_invoke_2 + 53
    12  libclang_rt.asan_iossim_dynamic.dylib 0x0000000101d582b4 __wrap_dispatch_async_block_invoke + 260
    13  libdispatch.dylib                   0x00000001078e8978 _dispatch_call_block_and_release + 12
    14  libdispatch.dylib                   0x00000001079120cd _dispatch_client_callout + 8
    15  libdispatch.dylib                   0x00000001078f365f _dispatch_root_queue_drain + 1450
    16  libdispatch.dylib                   0x00000001078f3059 _dispatch_worker_thread3 + 123
    17  libsystem_pthread.dylib             0x0000000107cbb4de _pthread_wqthread + 1129
    18  libsystem_pthread.dylib             0x0000000107cb9341 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException

// Storing my keys as

struct user {    
    static let shared = user()
    let username:String = "user_username"
    let password:String = "user_password"
    let mobile:String = "user_mobile"
    let email:String = "user_email"
    let fname:String = "user_fname"
    let lname:String = "user_lname"
    let lastSync:String = "user_sync"
    let id:String = "user_employeeId"
    let empRole:String = "user_role"
    let empManager:String = "user_manager"
    let empFinance:String = "user_finance"
}

Thanks in Advance
jeff ayan
  • 819
  • 1
  • 13
  • 16
  • Have you added any code in `didFinishLaunching` in `AppDelegate`? – Karthick Selvaraj Apr 25 '17 at 09:52
  • Add your AppDelegate class. – dahiya_boy Apr 25 '17 at 09:52
  • 1
    The error message is pretty clear. A method which belongs to `NSString` is sent to `NSData`. – vadian Apr 25 '17 at 09:53
  • @Karthick yes I'm checking whether the user is already logged in – jeff ayan Apr 25 '17 at 09:55
  • As @vadian said `getCString:maxLength:encoding:` is a `NSString` method. And your error states that it's a `NSData` object is calling that method. Meaning? Somewhere, you think that the object you are manipulating is a `NSString` object, but it's a `NSData` one instead. From the stacktrace, I'd say that your issue is where you use `NSUserDefault`. But we need that code (where you read it and where you save it). – Larme Apr 25 '17 at 09:56
  • @vadian but i store all string values here – jeff ayan Apr 25 '17 at 09:57
  • @vadian I store like this global.defaults.setValue(employeeEmailId, forKey: user.shared.email) global.defaults.setValue(employeeFirstName, forKey: user.shared.fname) global.defaults.setValue(employeeLastName, forKey: user.shared.lname) – jeff ayan Apr 25 '17 at 09:58
  • The struct declaration is irrelevant. The error is related to `UserDefaults`. – vadian Apr 25 '17 at 10:00
  • @vadian I retrive like this let _fname = global.defaults.value(forKey: user.shared.fname) as? String – jeff ayan Apr 25 '17 at 10:02
  • But it was working fine. only today it is creating this burden – jeff ayan Apr 25 '17 at 10:02
  • you can do is set an exception breakpoint. Open the breakpoints tab (cmd+7), then press the + button. Now add an exception breakpoint and it should halt as soon as the exception is raised. – KKRocks Apr 25 '17 at 10:04

0 Answers0