开发者

Xcode couldn't find NSObject's method - Objective C

开发者 https://www.devze.com 2023-03-31 22:40 出处:网络
I got into a weird situation, I am trying different methods of NSObject just to know how it works. I am currently testing them on a simple view based application on iOS. I created a random object grea

I got into a weird situation, I am trying different methods of NSObject just to know how it works. I am currently testing them on a simple view based application on iOS. I created a random object greater which returns objects in id as basic NSObject, Than I want to determine what object it is by getting their class name. Therefore I used below method...

Link Edit开发者_开发技巧ed

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/className

Now when I call this method on my random object, Like...

[object className];

Xcode gives me an error saying this...

Instance method '-className' not found

Is this method deprecated? Or Am I doing something wrong?

Thanks


For whatever reason, the className method only exists on Mac OS X. On iOS you can use NSStringFromClass([object class]) instead.


If you look at the documentation it say's that it only available in Mac OS X.

className

Returns a string containing the name of the class.
- (NSString *)className
Return Value

A string containing the name of the class.
Discussion

This method is invoked by Cocoa’s scripting support classes.
Availability

    Available in Mac OS X v10.0 and later.

What is your purpose of finding class name.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号