- Compare dynamic-typed vs static-typed languages. Discuss the advantages and disadvantages?
- Statically-typed language:
- Dynamic-typed language: why we call it Dynamic? because it is processed in Runtime !
- Compare objective-C with other languages. Discuss the advantages and disadvantages?
- While objective-C looks similar to other languages like C/Java, it is fundamentally different in 2 aspects: it’s a dynamically typed language, and it uses methods and messages instead of function.
- A dynamically typed language allows posing, so allows us to add new behaviours to existing framework classes.
- Life cycle & states of an application:
- 5 states: not running -> inactive -> active -> background (about 5s) -> suspended (not executing)
- (not-running)-touch icon-app:WillFinishLaunching-(->Inactive)-app:didFinishLaunching-appDidBecomeActive-(->Active)-appWillResignActive-(->Background)-appDidEnterBackground(5 seconds to perform tasks)(->Suspended)
- From background it can appWillEnterForeground-(->Active) or appWillTerminate(5 seconds to perform)(->not-running)
- Compare MRR with ARC?
- Manual Retain Release:
- creation with alloc_init, new or copy/mutableCopy (retainC =1)
- retain (retainC+1), release (retainC-1), when retainC ==0 -> destroyed.
- your class owns an obj if you created it or retained it.
- Use release rather than Auto-release: release allows you to dictate the memory management (use autorelease if function returns an object created inside it).
- dealloc is to release instance variables, also in viewDidUnload
- use Macro RELEASE_SAFELY(obj) [object release];object=nil;
- Manual Retain Release:
- Compare properties and ivars. When and why should we use ivars?
- Compare categories with subclasses? When and why should we use which?
- Common performance issues of TableView? CollectionView? How to avoid them?
- Three ways to achieve Concurrency in iOS?
- Compare Objective-C and Swift? How to use Swift together in a project with Objective-C?
- What is the difference between Message-sending in Obj-C and function-calling in Java?
- Message-sending in Obj-C is not like function calling. Message is just a request to call a function – the message is essentially a selector. Which function will be called is decided by the Message-receiving-object.
- These 4 ways to send messages are equivalent:
SEL mySelector = @selector(doSomething);
[myObject doSomething] [myObject performSelector:mySelector] [myObject performSelector:@selector(doSomething)] [myObject performSelector:NSSelectorFromString(@"doSomething")];
- If a message is forwarded to an object that can’t handle it, ERROR will be thrown.
- If a message is forwarded to an object that does not respond to it, however, before announcing ERROR, the runtime sends it a forwardInvocation: message, so the message can be forwarded further.
- However, class has opportunity to use dynamic method solver before the forwarding mechanism kicks in! If we implement these solvers (for instance/ class methods respectively):
- _cmd: the enclosing method in which the current method is called.
- __func__: the function name string, also can use macros:
__FUNCTION__ = sub __PRETTY_FUNCTION__ = void a::sub(int)
- IMP: instance method pointer – a function pointer – points to an Obj-C method.IMP is defined by:
typedef id (*IMP)(id self,SEL _cmd,...);
To access the IMP, the message “methodForSelector” can be used.
IMP myImpDoSomething = [myObject methodForSelector:@selector(doSomething)];
id, can only be used as the result type in a method declaration.
instancetype, the compiler will correctly infer that the result of
+personWithName:is an instance of a
- dynamic types,
- method swizzling
- Memory management: copy vs retain, ARC vs MRR
- Code signing
- Debugging: compare
- Instruments: list
- Compare Collections
- GUI – frames vs bounds,
- App States:
- Compare Categories vs Subclasses
- Delegates vs notifications