userdefaults

App Crashing with error: generic parameter 'T' could not be inferred

旧巷老猫 提交于 2020-04-18 05:45:40
问题 I'm trying to get custom object which is hashable from UserDefault. My custom model is defined below: class WorkerProfileResponse: Mappable, Hashable{ static func == (lhs: WorkerProfileResponse, rhs: WorkerProfileResponse) -> Bool { return lhs.id == rhs.id } var hashValue: Int{ return self.id! } var id, loginStatus, lastLogin, lastActive: Int? var username, email, mobileNumber: String? var userCategories: [String]? var userSubCategories: [String]? var biometricToken: String? var accessToken:

Reference Types/Subclassing, and Changes to Swift 4 Codable & encoder/decoders

烈酒焚心 提交于 2020-01-24 22:58:07
问题 I'm struggling to understand class/reference type behavior and how this relates to changes as I try to upgrade and reduce code using Codable in Swift 4. I have two classes – a SuperClass with all of the data that will be persistent and that I save to UserDefaults (a place name & string with coordinates), and a SubClass that contains additional, temporary info that I don't need (weather data for the SuperClass coordinates). In Swift 3 I used to save data like this: func saveUserDefaults() {

Removing Suite in UserDefault

我们两清 提交于 2020-01-15 12:20:08
问题 var sharedPreference : UserDefaults = UserDefaults.init(suiteName: "userKeyValue")! I am creating UserDefault instance like this and most probably it is creating a space in device with name userKeyValue and keep all key value pairs in that. Now I want to migrate the content to different UserDefault instance var oldSharedPreference : UserDefaults? = UserDefaults(suiteName: "userKeyValue") if (oldSharedPreference != nil) { print("Previous data found") for (key, value) in oldSharedPreference!

Clearing a subset of UserDefaults in Swift [closed]

喜你入骨 提交于 2020-01-07 09:47:34
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed last year . The use case is that I want to separate my UserDefaults (different business logic may require Userdefaults to be grouped separately) by an identifier just like Android's SharedPreferences. For example, when a user in my app clicks on logout button, I would want to clear his account related defaults

libc++abi.dylib: terminating with uncaught exception of type NSException Alamofire

核能气质少年 提交于 2020-01-06 02:45:27
问题 I am sending images to the server using alamofire. If parameters ; let parameters: Parameters = [ "userID": "1", "acToken": "acToken" ] working but parameters ; let parameters: Parameters = [ "userID": userID, "acToken": acToken ?? "" ] not working. error = libc++abi.dylib: terminating with uncaught exception of type NSException I'm using swift4, alamofire 4, Xcode 9.2 My upload method : func profilePhotoUpload(){ let defaults = UserDefaults.standard let userID = defaults.integer(forKey:

Difference between UserDefaults() and UserDefaults.standard

久未见 提交于 2020-01-03 21:09:42
问题 Is there a difference between UserDefaults() and UserDefaults.standard in Swift 3.0? 回答1: UserDefaults - Gives you a new object , each object is allocated a different memory and deallocated when object scope is finished. UserDefaults.standard - Gives you the singleton object by using the class method standard the object received by this method is allocated single memory throughout the application. And the usage of them if you´re interesedted in that: // Set UserDefaults.standard.set("YOUR

How can I use UserDefaults in Swift?

半腔热情 提交于 2019-12-27 10:59:46
问题 How can I use UserDefaults to save/retrieve strings, booleans and other data in Swift? 回答1: ref: NSUserdefault objectTypes Swift 3 and above Store UserDefaults.standard.set(true, forKey: "Key") //Bool UserDefaults.standard.set(1, forKey: "Key") //Integer UserDefaults.standard.set("TEST", forKey: "Key") //setObject Retrieve UserDefaults.standard.bool(forKey: "Key") UserDefaults.standard.integer(forKey: "Key") UserDefaults.standard.string(forKey: "Key") Remove UserDefaults.standard.removeObject

saving data array causes crash swift

情到浓时终转凉″ 提交于 2019-12-25 01:21:18
问题 I tried adding an item to an arrar and saving in Userdefault but the app crashed and I would love anyone to point me to what I am doing wrong private func putArray(_ value: GMSAutocompletePrediction?, forKey key: String) { guard let value = value else { return } log("THE MESSAGE \(value)", .fuck) var newArray = getArray(forKey: key) log("THE MESSAGE ARRAY \(newArray)", .fuck) if newArray.contains(value) { newArray.remove(at: newArray.firstIndex(of: value)!) } else { newArray.append(value) }

Saving model into Userdefaults crashes application swift [duplicate]

China☆狼群 提交于 2019-12-24 19:25:15
问题 This question already has answers here : How to save list of object in user Default? (6 answers) Closed 6 months ago . I am trying to save my model class in UserDefault but keep getting error of -[__SwiftValue encodeWithCoder:]: unrecognized selector sent to instance 0x2825fc0a0' I am using codables and below is what my Model looks like struct AuthModel: Codable { let token: String? let firstName: String? let lastName: String? let telephone: String? let userId: Int? let email: String? let

swift QLPreviewPanel crash — NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints

…衆ロ難τιáo~ 提交于 2019-12-24 18:53:02
问题 I am trying to open a preview panel: QLPreviewPanel.shared().makeKeyAndOrderFront(self) for a valid QLPreviewItem (url). This works well for regular files, but crashes on folders and some specific urls, for example vnc internet connection files (.vnc). The console error: [Layout] Unable to simultaneously satisfy constraints: ( "", "", "", "", "" ) Will attempt to recover by breaking constraint Set the NSUserDefault NSConstraintBasedLayoutVisualizeMutuallyExclusiveConstraints to YES to have -