swift - iOS Code Works on iOS 9 but not on iOS 8? -


one of tabs (in tab-based application) works on ios 9, not work on ios 8. specifically, when trying load data plist, error shown below.

i have "planner" tab saves entries plist. ios 8 error - reason: '*** -[nskeyedunarchiver initforreadingwithdata:]: incomprehensible archive (0x62, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x30, 0x30)'

saving code:

let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate     plistpath = appdelegate.plistpathindocument     plistpath2 = appdelegate.plist2pathindocument     // extract content of file nsdata     let data:nsdata =  nsfilemanager.defaultmanager().contentsatpath(plistpath)!     let data2:nsdata = nsfilemanager.defaultmanager().contentsatpath(plistpath2)!     do{         if(numofviewwillappear == 0)         {             if let x = nskeyedunarchiver.unarchiveobjectwithdata(data2)             {                 self.sortedsections = nskeyedunarchiver.unarchiveobjectwithdata(data2) as! [string]                 self.sections = nskeyedunarchiver.unarchiveobjectwithdata(data) as! dictionary             }             numofviewwillappear++         }     } 

and appdelegate preparation code:

    func prepareplist() {     let rootpath = nssearchpathfordirectoriesindomains(nssearchpathdirectory.documentdirectory, .userdomainmask, true)[0]     let url = nsurl(string: rootpath)     plistpathindocument = (url?.urlbyappendingpathcomponent("planner.plist").path)!      if !nsfilemanager.defaultmanager().fileexistsatpath(plistpathindocument){         let plistpathinbundle = nsbundle.mainbundle().pathforresource("planner", oftype: "plist")!         {             try nsfilemanager.defaultmanager().copyitematpath(plistpathinbundle, topath: plistpathindocument)             print("plist copied")         }         catch{             print("error copying plist!")         }     }     else{         print("plst exists \(plistpathindocument)")     }  } 

code in save items plist:

self.sections[todoitem.duedate] = [assignment(name: todoitem.name, duedate: todoitem.duedate)] let appdelegate = uiapplication.sharedapplication().delegate as! appdelegate plistpath = appdelegate.plistpathindocument do{   let sectionsdata = nskeyedarchiver.archiveddatawithrootobject(sections)   sectionsdata.writetofile(plistpath, atomically: true) } 

i'm not sure it's worth try:

self.sections = nskeyedunarchiver.unarchiveobjectwithdata(data) as! dictionary 

in "saving code" in above mentioned line, try using nsdictionary instead of dictionary when running on ios8. think read somewhere, introduced dictionary class quite recently. i'm not of , i'm kind of newbie when comes ios it's worth try...it might work. if works, put dictionary line in if #available(ios 9.0 *) condition.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -