无法将Swift嵌套类作为AnyClass参数传递

时间:2016-03-22 21:13:05

标签: swift swift2

当我尝试将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

1 个答案:

答案 0 :(得分:1)

解决方案是使用.self访问类型

let i = getInfo(Outer.Data.self)