8

I'm trying to convert some code that works in Objective-C to Swift. The problem I'm running into is that needsDisplayForKey/actionForKey aren't getting called the same way. As far as I can tell, the custom key values aren't getting passed in correctly. Here is what I get when I debug it:

default value:

(String!) event = {
  core = {
    _baseAddress = Builtin.RawPointer = 0x00feee51 "onOrderIn"
    _countAndFlags = 1073741833
    _owner = Some {
      Some = (instance_type = Builtin.RawPointer = 0x01026348 @"onOrderIn")
    }
  }
}

custom value (empty string passed in):

(String!) event = {
  core = {
    _baseAddress = Builtin.RawPointer = 0x0b418f79
    _countAndFlags = 1073741833
    _owner = Some {
      Some = (instance_type = Builtin.RawPointer = 0x0b418f70 -> 0x006e38f0 (void *)0x006e38c8: __NSCFString)
    }
  }
}

I'm not sure what the relevant code might be. I'll just ask - has anyone else was able to define a custom implicit animation in Swift? Is there anything I need to keep in mind when moving over from Objective C?

override class func needsDisplayForKey(key: String!) -> Bool{
    if key == "angleFrom" || key == "angleTo" {
        return true;
    }
    return super.needsDisplayForKey(key)
}

override func actionForKey(event: String!) -> CAAction!{
    if event == "angleFrom" || event == "angleTo" {
        return self.makeAnimationForKey(event)
    }
    return super.actionForKey(event)
}
user3320597
  • 146
  • 1
  • 5
  • It looks like dynamic properties might not be working yet in Swift, at least not without bridging over to Objective-C http://stackoverflow.com/questions/24015185/generating-swift-models-from-core-data-entities – user3320597 Jun 11 '14 at 23:46

1 Answers1

13

I got this working in Swift by using @NSManaged attribute in front of the variable declaration (where you would use the the @dynamic attribute in Objective-C)

Tjeerd
  • 226
  • 2
  • 7
  • Thanks, this worked for me. I used the overrides as described in the question and made my custom property (the key) be @NSManaged. – Code Commander Mar 06 '15 at 23:42
  • yes, that is the case because `@NSManaged` produces what Objective-C calls `@dynamic` property meaning no implementation, setting and getting values will be handled at runtime through KVO, and that is exactly the same type of property CoreGraphics needs, too! – Sash Zats May 20 '16 at 21:11