user2363025
user2363025

Reputation: 6515

accessing class name in swift 2.3

I'm trying to get the class name of a swift 2.3 class as a string like what class.getSimpleName() provides in Android. When trying the following, i get an error, Type Test1 has no member classForCoder

public class Test1
    {


        public class Test2
        {
        }

        //class.getSimpleName()
        public static let TAG : String = String(Test1.classForCoder)

    }

Upvotes: 1

Views: 185

Answers (1)

xoudini
xoudini

Reputation: 7031

Swift 3

Use init(describing:).

static let className = String(describing: YourClass.self)

Swift 2.x

And in Swift 2.3 it works with init(_:).

static let className = String(YourClass.self)

Upvotes: 1

Related Questions