当我尝试将Swift嵌套类传递给期望AnyClass
参数的函数时,我得到以下编译器错误:
类型名称后的预期成员名称或构造函数调用
有没有办法可以修复上面的错误并将嵌套类作为参数传递?
func getInfo(type: AnyClass) -> UInt32
{
var outPropCount: UInt32 = 0
let properties: UnsafeMutablePointer<objc_property_t> = class_copyPropertyList(type, &outPropCount);
free(properties)
return outPropCount
}
public class Outer: NSObject
{
public class Data: NSObject
{
public var groups: [Int] = []
}
}
public class Data: NSObject
{
public var groups: [Int] = []
}
let o = getInfo(Outer) // works
let d = getInfo(Data) // works
let i = getInfo(Outer.Data) // fails to compile
答案 0 :(得分:1)
解决方案是使用.self
访问类型
let i = getInfo(Outer.Data.self)