Tag: types

Class type Objective C

In the NSObject protocol, it defines a method that is similar to this: -(Class) class What type of object is the Class object? Or is it even an object? What can I do with the object? Can I get the base class or adopted protocols?

What is the difference between int and NSInteger?

Possible Duplicates: When to use NSInteger vs int? Why is there is an NSInteger? Can we use int and NSInteger interchangably? Is there any specific situation to use NSInteger only, instead of using int?

Access objects of a specific type using for-in loop in Objective C

This question already has an answer here: Fast Enumeration on NSArray of Different Types 5 answers

unknown type name in objective c

I’m pretty new to objective c, and having some basic problems. I wrote a simple program using a navigator, and everything worked fine. then I added few lines of code (can’t even remember what exactly, and it seems to have no connection to the problem) and the problem occurred. I tried ctrl+z, and the problem […]

Cocoa: Testing to find if an NSString is immutable or mutable?

This produces an immutable string object: NSString* myStringA = @”A”; //CORRECTED FROM: NSMutableString* myStringA = @”A”; This produces a mutable string object: NSMutableString* myStringB = [NSMutableString stringWithString:@”B”]; But both objects are reported as the same kind of object, “NSCFString”: NSLog(@”myStringA is type: %@, myStringB is type: %@”, [myStringA class], [myStringB class]); So what is distinguishing […]

Why use id when we can just use NSObject?

I know that when we want to create an unknown value object we use id. However, I’m curious that why did Apple to choose id which decides it’s value during runtime, when every object is a subclass of NSObject. So instead of id delegate we could have used NSObject *delegate Does anyone know why? Thanks.

In Objective-C, what is the equivalent of Java's “instanceof” keyword?

I would like to check whether an object (e.g. someObject) is assignable (cast-able) to a variable of another type (e.g. SpecifiedType). In Java, I can write: someObject instanceof SpecifiedType A related question is finding whether the runtime type of an object is equal to a another type. In Java, I can write: someObject.getClass().equals(SpecifiedType.class) How can […]

How to detect a property return type in Objective-C

I have an object in objective-c at runtime, from which I only know the KVC key and I need to detect the return value type (e.g. I need to know if its an NSArray or NSMutableArray) of this property, how can I do that?

In Cocoa do you prefer NSInteger or int, and why?

NSInteger/NSUInteger are Cocoa-defined replacements for the regular built-in types. Is there any benefit to using the NS* types over the built-ins? Which do you prefer and why? Are NSInteger and int the same width on 32-bit / 64-bit platforms?

What is the meaning of id?

I am (trying to) learn Objective-C and I keep coming across a phrase like: -(id) init; And I understand id is an Objective C language keyword, but what does it mean to say “the compiler specifically treats id in terms of the pointer type conversion rules”? Does id automatically designate the object to its right […]