以下是问题,如果类型是protocol.type,我无法调用类方法.是否有可以实现这一目标的替代模式.
真实情况是我有arr:[SomeProtocol.Type],我想执行let字符串:[String] = arr.map {$ 0.str}
protocol SomeProtocol: class {
static var str: String { get }
static func value() -> Int
}
class SomeClass: SomeProtocol {
static var str: String = "SomeClass"
static func value() -> Int {
return 1
}
}
let protocolType: SomeProtocol.Type = SomeClass.self
println(protocolType.str) // compile error
println(protocolType.value()) // compile error
Run Code Online (Sandbox Code Playgroud) 我使用CABasicAnimation将以下代码添加到CALayer的动画边界属性中.但代码似乎不起作用.
let fromValue = textLabel.layer.bounds
let toValue = CGRectMake(textLabel.layer.bounds.origin.x, textLabel.layer.bounds.origin.y, textLabel.layer.bounds.width, textLabel.layer.bounds.height + 50)
let positionAnimation = CABasicAnimation(keyPath: "bounds")
positionAnimation.fromValue = NSValue(CGRect: fromValue)
positionAnimation.toValue = NSValue(CGRect: toValue)
positionAnimation.duration = 1
positionAnimation.fillMode = kCAFillModeBoth
positionAnimation.removedOnCompletion = false
textLabel.layer.addAnimation(positionAnimation, forKey: "bounds")
Run Code Online (Sandbox Code Playgroud)