EzDevInfo.com

objective-c interview questions

Top objective-c frequently asked interview questions

Constants in Objective-C

I'm developing a Cocoa application, and I'm using constant NSStrings as ways to store key names for my preferences.

I understand this is a good idea, because it allows easy changing of keys if necessary. Plus, it's the whole 'separate your data from your logic' notion.

Anyway, is there a good way to make these constants defined once for the whole application? I'm sure that there's an easy and intelligent way, but right now my classes just redefine the ones they use.


Source: (StackOverflow)

Creating an abstract class in Objective C

I'm originally a Java programmer who now works with Objective-C. I'd like to create an abstract class but that doesn't appear to be possible in Objective-C. Is this possible?

If not, how close to an abstract class can I get in Objective-C?


Source: (StackOverflow)

Advertisements

Send and receive messages through NSNotificationCenter in Objective-C? [closed]

I need a simple example program to send and receive a message through NSNotificationCenter in Objective-C ?


Source: (StackOverflow)

How do I set up NSZombieEnabled in Xcode 4?

How do I set up NSZombieEnabled and CFZombieLevel for my executable in Xcode 4?


Source: (StackOverflow)

How do I check if a string contains another string in Objective-C?

How can I check if a string (NSString) contains another smaller string?

I was hoping for something like:

NSString *string = @"hello bla bla";
NSLog(@"%d",[string containsSubstring:@"hello"]);

But the closest I could find was:

if ([string rangeOfString:@"hello"] == 0) {
    NSLog(@"sub string doesnt exist");
} 
else {
    NSLog(@"exists");
}

Anyway, is that the best way to find if a string contains another string?


Source: (StackOverflow)

@synthesize vs @dynamic, what are the differences?

What are the differences between implementing a @property with @dynamic or @synthesize?


Source: (StackOverflow)

How can I disable the UITableView selection highlighting?

When you tap a row in a UITableView, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing?


Source: (StackOverflow)

How do you trigger a block after a delay, like -performSelector:withObject:afterDelay:?

Is there a way to call a block with a primitive parameter after a delay, like using performSelector:withObject:afterDelay: but with an argument like int/double/float?


Source: (StackOverflow)

How do I test if a string is empty in Objective C?

How do I test if an NSString is empty in Objective C?


Source: (StackOverflow)

Location Services not working in iOS 8

My app that worked fine on iOS 7 doesn't work with the iOS 8 SDK.

CLLocationManager doesn't return a location, and I don't see my app under Settings -> Location Services either. I did a Google search on the issue, but nothing came up. What could be wrong?


Source: (StackOverflow)

How do I create delegates in Objective-C?

I know how delegates work, and I know how I can use them.

But how do I create them?


Source: (StackOverflow)

How to check iOS version?

I want to check if the iOS version of the device is greater than 3.1.3 I tried things like:

[[UIDevice currentDevice].systemVersion floatValue]

but it does not work, I just want a:

if (version > 3.1.3) { }

How can I achieve this?


Source: (StackOverflow)

Generating random numbers in Objective-C

I'm a Java head mainly, and I want a way to generate a pseudo-random number between 0 and 74. In Java I would use the method:

Random.nextInt(74)

I'm not interested in a discussion about seeds or true randomness, just how you accomplish the same task in Objective-C. I've scoured Google, and there just seems to be lots of different and conflicting bits of information.


Source: (StackOverflow)

@class vs. #import

It is to my understanding that one should use a forward-class declaration in the event ClassA needs to include a ClassB header, and ClassB needs to include a ClassA header to avoid any circular inclusions. I also understand that an #import is a simple ifndef so that an include only happens once.

My inquiry is this: When does one use #import and when does one use @class? Sometimes if I use a @class declaration, I see a common compiler warning such as the following:

warning: receiver 'FooController' is a forward class and corresponding @interface may not exist.

Would really love to understand this, versus just removing the @class forward-declaration and throwing an #import in to silence the warnings the compiler is giving me.


Source: (StackOverflow)