EzDevInfo.com

cocoa interview questions

Top cocoa frequently asked interview questions

throwing an exception in objective-c/cocoa

What's the best way to throw an exception in objective-c/cocoa?


Source: (StackOverflow)

What does the NS prefix mean?

Many classes in Cocoa/Cocoa Touch have the NS prefix. What does it mean? Thanks


Source: (StackOverflow)

Advertisements

Difference between objectForKey and valueForKey?

What is the difference between objectForKey and valueForKey? I looked both up in the documentation and they seemed the same to me.


Source: (StackOverflow)

Regular expressions in an Objective-C Cocoa application

Initial Googling indicates that there's no built-in way to do regular expressions in an Objective-C Cocoa application.

So four questions:

  1. Is that really true?

  2. Are you kidding me?

  3. Ok, then is there a nice open-source library you recommend?

  4. What are ways to get close enough without importing a library, perhaps with the NSScanner class?


Source: (StackOverflow)

What does this mean? "'NSUnknownKeyException', reason: ... This class is not key value coding-compliant for the key X"

I'm trying to link a UILabel with an IBOutlet created in my class.

My application is crashing with the following error. What does this mean? How can I fix it?

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x6e36ae0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key XXX.'


Source: (StackOverflow)

@synthesize vs @dynamic, what are the differences?

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


Source: (StackOverflow)

How to print out the method name and line number and conditionally disable NSLog?

I'm doing a presentation on debugging in Xcode and would like to get more information on using NSLog efficiently.

In particular, I have two questions:

  • is there a way to easily NSLog the current method's name / line number?
  • is there a way to "disable" all NSLogs easily before compiling for release code?

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)

What is the best way to unit test Objective-C code?

What frameworks exist to unit test Objective-C code? I would like a framework that integrates nicely with Xcode.


Source: (StackOverflow)

Objective-C: Extract filename from path string

When I have NSString with /Users/user/Projects/thefile.ext I want to extract thefile with Objective-C methods.

What is the easiest way to do that?


Source: (StackOverflow)

How do I iterate over an NSArray?

I'm looking for the standard idiom to iterate over an NSArray. My code needs to be suitable for OS X 10.4+.


Source: (StackOverflow)

How do you print out a stack trace to the console/log in Cocoa?

I'd like to log the call trace during certain points, like failed assertions, or uncaught exceptions.


Source: (StackOverflow)

Is It Possible to NSLog C Structs (Like CGRect or CGPoint)?

I want to be able to debug C structures without having to explicitly type every property that they consist of.

i.e. I want to be able to do something like this:

CGPoint cgPoint = CGPointMake(0,0);
NSLog(@"%@",cgPoint);

Obviously the '%@' won't work, hence the question.


Source: (StackOverflow)

Cocoa: What's the difference between the frame and the bounds?

UIView and its subclasses all have the properties frame and bounds. What's the difference? (Please don't quote the Apple docs — I've already read them and did not understand.)


Source: (StackOverflow)

Cocoa Autolayout: content hugging vs content compression resistance priority

I can't find a clear answer on Apple documentation regarding Cocoa Autolayout about the difference between content hugging and compression resistance.

Can somebody explain their usages and difference ?


Source: (StackOverflow)