title: UserDefaults or Core Data?
body: <p>I need to store some objects in my app (Xcode 9.1, Swift 4). Currently, I'm storing it like this:</p>
  
  <pre><code>class myItemManager {
  
      var items: [myItem]? {
          didSet {
              Cache.c.items = items
          }
      }
  
      static var manager = myItemManager() {
          didSet {
              myItemManager.manager.items = Cache.c.items
          }
      }
  }
  
  class Cache {
  
      private let uds = UserDefaults.standard
  
      static let c = Cache()
  
      var items: [(myItem)]? {
          get {
              if let decoded = uds.object(forKey: Constants.Cache.myItem) as? Data {
                  let decodedItems = NSKeyedUnarchiver.unarchiveObject(with: decoded) as? [myItem]
                  return decodedItems
              } else {
                 return nil
              }
          }
          set {
              let encodedData: Data = NSKeyedArchiver.archivedData(withRootObject: newValue as AnyObject)
              uds.set(encodedData, forKey: Constants.Cache.myItem)
              uds.synchronize()
          }
      }
  }
  </code></pre>
  
  <p>First, I'm downloading items (from JSON). After I download it, I just save it, like this:</p>
  
  <pre><code>myItemManager.manager.items = downloadedItems
  </code></pre>
  
  <p>Of course, "myItem" subclasses NSObject and NSCoding (allows to save in UserDefaults). </p>
  
  <p>Is this a good approach? Or should I use Core Data? In the future, I will have to filter this data and present it in UICollectionView.</p>