Here’s what I did:
In Xcode 8.1, I created a new Objective-C project from the Single View Application template.
I added a new Objective-C class called
LittleNapoleon, using the Cocoa Touch Class template.
-[ViewController viewDidLoad]to load the class; the code you posted doesn’t actually compile, so I modified it as shown below. I also added an include of
LittleNapoleon.hto the top of the file.
I ran the app ten times on the iOS 10.1 simulator. It worked every time, producing the following output.
2016-12-13 15:40:40.772 xxoi2[6368:438372] s = LittleNapoleon 2016-12-13 15:40:40.773 xxoi2[6368:438372] cls = LittleNapoleon
I also ran it a few times on an iOS 10.1.1 device and that works fine as well.
I’m not sure what’s happening with your project, but this seems to be working for me. Perhaps you can try repeating the steps I’ve described above to see if the problem is related to your environment or your actual project.
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"
Class dummy = [LittleNapoleon class]; NSString * s = NSStringFromClass(dummy); NSLog(@"s = %@", s); Class cls = [[NSBundle mainBundle] classNamed:s]; NSLog(@"cls = %@", cls);