Reputation: 577
class SomeClass {
class var category: Int {
return 1class SomeClass {
class var category: Int {
return 1
}
}
class AnotherClass {
var someClass: SomeClass!
init() {
someClass = SomeClass()
}
}
var a = AnotherClass()
println("\(a.someClass.dynamicType.category)") // error: SomeClass!.Type does not have a member named category
println("\(SomeClass.category)") // print 1
of course I can use SomeClass.category, here is just an example to show the problem. when I don't know the exact type of a.someClass, inheritance for example, how can I do it?
Upvotes: 0
Views: 87
Reputation: 51911
You can:
println("\(a.someClass!.dynamicType.category)")
Unlike normal member access, .dynamicType
does not implicitly unwrap the ImplicitlyUnwrappedOptional
In your case, a.someClass
is ImplicitlyUnwrappedOptional<SomeClass>
, and ImplicitlyUnwrappedOptional<T>
has no .category
static member.
So, you have to manually unwrap it with a.someClass!
Upvotes: 2