ios - Object Archive (.plist) between app and its extension -


i'm developing app keyboard extension , i'm trying share between them .plist file contains encoded custom objects (all of same type, class inheriting nsobject).

i managed sharing setting app group common both this:

// mark: - save helper functions  func documentsdirectory() -> string {     let paths = nssearchpathfordirectoriesindomains(.documentdirectory, .userdomainmask, true)      return paths[0] }  func datafilepath() -> string {     let groupcontainerurl: url = filemanager.default.containerurl(forsecurityapplicationgroupidentifier: "group.myapp.something")!     let groupcontainerpath = groupcontainerurl.path     return (groupcontainerpath nsstring).appendingpathcomponent("myobjects.plist") } 

and loading file array of objects:

private func loadcarmojis() -> [myobject] {     var myobjects: [myobject] = []      let path = datafilepath()      if filemanager.default.fileexists(atpath: path) {          if let data = try? data(contentsof: url(fileurlwithpath: path)) {             let unarchiver = nskeyedunarchiver(forreadingwith: data)             myobjects = unarchiver.decodeobject(forkey: "myobjects") as! [myobject]             unarchiver.finishdecoding()         }     }     return myobjects } 

(there function saving)

into main app, works. saving, retrieving, etc.

into keyboard extension, added these files of code in other target too, "datamodel.swift" , "myobject.swift" (myobject fictional name).

when calls these same functions, file found, , indeed after manual checking logged path, they're same.

problem is, in extension app, crashes, @ line

myobjects = unarchiver.decodeobject(forkey: "myobjects") as! [myobject] 

with error message

terminating app due uncaught exception nsinvalidunarchiveoperationexception', reason: '*** [nskeyedunarchiver decodeobjectforkey:]: cannot decode object of class (myapp.myobject) key (ns.objects); class may defined in source code or library not linked' *** first throw call stack:  { ....  

my suspicious same class nsobject identified differently in 2 app targets.

how can solve problem or work around it? has little datastore , i'd avoid databases.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -