我有这个协议继承
@objc protocol Base {}
protocol Some : Base {}以及检查它的代码( main.swift )
import Foundation
class Model1 : NSObject {}
extension Model1 : Some {}
class Model2 : NSObject, Some {}
func test() {
let m1: NSObject = Model1()
let m2: NSObject = Model2()
print("m1 is Some? \(m1 is Some)")
print("m2 is Some? \(m2 is Some)")
print("m1 is Base? \(m1 is Base)")
print("m2 is Base? \(m2 is Base)")
}
test()有趣的是,swiftc和swift的输出不同
swiftc main.swift && ./main
m1 is Some? true
m2 is Some? true
m1 is Base? false
m2 is Base? falsevs
swift main.swift
m1 is Some? true
m2 is Some? true
m1 is Base? true
m2 is Base? false但问题是为什么我不能把他们中的任何一个投给Base**?**
如果我将@objc添加到Some中,那么每个测试都将通过true。但我现在不能这么做,这是另一个SO (请看这里)的主题。
swiftc --version
Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1)
Target: x86_64-apple-macosx10.9发布于 2017-02-06 23:55:41
来自swift用户,似乎是一个已知的问题,有待解决:https://bugs.swift.org/browse/SR-1175
https://stackoverflow.com/questions/42023977
复制相似问题