Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to set a non-property-list object - NSUserDefaults

I couldn't find reason how I have got an error when I am trying save Dictionary in the NSUserDefaults.

There is a really simple class function:

class func userLoggedIn(udid udid: String, username: String, email: String, userData: [String: AnyObject]) {
    let userDataDictionary: NSDictionary = NSDictionary(dictionary: userData)

    NSUserDefaults.standardUserDefaults().setObject(udid, forKey: UserDefaultsKeyType.UserUDID.rawValue)
    NSUserDefaults.standardUserDefaults().setObject(username, forKey: UserDefaultsKeyType.Username.rawValue)
    NSUserDefaults.standardUserDefaults().setObject(email, forKey: UserDefaultsKeyType.Email.rawValue)
    NSUserDefaults.standardUserDefaults().setObject(userDataDictionary, forKey: UserDefaultsKeyType.UserData.rawValue)

    NSUserDefaults.standardUserDefaults().synchronize()
}

It creates few records that are the logged user data. Unfortunately the .UserData key has a problem. Few lines of code in past I tried to save userData object at that key. But after the error I added new temporary object. After I have tried to save some new data I have got that error:

    2016-10-31 18:45:04.564 ios_app[11679:194224] Attempt to set a non-property-list object {
    account = 1;
    email = "[email protected]";
    emailVerified = 0;
    firstName = test;
    values = 0;
    gender = "<null>";
    description = string;
    name = test;
    permissions =     (
        "test_user_role"
    );
} as an NSUserDefaults/CFPreferences value for key userData
2016-10-31 18:45:04.572 ios_app[11679:194224] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to insert non-property list object {
    account = 1;
    email = "[email protected]";
    emailVerified = 0;
    firstName = test;
    values = 0;
    gender = "<null>";
    description = string;
    name = test;
    permissions =     (
        "test_user_role"
    );
} for key userData'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010bfded85 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010ba52deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010bfdecbd +[NSException raise:format:] + 205
    3   CoreFoundation                      0x000000010bf99dee _CFPrefsValidateValueForKey + 142
    4   CoreFoundation                      0x000000010bfe1ed9 -[CFPrefsPlistSource sendMessageSettingValue:forKey:] + 217
    5   CoreFoundation                      0x000000010bfe0a1d -[CFPrefsPlistSource alreadylocked_setValues:forKeys:count:] + 509
    6   CoreFoundation                      0x000000010bf99f15 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 261
    7   CoreFoundation                      0x000000010bed6950 -[CFPrefsSource setValues:forKeys:count:] + 32
    8   CoreFoundation                      0x000000010bfd8a6a -[CFPrefsSearchListSource alreadylocked_setValues:forKeys:count:] + 362
    9   CoreFoundation                      0x000000010bf99f15 -[CFPrefsSource setValues:forKeys:count:removeValuesForKeys:count:] + 261
    10  CoreFoundation                      0x000000010bed6950 -[CFPrefsSource setValues:forKeys:count:] + 32
    11  CoreFoundation                      0x000000010bf0fd0a -[CFPrefsSource setValue:forKey:] + 58
    12  CoreFoundation                      0x000000010bfd69f1 __95+[CFPrefsSearchListSource withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 385
    13  CoreFoundation                      0x000000010bfd67f6 normalizeQuintuplet + 518
    14  CoreFoundation                      0x000000010bfd65e4 +[CFPrefsSearchListSource withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 100
    15  CoreFoundation                      0x000000010bfc4169 _CFPreferencesSetAppValueWithContainer + 153
    16  Foundation                          0x000000010b6062fe - [NSUserDefaults(NSUserDefaults) setObject:forKey:] + 55

[...]

    30  UIKit                               0x0000000109aa9f09 UIApplicationMain + 171
            31  ios_app                     0x00000001085619c2 main + 114
            32  libdyld.dylib                       0x000000010cdb792d start + 1
            33  ???                                 0x0000000000000001 0x0 + 1
        )
        libc++abi.dylib: terminating with uncaught exception of type NSException

I will be glad for help :)

like image 901
Dzeremix Avatar asked Oct 31 '16 18:10

Dzeremix


1 Answers

You can't have null in there.

property lists do not support explicit nulls

Wikipedia

like image 95
Andreas Avatar answered Oct 13 '22 20:10

Andreas