ios - NSManagedObject subclass with Protocol does not work -


i have nsmanagedobject subclass there protocol implemented , getting bad access while calling method on it, code follows.

public protocol mymessageintializer {    func initialize(state:stateconstants) } public class mymessage : nsmanagedobject {   var currentstate: messagestate?    @nsmanaged var type : string   @nsmanaged var duration : string    public func setcurrentstate(state:messagestate) {     self.currentstate = state   }   public func processevent(event:messageevent) {     currentstate?.update(event: event, message: self)   }   public func getcurrentstate() -> messagestate {     return currentstate!   }  }  class inboundmessage: mymessage, mymessageinitializer {      public func initialize(state:stateconstants) {          print("inboundmessage initializer called")      } } 

this how creating message object , initialising

class messagefactory: nsobject {      static func createmessage(state:stateconstants) -> mymessage {          let appdelegate = uiapplication.shared.delegate as! appdelegate          let managedcontext = appdelegate.persistentcontainer.viewcontext// persistentcontainer.viewcontext          let entity = nsentitydescription.entity(forentityname: "message", in: managedcontext)          let message = inboundmessage(entity:entity!,insertinto:managedcontext)         message.initialize(state:state)                 return message      } } 

i

bad_access message.initialize(state:state) line


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -