objective-c interview questions
Top objective-c frequently asked interview questions
I'm developing a Cocoa application, and I'm using constant NSString
s 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)
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)
I need a simple example program to send and receive a message through NSNotificationCenter
in Objective-C ?
Source: (StackOverflow)
This question already has an answer here:
There are a lot of questions about this problem on SO:
But really no one answer works for me.
How do I capture an image programmatically without the camera shutter sound activating?
Source: (StackOverflow)
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)
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)
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)
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)
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)
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)
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)