[1] Foundation vs Core Foundation
CoreFoundation is a general-purpose C framework whereas Foundation is a general-purpose Objective-C framework. Both provide collection classes, run loops, etc, and many of the Foundation classes are wrappers around the CF equivalents. CF is mostly open-source , and Foundation is closed-source.
Core Foundation is the C-level API, which provides CFString, CFDictionary and the like. Foundation is Objective-C, which provides NSString, NSDictionary, etc. CoreFoundation is written in C while Foundation is written in Objective-C. Foundation has a lot more classes CoreFoundation is the common base of Foundation and Carbon.
[2] iOS Directories
~/Documents, ~/Documents/Inbox
[both will store user generated files that can be exposed to user. Ex. email attachments]
~/Library [files not to user.]
~/tmp [System clears files if app not running. Not backed up by iTunes]
[3] Concurrency Operations
Operations can be configured to run a block of code synchronously or asynchronously. Place them in operation queue (NSOperationQueue) to avail concurrency.
Cocoa provides three different types of operations:
Block operations : These facilitate the execution of one or more block objects.
Invocation operations :These allow you to invoke a method in another, currently existing object.
Plain operations :These are plain operation classes that need to be subclassed. The code to be executed will be written inside the main method of the operation object.
[4] GCD
Grand Central Dispatch is not just a new abstraction around what we've already been using, it's an entire new underlying mechanism that makes multithreading easier and makes it easy to be as concurrent as your code can be without worrying about the variables like how much work your CPU cores are doing, how many CPU cores you have and how much threads you should spawn in response.
[5] Cocoa Manual Memory management rules
To increment the retain count of any object, send it the retain message. This is called retaining the object. The object is now guaranteed to persist at least until its retain count is decremented once more. To make this a little more convenient, a retain call returns as its value the retained object — that is, [myObject retain] returns the object pointed to by myObject, but with its retain count incremented.
When you say alloc (or new) to a class, the resulting instance comes into the world with its retain count already incremented. You do not need to retain an object you’ve just instantiated by saying alloc or new (and you should not). Similarly, when you say copy to an instance, the resulting new object (the copy) comes into the world with its retain count already incremented. You do not need to retain an object you’ve just instantiated by saying copy (and you should not).
To decrement the retain count of any object, send it the release message. This is called releasing the object.
If Object A obtained Object B by saying alloc (or new) or copy, or if Object A has said retain to Object B, then Object A should balance this eventually by saying release to Object B, once. Object A should assume thereafter that Object B no longer exists.
[6] Frame vs bounds
The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).
[7] Naming convention for classes, objects and methods
Class names must be unique across an entire app. Use 2 letter prefix related to company name or application name or specific component. If multiple words needed, then Camel case letter is preferred to use.
Method name should be expressive and unique within a class. It do not have prefix, and it should start from the lowercase letter; camel case for multiple words.
Local variable must be unique within the same scope.
[8] NSOperationQueue vs GCD
GCD :Simple, light weight, Low level C based API focused on lock free algorithms and performance.
NSOperationQueue : Internally implemented using GCD. Recommended to use NSOperationQueue instead of GCD unless specific it doesn’t support.
[9] Why Objective – C is a dynamic programming language ?
Static typed languages are those in which type checking is done at compile-time, whereas dynamic typed languages are those in which type checking is done at run-time.
—- in other words —
Objective-C is a dynamically-typed language, meaning that you don't have to tell the compiler what type of object you're working with at compile time. Declaring a type for a variable is merely a promise which can be broken at runtime if the code leaves room for such a thing. You can declare your variables as type id, which is suitable for any Objective-C object.
[10] Cocoa and Cocoa Touch Frameworks
Uses 2 frameworks:
“Cocoa” (OS X) = Foundation framework + Appkit
“Cocoa Touch” (iOS) = Foundation framework + UIKit [In iOS, Appkit replaced with UIKit]
[11] iOS App (multi)layered Architecture
Cocoa Touch : Responsible for View Controllers, Story board, Gestures and event ending.
Includes following frameworks - UIKit, Map, Push notification service, Message UI, Game Kit, iAd.
Media: Audio/Video frameworks like Core Video, Core Graphics, Core Image, Image I/O, OpenGL, GL Kit, Asset Library, Quartz (2D), Core Animation, Core Audio, AVFoundation.
Core Services : Object Oriented cover over OS. Taking care of GCD, iCloud storage, inAppPurchase, Foundation framework., Core Data, SQLite library, Core Foundation, Core Location.
Core OS : Low level Networking, External Accessories, memory allocation, threading, standard I/O. file system, A MAC 4XBSD unix kernel with C API.
[12] App States
Not running State: The app has not been launched or was running but was terminated by the system.
Inactive state: (Foreground) The app is running in the foreground but is currently not receiving events. ( It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message.
Active state (Foreground): The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
Background state: The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.
Suspended state: The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.
[13] App Life/Launch Cycle
[a] Main Function :
App entry point “main” function, Creates application level Autorelease pool.
Hands control off to UIKit framework by calling UIApplicationMain.
[b] UIApplicationMain invokes UIApplication, loads storyboard, reads info.plist for application setups. Sets UIApplicationDelegate, that will create UIWindow object and RootViewController.
[c] Main event loop : At launch time that later processes user event such as gestures, sensor readings, redraw.
[d] Background Message : The executes code at background but not received any events. However , mostly it will be on the way of suspended state.
[e] Termination of app : System initiates app termination when it misbehaves, not responding events, out of memory.
[14] Difference between #import in Obj-C and #include in C?
#import contains some logic that will make sure the file included only once. Avoids recursive inclusion. Where it not in the case of #include.
#import is an improved version of #include.
#import brings the entire header file into the current file.
[15] NSOperationQueue vs GCD
GCD :Simple, light weight, Low level C based API focused on lock free algorithms and performance.
NSOperationQueue : Internally implemented using GCD.
Recommended to use NSOperationQueue instead of GCD unless specific it doesn’t support. because, - It can be pause, resume or cancel operations
KVO capabilities upon NSOperation class properties.
Dependencies to execute operations in specific order.
Specific number of operations can be queued.
[16] Exceptions vs Error
Exceptions represent programmer-level bugs like trying to access an array element that doesn’t exist. They are designed to inform the developer that an unexpected condition occurred. Since they usually result in the program crashing, exceptions should rarely occur in your production code.
CoreFoundation is a general-purpose C framework whereas Foundation is a general-purpose Objective-C framework. Both provide collection classes, run loops, etc, and many of the Foundation classes are wrappers around the CF equivalents. CF is mostly open-source , and Foundation is closed-source.
Core Foundation is the C-level API, which provides CFString, CFDictionary and the like. Foundation is Objective-C, which provides NSString, NSDictionary, etc. CoreFoundation is written in C while Foundation is written in Objective-C. Foundation has a lot more classes CoreFoundation is the common base of Foundation and Carbon.
[2] iOS Directories
~/Documents, ~/Documents/Inbox
[both will store user generated files that can be exposed to user. Ex. email attachments]
~/Library [files not to user.]
~/tmp [System clears files if app not running. Not backed up by iTunes]
[3] Concurrency Operations
Operations can be configured to run a block of code synchronously or asynchronously. Place them in operation queue (NSOperationQueue) to avail concurrency.
Cocoa provides three different types of operations:
Block operations : These facilitate the execution of one or more block objects.
Invocation operations :These allow you to invoke a method in another, currently existing object.
Plain operations :These are plain operation classes that need to be subclassed. The code to be executed will be written inside the main method of the operation object.
[4] GCD
Grand Central Dispatch is not just a new abstraction around what we've already been using, it's an entire new underlying mechanism that makes multithreading easier and makes it easy to be as concurrent as your code can be without worrying about the variables like how much work your CPU cores are doing, how many CPU cores you have and how much threads you should spawn in response.
[5] Cocoa Manual Memory management rules
To increment the retain count of any object, send it the retain message. This is called retaining the object. The object is now guaranteed to persist at least until its retain count is decremented once more. To make this a little more convenient, a retain call returns as its value the retained object — that is, [myObject retain] returns the object pointed to by myObject, but with its retain count incremented.
When you say alloc (or new) to a class, the resulting instance comes into the world with its retain count already incremented. You do not need to retain an object you’ve just instantiated by saying alloc or new (and you should not). Similarly, when you say copy to an instance, the resulting new object (the copy) comes into the world with its retain count already incremented. You do not need to retain an object you’ve just instantiated by saying copy (and you should not).
To decrement the retain count of any object, send it the release message. This is called releasing the object.
If Object A obtained Object B by saying alloc (or new) or copy, or if Object A has said retain to Object B, then Object A should balance this eventually by saying release to Object B, once. Object A should assume thereafter that Object B no longer exists.
[6] Frame vs bounds
The frame of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within. The bounds of a view is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).
[7] Naming convention for classes, objects and methods
Class names must be unique across an entire app. Use 2 letter prefix related to company name or application name or specific component. If multiple words needed, then Camel case letter is preferred to use.
Method name should be expressive and unique within a class. It do not have prefix, and it should start from the lowercase letter; camel case for multiple words.
Local variable must be unique within the same scope.
[8] NSOperationQueue vs GCD
GCD :Simple, light weight, Low level C based API focused on lock free algorithms and performance.
NSOperationQueue : Internally implemented using GCD. Recommended to use NSOperationQueue instead of GCD unless specific it doesn’t support.
[9] Why Objective – C is a dynamic programming language ?
Static typed languages are those in which type checking is done at compile-time, whereas dynamic typed languages are those in which type checking is done at run-time.
—- in other words —
Objective-C is a dynamically-typed language, meaning that you don't have to tell the compiler what type of object you're working with at compile time. Declaring a type for a variable is merely a promise which can be broken at runtime if the code leaves room for such a thing. You can declare your variables as type id, which is suitable for any Objective-C object.
[10] Cocoa and Cocoa Touch Frameworks
Uses 2 frameworks:
“Cocoa” (OS X) = Foundation framework + Appkit
“Cocoa Touch” (iOS) = Foundation framework + UIKit [In iOS, Appkit replaced with UIKit]
[11] iOS App (multi)layered Architecture
Cocoa Touch : Responsible for View Controllers, Story board, Gestures and event ending.
Includes following frameworks - UIKit, Map, Push notification service, Message UI, Game Kit, iAd.
Media: Audio/Video frameworks like Core Video, Core Graphics, Core Image, Image I/O, OpenGL, GL Kit, Asset Library, Quartz (2D), Core Animation, Core Audio, AVFoundation.
Core Services : Object Oriented cover over OS. Taking care of GCD, iCloud storage, inAppPurchase, Foundation framework., Core Data, SQLite library, Core Foundation, Core Location.
Core OS : Low level Networking, External Accessories, memory allocation, threading, standard I/O. file system, A MAC 4XBSD unix kernel with C API.
[12] App States
Not running State: The app has not been launched or was running but was terminated by the system.
Inactive state: (Foreground) The app is running in the foreground but is currently not receiving events. ( It may be executing other code though.) An app usually stays in this state only briefly as it transitions to a different state. The only time it stays inactive for any period of time is when the user locks the screen or the system prompts the user to respond to some event, such as an incoming phone call or SMS message.
Active state (Foreground): The app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
Background state: The app is in the background and executing code. Most apps enter this state briefly on their way to being suspended. However, an app that requests extra execution time may remain in this state for a period of time. In addition, an app being launched directly into the background enters this state instead of the inactive state.
Suspended state: The app is in the background but is not executing code. The system moves apps to this state automatically and does not notify them before doing so. While suspended, an app remains in memory but does not execute any code. When a low memory condition occurs, the system may purge suspended apps without notice to make more space for the foreground app.
[13] App Life/Launch Cycle
[a] Main Function :
App entry point “main” function, Creates application level Autorelease pool.
Hands control off to UIKit framework by calling UIApplicationMain.
[b] UIApplicationMain invokes UIApplication, loads storyboard, reads info.plist for application setups. Sets UIApplicationDelegate, that will create UIWindow object and RootViewController.
[c] Main event loop : At launch time that later processes user event such as gestures, sensor readings, redraw.
[d] Background Message : The executes code at background but not received any events. However , mostly it will be on the way of suspended state.
[e] Termination of app : System initiates app termination when it misbehaves, not responding events, out of memory.
[14] Difference between #import in Obj-C and #include in C?
#import contains some logic that will make sure the file included only once. Avoids recursive inclusion. Where it not in the case of #include.
#import is an improved version of #include.
#import brings the entire header file into the current file.
[15] NSOperationQueue vs GCD
GCD :Simple, light weight, Low level C based API focused on lock free algorithms and performance.
NSOperationQueue : Internally implemented using GCD.
Recommended to use NSOperationQueue instead of GCD unless specific it doesn’t support. because, - It can be pause, resume or cancel operations
KVO capabilities upon NSOperation class properties.
Dependencies to execute operations in specific order.
Specific number of operations can be queued.
[16] Exceptions vs Error
Exceptions represent programmer-level bugs like trying to access an array element that doesn’t exist. They are designed to inform the developer that an unexpected condition occurred. Since they usually result in the program crashing, exceptions should rarely occur in your production code.