swift - Xcode 8.1 UIDataSourceModelAssociation broken? -


i trying implement state restoration on core data project (swift) , having problems implementing uidatasourcemodelassociation protocol on data source uitableview in split view controller, wrapper class around nsfetchedresultscontroller.   code :

1   extension eventdataprovider : uidatasourcemodelassociation   2   {   3     public func modelidentifierforelement(at idx: indexpath, in view: uiview) -> string?   4     {   5       let elementatindexpath = self.fetchedresultscontroller.object(at: idx)   6      7       return string(describing: elementatindexpath.objectid.urirepresentation())   8     }   9     public func indexpathforelement(withmodelidentifier identifier: string, in view: uiview) -> indexpath?   10    {   11      if let url = url(string: identifier),   12         let objectid = self.fetchedresultscontroller.managedobjectcontext.persistentstorecoordinator?.managedobjectid(forurirepresentation: url),   13         let object = self.fetchedresultscontroller.managedobjectcontext.object(with: objectid) as? cdevent   14      {   15        return self.fetchedresultscontroller.indexpath(forobject: object) as nsindexpath?   16      }   17     18      return nil   19    }   20  }   

i getting exc_bad_instruction exception, stops debugger @ top of appdelegate class, on state restoration seems point problem "static foundation.indexpath._unconditionallybridgefromobjectivec (swift.optional<__objc.nsindexpath>) -> foundation.indexpath".

i use restorationarchivetool convert resulting data.data file savedstate folder plist command ".../restorationarchivetool  --plist --structured -o path/to/outputfile

if view resulting plist file preview, following :

kapplicationselectedcellindexpathskey...( "<nsindexpath: 0x7fe60054cb00> {length = 2, path = 0 - 3}")

... if open plist in xcode, following :

kapplicationselectedcellindexpathskey key ( value

presuming decoder uses same algorithm plist reader converting data file, not surprising kind of exception.

if remove uidatasourcemodelassociation extension, exception goes away.

can else confirm problem or have missed obvious?

your function has signature:

indexpathforelement(withmodelidentifier identifier: string, in view: uiview) -> indexpath?

thats why should cast return type indexpath instead of nsindexpath:

return self.fetchedresultscontroller.indexpath(forobject: object) nsindexpath? 

to

return self.fetchedresultscontroller.indexpath(forobject: object) indexpath? 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -