Dalija Prasnikar
Dalija Prasnikar

Reputation: 28516

Cannot pass Swift nested class as AnyClass parameter

When I try to pass Swift nested class to function expecting AnyClass parameter I get following compiler error:

Expected member name or constructor call after type name

Is there a way I can fix above error and pass nested class as parameter?

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

Upvotes: 1

Views: 178

Answers (1)

Dalija Prasnikar
Dalija Prasnikar

Reputation: 28516

Solution is to use .self to access type

let i = getInfo(Outer.Data.self)

Upvotes: 1

Related Questions