Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

are needsDisplayForKey/actionForKey overrides working correctly?

Tags:

swift

calayer

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)
}
like image 441
user3320597 Avatar asked Jun 10 '14 20:06

user3320597


1 Answers

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)

like image 165
Tjeerd Avatar answered Oct 25 '22 01:10

Tjeerd