Attempt to insert non-property list object when trying to save a custom object in Swift 3

You need to create Data instance from your JobCategory model using JSONEncoder and store that Data instance in UserDefaults and later decode using JSONDecoder. struct JobCategory: Codable { let id: Int let name: String } // To store in UserDefaults if let encoded = try? JSONEncoder().encode(category) { UserDefaults.standard.set(encoded, forKey: UserDefaultsKeys.jobCategory.rawValue) } // Retrieve from UserDefaults … Read more

Xcode 9 GM – WKWebView NSCoding support was broken in previous versions

The error is correct behavior, and not a bug in Xcode 9. Although WKWebView was introduced in iOS 8, there was a bug in -[WKWebView initWithCoder:] that was only fixed in iOS 11, which always crashed at runtime and thus prevented configuring one within Interface Builder. https://bugs.webkit.org/show_bug.cgi?id=137160 Rather than allow developers to build something in … Read more

Saving custom Swift class with NSCoding to UserDefaults

In Swift 4 or higher, Use Codable. In your case, use following code. class Blog: Codable { var blogName: String? } Now create its object. For example: var blog = Blog() blog.blogName = “My Blog” Now encode it like this: if let encoded = try? JSONEncoder().encode(blog) { UserDefaults.standard.set(encoded, forKey: “blog”) } and decode it like … Read more