我有以下设置:
// MARK: Basis
public class Foo {
public typealias Bar = [String : Int]
}
func take(fooBar: Foo.Bar) {
print(fooBar)
}
// MARK: Problems
public typealias FooBar = Foo.Bar
public extension Dictionary
where Key == FooBar.Key,
Value == FooBar.Value {
func baz() {
take(fooBar: self as! FooBar)
}
}
// MARK: Usages
FooBar().baz()
take(fooBar: [:])
这对我来说似乎很好,但我得到了这个错误:
main.swift:16:31: error: type alias 'Bar' is not a member type of 'Foo'
public typealias FooBar = Foo.Bar
~~~ ^
我非常困惑……它就在那里;我应该能看到它。
这是最令人困惑的部分:如果我注释掉 extension Dictionary
block 和 baz()
的调用站点,那么一切正常。
也就是说,编译运行没有问题:
public class Foo {
public typealias Bar = [String : Int]
}
func take(fooBar: Foo.Bar) {
print(fooBar)
}
public typealias FooBar = Foo.Bar
take(fooBar: [:])
所以我的问题是:这是怎么回事,我该如何解决?
最佳答案
这是 Swift 编译器中的错误。你可以在这里追踪它:SR-6179
关于swift - 类型别名 "Bar"不是类型 "Foo"的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46816925/