1. List and explain: IOS application States
Not Running:has not been lanuched or terminated by the system
Inactive:running in foreground and is receiving events stay briefly on their A-to is active.
Active:running in foreground and receiving events.
Background:running in Background and executing code. Stay briefly on their-to is suspended.
Suspended:remains in memory but does execute any code.
2. ios Compiler optimizes references to string objects that has the same value
nsstring *firstname = @ " jack " ; NSString *secondname = @ " jack Span style= "color: #800000;" > " ; if (FirstName == Secondname) {NSLog ( @ " Span style= "color: #800000;" >areequal );} else {NSLog ( @ " Arenotequal );}
FirstName and Secondname is pointers to different objects that has the same value. But the optimization machanism of IOS compiler let both pointers actually pointing to same address.
In Swift, Closures and functions is also assigned by reference. If variable or constant A and B is assigned to the same closure or function, they gonna has exactly the same value in me Mory.
3. Concurrency
==thread:not suggested, hard to design
==dispatch Queues:first in first off only. GCD takes care of creating the needed threads and scheduling tasks to run on those threads.
==operation queue:implemented by Nsoperationqueue don't limited to FIFO order and support complex execution order graphs fo R your tasks.
4.Swift Retain Cycle
1 classA {2 3 Let b:b4 5 init () {6 7b =B ()8 9B.A = SelfTen One } A - Deinit () { - thePrint"A Deinit") - - } - + } - + classB { A atvar a:a? =Nil - - Deinit { - -Print (B deinit") - in } - to}
To resolve a retain cycle
When property A and B must isn't be nil, one should is assigned unowned Reference and the other one should be I mplicitly Unwrapped Optional
When one of the property A or B could is nil, the one which can ' t be nil should be assigned unowned.
When both of the property A and B could is nil, assign weak for one property.
5. Objective-c Single Example Singleton
@implementation Mymanager+ (ID) sharedmanager { static Mymanager * staticinstance = nil; static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^=return staticinstance;} @end
6. Available prefixs to keyword func in Swift
override: To override methods in superclass you must write override before Func
class: To implement a class method must write class before Func
static: To implement a structures/enumerations method must write static before Func
mutating: For all structures/enumerations methods This could change the instance properties, you must write Mutat ing before func
7. Closures Classification
Global Function:do not capture values
Nested function:capture values from enclosing Function
Closure expression:a unamed Closure that capture values from surrounding context
{(parameters)-(return in statements}
8. Closure Shorthand
Reversed = Names.sort ({(S1: a href= "" string/a, S2: a href= "" string/a), a href= "" bool/a in R Eturn s1 > s2})
Inferring Type from context
Reversed = Names.sort ({s1, S2 in return s1 > s2})
Implicit Returns from Single-expression Closures
Reversed = Names.sort ({s1, s2 in S1 > s2})
Shorthand Argument Names
Reversed = Names.sort ({$ > $})
Operator Functions
Reversed = Names.sort (>)
iOS Interview preparation