I try to set an array of strings
to UserDefaults
but my app gets frozen at that point. I have no problem to set others kinds of data (like String
and Bool
). I have read this topic and others post elsewhere stating it could be problematic depending on the kind of data we want to store. In my case, I only want to store an array of strings [String]
. I have both Objective-C (where I can succesfully save arrays of strings) and Swift classes in my project.
Objective-C class (AppDelegate.m)
{
NSUserDefaults *appSettings; /// declared in header file
}
appSettings = [NSUserDefaults standardUserDefaults];
NSString *xibHome = @"Home";
[appSettings setObject:xibHome forKey:kNibHome];
NSArray *array = [[NSArray alloc] initWithObjects:@"Test", nil];
[appSettings setObject:array forKey:@"test"]; ---> works fine
[SetupAppSettings appSettingsWithSettings:appSettings];
SetupAppSettings.swift file
class SetupAppSettings: NSObject {
@objc class func appSettings(settings:UserDefaults) {
let swiftArray = ["Test"]
settings.set(swiftArray, forKey: "test") ---> app crashes (no message error, just frozen at launchtime)
....
}
}
It looks like the problem resides in my Swift code. But I cannot figure out why [String]
type objects cannot be stored.
Could anyone help me to sort it out?
EDITED
Here is two screenshots as recommended of the process just after pausing the app if it can help: