-1

I'm stuck with a random error in my application while I try to save NSUserDefaults. Any help/suggesion will be very appreciated!!! I've searched around but have not found any solution :|

Before saving the NSuserDefaults, I set 3 values:

[[NSUserDefaults standardUserDefaults] setBool:YES forKey:kInitialized];
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kIsOK];
[[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:kInitDate]; 
[[NSUserDefaults standardUserDefaults] synchronize];

Here is the crash log:

Thread 11 Crashed:
0   libsystem_kernel.dylib          0x383361f0 __pthread_kill + 8
1   libsystem_pthread.dylib         0x383a0792 pthread_kill + 54
2   libsystem_c.dylib               0x382e7032 __abort + 74
3   libsystem_c.dylib               0x382e6fe4 abort + 84
4   libsystem_malloc.dylib          0x383656f4 szone_error + 312
5   libsystem_malloc.dylib          0x38365974 free_list_checksum_botch + 24
6   libsystem_malloc.dylib          0x3835fe02 small_malloc_from_free_list + 190
7   libsystem_malloc.dylib          0x3835cefa szone_malloc_should_clear + 1394
8   libsystem_malloc.dylib          0x3835c952 malloc_zone_malloc + 70
9   CoreFoundation                  0x2d51026c __CFBasicHashRehash + 324
10  CoreFoundation                  0x2d5116e4 __CFBasicHashAddValue + 96
11  CoreFoundation                  0x2d42bff0 CFBasicHashAddValue + 3308
12  CoreFoundation                  0x2d42c696 CFDictionaryAddValue + 178
13  CoreFoundation                  0x2d440c1c _flattenPlist + 164
14  CoreFoundation                  0x2d440ca2 _flattenPlist + 298
15  CoreFoundation                  0x2d4a48da __CFBinaryPlistWrite + 126
16  CoreFoundation                  0x2d440a48 CFPropertyListWrite + 240
17  CoreFoundation                  0x2d450dd4 CFPropertyListWriteToStream + 140
18  CoreFoundation                  0x2d44ea5c _CFXPreferencesWritePlist + 264
19  CoreFoundation                  0x2d44e94c -[CFXPreferencesPropertyListSourceSynchronizer writePlistToDisk] + 124
20  CoreFoundation                  0x2d44c1aa -[CFXPreferencesPropertyListSourceSynchronizer synchronizeAlreadyFlocked] + 482
21  CoreFoundation                  0x2d44bfc0 -[CFXPreferencesPropertyListSourceSynchronizer synchronize] + 16
22  CoreFoundation                  0x2d45d25e -[CFXPreferencesPropertyListSource synchronize] + 106
23  CoreFoundation                  0x2d45da9a -[CFXPreferencesSearchListSource synchronize] + 70
24  CoreFoundation                  0x2d4eb7ba ___CFXPreferencesAppSynchronize_block_invoke + 26
25  CoreFoundation                  0x2d4ec122 ____CFXPREFS_SYNC_LOCKED_block_invoke + 30
26  libdispatch.dylib               0x3825b81c _dispatch_client_callout + 20
27  libdispatch.dylib               0x382617c6 _dispatch_barrier_sync_f_invoke + 22
28  CoreFoundation                  0x2d4668b8 CFPreferencesAppSynchronize + 260
29  Foundation                      0x2de516ec -[NSUserDefaults(NSUserDefaults) synchronize] + 20

Update: I've replaced setValue to setObject and continue to observe my application. I will report to you soon if it's oK with this correction or not.

3
  • What is the exception message?
    – Paulw11
    Oct 21, 2014 at 19:50
  • The message is a EXC_CRASH: Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Triggered by Thread: 11
    – Duyen-Hoa
    Oct 21, 2014 at 20:04
  • 1
    Please don't correct code in your original question. Instead, add an UPDATE section showing what you changed and with the comment that it now works. Otherwise you destroy the value of this for anyone else because the first thing they see is the CORRECT code.
    – Andy Dent
    Jan 12, 2015 at 20:39

2 Answers 2

2

For NSUserDefaults, you are supposed to use setObject:forKey:, not setValue:forKey:. This may be what is causing your crash, but even if it is not causing the crash it is something that you would want to change.

0
1

Do like this. You are creating object of NSDate

 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:kInitialized];
 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kIsOK];
 [[NSUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:kInitDate];
 [[NSUserDefaults standardUserDefaults] synchronize];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.