title: Swift framework for iOS and macOS
body: <p>currently i'm developing an app for my graduation project. The problem is, that it's not just one app, it consists of an iOS app that is made for the users and a macOS app for the "Owner". In the mac App the owner can create a file that should then be red in the iOS app.</p>
  
  <p>Until now I have made a script that has all the necessary variables to transport the information, it can serialise and deserialise a file and assign it to the UI. Everything worked fine as long as I was working on the macOS app, the files can be created, deserialised and so on, however when I tried to go to the iOS app, I copied the exact same script that serves as the dataModel into the project and when I tried to deserialise a file created in the macOS file the app crashed and gave me an error saying:</p>
  
  <blockquote>
    <p>cannot decode object of class (ExcursionCreator.ExcursionDataModel)
    for key (root); the class may be defined in source code or a library
    that is not linked'</p>
  </blockquote>
  
  <p>I investigated on the error and found out that i cannot just copy the script from one project to the other, so I found a source that said that I should create a framework with just this file, however i haven't found any useful topics that talk about frameworks for cross platform. </p>
  
  <p>So my question in a few words is, is it true that I have to create a framework for this purpose and if so how would I do it so it works on macOS as well on iOS. Any other advice would also be greatly appreciated.   Thanks in advance Jorge. :)</p>
  
  <h2>Update</h2>
  
  <p>As asked by danielv here is my code where I store the information, it also conforms to the NSCoding protocol so i can serialise and deserialise it:</p>
  
  <pre><code>import Foundation
  
  class ExcursionDataModel: NSObject, NSCoding {
  
      var title: String
  
      var imagesData = [Data]()
      var thumbnailImageData: Data?
      var shortText = String()
      var completeText = String()
  
      var difficulty: String = "Hard"
      var duration: String = "Long"
  
      var isFavourite: Bool = false
      var type: excursionType = .other
  
      enum excursionType: String {
          case biking
          case rafting
          case other
      }
  
      static let possibleDifficulties = ["Hard", "Medium", "Easy"]
      static let possibleDurations = ["Long", "Medium", "Short"]
  
      init (title: String) {
          self.title = title
      }
  
      override init() {
          self.title = "Title"
      }
  
      struct PropertyKey {
          static let titleKey = "title"
          static let imagesKey = "images"
          static let thumbnailImageKey = "thumbnailImage"
          static let shortTextKey = "shortText"
          static let completeTextKey = "completeText"
          static let difficultyKey = "difficulty"
          static let durationKey = "duration"
          static let isFavouriteKey = "isFavourite"
          static let typeKey = "type"
      }
  
      //MARK: - NSCoding
  
      func encode(with aCoder: NSCoder) {
  
          aCoder.encode(title, forKey: PropertyKey.titleKey)
          aCoder.encode(imagesData, forKey: PropertyKey.imagesKey)
          aCoder.encode(thumbnailImageData, forKey: PropertyKey.thumbnailImageKey)
          aCoder.encode(shortText, forKey: PropertyKey.shortTextKey)
          aCoder.encode(completeText, forKey: PropertyKey.completeTextKey)
          aCoder.encode(difficulty, forKey: PropertyKey.difficultyKey)
          aCoder.encode(duration, forKey: PropertyKey.durationKey)
          aCoder.encode(isFavourite, forKey: PropertyKey.isFavouriteKey)
          aCoder.encode(type.rawValue, forKey: PropertyKey.typeKey)
      }
  
      required convenience init?(coder aDecoder: NSCoder) {
          let title = aDecoder.decodeObject(forKey: PropertyKey.titleKey) as! String
  
          self.init(title: title)
  
          self.imagesData = aDecoder.decodeObject(forKey: PropertyKey.imagesKey) as! [Data]
          self.thumbnailImageData = aDecoder.decodeObject(forKey: PropertyKey.thumbnailImageKey) as? Data
          self.shortText = aDecoder.decodeObject(forKey: PropertyKey.shortTextKey) as! String
          self.completeText = aDecoder.decodeObject(forKey: PropertyKey.completeTextKey) as! String
          self.difficulty = aDecoder.decodeObject(forKey: PropertyKey.difficultyKey) as! String
          self.duration = aDecoder.decodeObject(forKey: PropertyKey.durationKey) as! String
          self.isFavourite = aDecoder.decodeObject(forKey: PropertyKey.isFavouriteKey) as! Bool
          self.type = excursionType(rawValue: aDecoder.decodeObject(forKey: PropertyKey.typeKey) as! String)!
      }
  }
  </code></pre>