Category: Basic Questions in IOS & objective-c
-
Google phone interview for iOS mobile developer position
An outline of google phone interview: Question 1 // Create a function that takes int numbers[1000] and sorts it into ascending order (lowest to highest) I asked an interviewer if bubble sort is ok, or does he wants something more complex. He said that bubble sort is good enough. I also talked about the complexity,…
-
Difference between formal and informal protocols
An informal protocol is a Category on NSObject. Implementation of the methods is optional. @interface NSObject(NSApplicationNotifications) – (void)applicationWillFinishLaunching:(NSNotification *)notification; … @interface NSObject(NSApplicationDelegate) – (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; … Formal protocols are an Extension to the Objective-C language. Methods can be required or optional. @protocol YourElementsViewDataSource – (NSUInteger)numberOfElements; – (CGFloat)sizeOfElementAtIndex:(NSUInteger)segmentIndex; @optional – (NSString *)titleForElementAtIndex:(NSUInteger)segmentIndex; – (BOOL)shouldExplodeElementAtIndex:(NSUInteger)segmentIndex; @required -…
-
Difference between shallow copy and deep copy
Shallow copy only copies a memory address. Changing one object will also change another. NSMutableArray *firstArray = [[NSMutableArray alloc] initWithObjects:@1, @2, @3, nil]; NSMutableArray *secondArray = [[NSMutableArray alloc] initWithObjects:@4, @5, @6, nil]; secondArray = firstArray; [secondArray setObject:@9 atIndexedSubscript:0]; NSLog(@”%@”, [firstArray objectAtIndex:0]); //9 the value in a first array has also changed Deep copy copies the…
-
Difference between frame and bound
Frame is a CGRect that is relative to it’s superview and bound is a CGRect that is relative to it’s own coordinate system. Practically (x,y) origin of bound would always be (0,0).