Is it possible to save an NSManagedObject in NSUserDefaults?
<p>I've having difficulty saving an NSManagedObject in userDefaults and I'd like to know a) should I be trying to do this or is this not an appropriate approach or b) if it is an appropriate approach, how can I get it to work?</p>

<p>I'm writing my app in Swift 2.3 and it has a few user default options, one of which is for a default "lift" (as in weightlifting, e.g. 'bench press', 'clean and jerk', 'incline bench press'). I'm actually converting them from an enum to a Core Data entity because every lift event that the user will be able to keep track of will be one of the available lifts types (for which I'll establish the appropriate relationship).</p>

<p>Here's the extension with the properties:</p>

<pre><code>extension Lift {

    @NSManaged var liftName: String
    @NSManaged var type: NSSet

   }
</code></pre>

<p>and the Lift entity with the things Xcode is complaining about:</p>

<pre><code>class Lift: NSManagedObject, NSCoding {
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(liftName, forKey: "liftName")
    } // Super.init isn't called on all paths before returning from initializer

required init(coder aDecoder: NSCoder) {

    // Initialization of immutable variable was never used, etc...
    let liftName = aDecoder.decodeObjectForKey("liftName") as! String

    }
  }
</code></pre>

<p>I've dealt with these types of errors before so my real concern is whether or not I'm headed down the wrong path. </p>

<p>I've read numerous threads tonight which have taught me that I'll need to encode an object (but not specifically an NSManagedObject) to save it then unencoded it when retrieving it and that my class must conform to NSCoding and what that protocol requires. But then I've seen <a href="https://stackoverflow.com/questions/32709029/saving-nsmanagedobject-in-nsuserdefaults">threads</a> that say <code>NSManagedObjects</code> should <strong>NOT</strong> be stored in <code>userDefaults</code>, but I don't know if that's true.</p>

<p>I've spent a few hours on this so before I go further, can/should this be done?</p>