Linked Questions
13 questions linked to/from Get class name of object as string in Swift
4 votes
2 answers
4k views
Swift ViewController class name as String [duplicate]
I have a viewController called 'MyViewController' in which I want to save some values to the user defaults. As key I wanted to use the class name "MyViewController" and append some string. Is it ...
-3 votes
1 answer
1k views
Getting class name in SWIFT equivalent to Objective C [self class]? [duplicate]
I am using the following syntax to debug my Objective C code, getting the class name. What is the equivalent in SWIFT? NSlog (@"Classe = %@",[self class]);
0 votes
1 answer
85 views
How to use a class name within the function that is inside of the class in Swift [duplicate]
Apologies for the title gore, but I can't really think of any other way to phrase it. I am a Swift noob and am trying to make a silly little program for practice. Anyway, I have superclass which I ...
367 votes
34 answers
271k views
How do I print the type or class of a variable in Swift?
Is there a way to print the runtime type of a variable in swift? For example: var now = NSDate() var soon = now.dateByAddingTimeInterval(5.0) println("\(now.dynamicType)") // Prints "(Metatype)" ...
327 votes
20 answers
311k views
Checking if an object is a given type in Swift
I have an array that is made up of AnyObject. I want to iterate over it, and find all elements that are array instances. How can I check if an object is of a given type in Swift?
125 votes
7 answers
65k views
Swift class introspection & generics
I am trying to dynamically create a class instance based type using generics, however I am encountering difficulty with class introspection. Here are the questions: Is there a Swift-equivalent to Obj-...
27 votes
4 answers
24k views
Get a view controller's class name as string
If I have a UIViewController subclass, how can I get the class name as string? I've tried doing [vc class], but this returns a Class object, not an NSString.
18 votes
3 answers
15k views
Get Swift class name in "class func" method
I have a static method in Swift class BaseAsyncTask: WebServiceClient { class func execute(content : [String:AnyObject], cancelled:CustomBool) { // Print class name (...
2 votes
1 answer
6k views
Swift: Load XIB when instantiating viewcontroller
I recently upgraded my project to Swift and I'm trying to figure out how to instantiate my XIBs dynamically while maintaining strong references to my viewcontrollers. I hate having to call NSBundle....
0 votes
3 answers
2k views
Xcode error: Semantic Issue, Property 'className' not found on object type 'GKEntity *'
Recently I started getting this error from Xcode: Error Screenshot This 'className' property belongs to NSObject. Here is the official documentation. Why is this happening and how do I solve this (...
1 vote
3 answers
995 views
Swift, a function defined in super class that returns the class name of subclass when called from a subclass object
In Objective-C I can do this: @interface MyManagedObjectSuperClass : NSManagedObject +(NSString*)entityName; @end @implementation +(NSString*)entityName { return NSStringFromClass([self class]) ...
2 votes
1 answer
2k views
UIWebView and Swift: Detect when a video starts playing
In Objective-C, I subscribed to the UIWindowDidBecomeVisibleNotification to know if some view gets above my current view controller, using: [[NSNotificationCenter defaultCenter] addObserver:self ...
0 votes
0 answers
167 views
How to print the object name (not class) in Swift?
From this answer, I know that I can get the name of the class type using NSStringFromClass(YourClassName) But I actually also need the name of the current object instance. So if I have code like this:...