<分区>
我已将以下内容放入 Playground 中以尝试理解这一点,但我只是没有:
import Foundation
@objc protocol Sample {
var value: Int { get set }
func increase()
func decrese()
}
extension Sample {
func increase() {
value += 1
}
func decrease() {
value -= 1
}
}
class Test: Sample {
var value: Int = 0
}
错误出现在 Test
的 class
声明旁边:
Non-'@objc' method 'increase()' does not satisfy requirement of '@objc' protocol 'Sample'
如果我在类中重新声明 increase()
和 decrease()
,则警告会消失。或者如果我从协议(protocol)中删除声明。有人可以解释一下吗?
编辑
我确实需要一个 Objective-C 类来符合这个协议(protocol),因此在开始时使用 @objc
。