ios - Core Data Swift cast failure in generic function in optimized builds -


we have app broad core data model, lots of custom subclasses implemented in objective c, used growing fraction of app that's written in swift. (for it's worth: we're building xcode 7.3.1 against ios 9.3, , swift code 2.2.)

there's helper function written in swift looks this:

extension nsmanagedobject {   func incontext<t: nsmanagedobject>(moc: nsmanagedobjectcontext) -> t? {     guard self.managedobjectcontext != moc else {       return (self as! t)     }      {       let obj = try moc.existingobjectwithid(self.objectid)       return (obj as! t)  // <--- fails here     }     catch let error {       return nil     }   } } 

this called in fair number of places objects jump contexts. calling code looks this:

let result: ecfoo? = foo.incontext(managedobjectcontext) 

this works flawlessly in debug builds of app. optimizations turned on, i'm running case call fails @ line i've marked, fetched object being cast nsmanagedobject correct subclass. stack trace starts swift_dynamiccastobjcclassunconditional, , message gets logged console is:

could not cast value of type 'ecfoo_foo_' (0x7fb857d2c250) 'ecfoo_foo_' (0x7fb857d2c250).

if put breakpoint on line, i'm attempting seems fine in debugger console:

(lldb) po moc.existingobjectwithid(self.objectid) ecfoo
true

this confusing, because it's same type on both sides here, , both appear dynamically generated subclass, rather formal class should trying cast (based on inference of calling code). can assume there's piece of information being optimized away necessary make work, i'm not entirely sure how fix it.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -