nsuserdefaults

Cannot store custom class in UserDefaults - Attempt to insert non-property list

↘锁芯ラ 提交于 2021-02-11 13:04:17
问题 I'm trying to store a custom class in UserDefaults , however I'm getting the "Attempt to insert non-property list" error as soon as the app starts. I have successfully stored arrays of custom classes, so I followed the same principle, but something is wrong. This is my class: import Foundation public class PlanRouteFilters: NSObject, NSCoding, Codable { var favoriteLines: Bool var routeType: Int var bus: Bool var train: Bool var subway: Bool var electric: Bool var sharedCar: Bool var bike:

Cannot store custom class in UserDefaults - Attempt to insert non-property list

情到浓时终转凉″ 提交于 2021-02-11 13:01:44
问题 I'm trying to store a custom class in UserDefaults , however I'm getting the "Attempt to insert non-property list" error as soon as the app starts. I have successfully stored arrays of custom classes, so I followed the same principle, but something is wrong. This is my class: import Foundation public class PlanRouteFilters: NSObject, NSCoding, Codable { var favoriteLines: Bool var routeType: Int var bus: Bool var train: Bool var subway: Bool var electric: Bool var sharedCar: Bool var bike:

User Default Values Changing to Previous Values Seemingly Randomly - Swift

泪湿孤枕 提交于 2020-12-11 05:59:06
问题 I am creating an app that is a game where there is a need to store the high score. I believe (correct me if I'm wrong on this, but this question made it seem this way) that user defaults are the best way to accomplish this. Sometimes when I switch between views in my app, the values change to what they previously were. Then I will switch back to another screen, and they will go back to what they should be. This happens kind-of hit and miss, so it is hard to tell, but I think it happens most

User Default Values Changing to Previous Values Seemingly Randomly - Swift

安稳与你 提交于 2020-12-11 05:56:37
问题 I am creating an app that is a game where there is a need to store the high score. I believe (correct me if I'm wrong on this, but this question made it seem this way) that user defaults are the best way to accomplish this. Sometimes when I switch between views in my app, the values change to what they previously were. Then I will switch back to another screen, and they will go back to what they should be. This happens kind-of hit and miss, so it is hard to tell, but I think it happens most

iOS UserDefaults falls behind saved content

橙三吉。 提交于 2020-11-25 04:05:11
问题 This situation is a bit too elaborate to describe in mere words, so I've created a minimal demo project for you to download and run: https://github.com/mattneub/DefaultsDemo You will need Xcode 10 to test. This is what the project looks like when it runs: The project code will appear to have quite a bit of unnecessary kerfuffle, but that is because I've included the minimum material from my real app (a card game) to reproduce the issue I'm seeing. There's a deck of cards and a layout of cards