title: Saving custom Swift class with NSCoding to UserDefaults
body: <p>I am currently trying to save a custom Swift class to NSUserDefaults. Here is the code from my Playground:</p>
  
  <pre><code>import Foundation
  
  class Blog : NSObject, NSCoding {
  
      var blogName: String?
  
      override init() {}
  
      required init(coder aDecoder: NSCoder) {
          if let blogName = aDecoder.decodeObjectForKey("blogName") as? String {
              self.blogName = blogName
          }
      }
  
      func encodeWithCoder(aCoder: NSCoder) {
          if let blogName = self.blogName {
              aCoder.encodeObject(blogName, forKey: "blogName")
          }
      }
  
  }
  
  var blog = Blog()
  blog.blogName = "My Blog"
  
  let ud = NSUserDefaults.standardUserDefaults()    
  ud.setObject(blog, forKey: "blog")
  </code></pre>
  
  <p>When I run the code, I get the following error</p>
  
  <blockquote>
    <p>Execution was interrupted, reason: signal SIGABRT.</p>
  </blockquote>
  
  <p>in the last line (<code>ud.setObject</code>...)</p>
  
  <p>The same code also crashes when in an app with the message</p>
  
  <blockquote>
    <p>"Property list invalid for format: 200 (property lists cannot contain
    objects of type 'CFType')"</p>
  </blockquote>
  
  <p>Can anybody help? I am using Xcode 6.0.1 on Maverick. Thanks.</p>