Skip to main content

IOS Beginner level [Part 1/4]: Basic concepts and terminology

Started developing iOS  apps? Great ! Before that make sure you have familiar with basic concepts covered in this post. Most probably you started using, but  totally unaware of it.  All these topics are the checklist for your next interview or your presentation and also you are welcome  even if use it as cheatsheet. 
Again I want to stress that it covers only the topic definition or few lines of description. You can find good tutorial sites for rest of in depth explanation.

[1] App
A large ecosystem of interconnected objects that communicate with each other to solve specific problem such as displaying user interface, responding events, inputs and storing information.

[2] App ID
App id is a 2 part string used to identify one or more apps from a single development team. Combination of Team Id and Bundle ID separated by a period character(.) There are 2 types of App Id’s , an Explicit app id used for single app and wildcard app ids (with domain name *) used for set of apps.

[3] Apple ID
A unique apple account login id / user id (basically email id) that allows to access Apple store, iBooks etc.

[4] BundleID
A bundle ID precisely identifies a single app. A bundle ID is used during the development process to provision devices and by the operating system when the app is distributed to customers. For example, Game Centre and In-App Purchase use a bundle ID to identify your app when using these services. The bundle ID string must be a uniform type identifier (UTI) that contains only alphanumeric characters (A-Z,a-z,0-9), hyphen (-), and period (.). The string should be in reverse-DNS format.



[5] Objective – C
Primary programming language for writing app for OS X and iOS. Super set of C language.

[6] 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. Objective-C is a best example for dynamically-typed language, meaning that you don't have to tell the compiler what type of object you're working with at compile time.

[7] Class
Blueprint of object, A class is a data structure that can have methods, instance variables, and properties, along with many other features. A class must have super class. Except,  NSObject and NSProxy classes, which are root classes. Root classes do not have a superclass. 

[8] Object 
Object is an instance of class. Will stored in heap (chunk of memory not in serial ordered) and accessed by using pointers.

[9] Immutable Object
It must set internal contents when it is created, and cannot subsequently be changed by other objects. Ex: NSString, NSNumber, NSDictionary, NSArray. Also are thread safe.

[10] Mutable Object
Object those contents are changing at runtime. Ex: NSMutableString, NSMutableDictionary.
NSMutableString subclasses from NSString

[11] Instance method
Prefix (-) for Instance method, Are accessed only after the class allocates and initialises its instance

[12] Class  / factory / static method
Prefix (+) indicates Class method or Factory method or Static method. We can call static method without creating / using instance of that class.

[13] Subclassing
Overriding methods of existing class.  UIButton, UITextField… are subclassed from UIView.
Eg : myHorizontalLine subclassed class from UIView by overriding method “-(void) drawRect:(CGRect) rect;”

[14] Cocoa and Cocoa Touch
“Cocoa” (OS X) = Foundation framework + Appkit
“Cocoa Touch” (iOS) = Foundation framework + UIKit   [In iOS,  Appkit replaced with UIKit] 
[15] LLVM  (Low Level Virtual Machine) 
It is faster than GCC compiler. Built with optimised library system. Greatly works with IDE.
LLVM parser handles syntax highlighting , code completion and every other index driven features.

[16] Fast enumeration
Fast enumeration is a language feature that allows you to enumerate over the contents of a collection.

[15] Collection
Collection classes are like NSArray, NSDictionary, NSSet.
Use [NSNull null] or NSNil object to represent no object in collection.

[16] Sandbox
For security reasons, iOS restricts each application (including preferences and data) into unique location in the filesystem. This restriction is called Application’s sandbox. Each app has access to the contents of its own sandbox. 

[17] Keychain
Is a secure, encrypted container for password data. Stored outside of application sandbox.

[18] Ad-Hoc Application 
It allows pre-release copies of app. Way to get app review before release.

[19] Thread-Safe
Thread safe code can be safely called from multiple threads or concurrent tasks without causing any problems (data corruption, crashing, etc). Code that is not thread safe must only be run in one context at a time. 
An example of thread safe code is NSArray. You can use it from multiple threads at the same time without issue. On the other hand, NSMutableArray is not thread safe and should only be accessed from one thread at a time.

[20] Context Switch
A context switch is the process of storing and restoring execution state (context) of a process or thread, when we switch between executing different threads on a single core (single process). So that the execution can be resumed from the same point at a later time. This enables multiple processes to share a single CPU and is an essential feature of a multitasking operating system. It’s like switching from one thread (process) to another.

[21] Notifications
NSNotification object provides a mechanism for broadcasting information. Async message passing b/w objects don’t know each other. They just know the broadcaster from which they have registered. (matches the key)

[22] Malloc 
Creates a block of memory (which is not associated with any object).

[23] Free 
System does not release Malloc based memory blocks. Hence used for releasing such blocks.

[24] Retain Counting 
Retain counts are the way in which memory is managed in Objective-C. When you create an object, it has a retain count of 1. When you send an object a retain message, its retain count is incremented by 1. When you send an object a release message, its retain count is decremented by 1. When you send an object a autorelease message, its retain count is decremented by 1 at some stage in the future. If an objectʼs retain count is reduced to 0, it is deallocated. 

[25] ARC Automatic Reference Counting 
ARC is a compiler ­level feature that simplifies memory management of objective-c objects. Instead of you having to remember when to retain or release an object, ARC evaluates the lifetime requirements of your objects and automatically inserts the appropriate method calls at compile time. Makes sure every object is nil or points to an object (i.e. No memory leak and no dangling pointers).

[26] Plist
Property lists organise data into named values and lists of values using several object types. These types give you the means to produce data that is meaningfully structured, transportable, storable, and accessible, but still as efficient as possible. The property-list programming interfaces for Cocoa and Core Foundation allow you to convert hierarchically structured combinations of these basic types of objects to and from standard XML. You can save the XML data to disk and later use it to reconstruct the original objects.

[27] Launch Image
When an app is launched, the system displays a temporary image until the app is able to present its user interface. This temporary image is your app’s launch image and it provides the user with immediate feedback that your app is launching and will be ready soon. You must provide at least one launch image for your app and you may provide additional launch images to address specific scenarios. 

[28] Responder Chain  
When the event happens in a view, the view will fire the event to chain of UIResponder objects associated with the view. The first UIResponder object is UIView itself. If it does not handle the event, then it continues up the chain until UIResponder object handled this event. It included UIViewControllers, UIView’s parent views and their associated UIViewControllers. if none of these handles UIWindow is asked and at last UIApplicationDelegate. 

[29] Chain of Responsibility
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.

[30] Dangling Pointer
A pointer whose object has been destroyed. Solution : After de-allocating memory, initialise pointer to NULL so that pointer will be no longer dangling. 

[31] Memory Leak 
An object without pointer is useless, it is occupying memory. But not other object can event get, a reference to it. An object  fails to go out of existence when no other objects exists that have a pointer to it. Possibly crashing with EXC_BAD_ACCESS error.

[32] Autorelease
When object sends ‘Autorelease’ message, that object is placed in autorelease pool, and a number is incremented saying how many times this object has been placed in this autorelease pool. From time to time, when nothing else is going on, the autorelease pool is automatically drained - This means that autorelease pool sends release message to each of its objects. Causes retain count zero and destroyed in the usual way.
So autorelease is a form of release; but with the policy “later, not right this second!”. 

[33] Autorelease Pool 
Autorelease pool blocks provide a mechanism whereby you can have ownership of an object, but avoid the possibility of it being deallocated immediately (such as when you return an object from a method). Autorelease pool instances are stored in pre-thread stack. Remember, each thread has its own stack of pools, which is used to determine which pool to put an object in when it gets autoreleased. It will create pool if not created (otherwise looks up current pool) and calls addObject:. Later when the pool is destroyed, release message sent to each objects from top to bottom of stack.

[34] Retain Cycle 
Situation where 2 objects are each retaining another, Neither object’s retain count decremented to zero. Resulting in memory leak.

[35] Posing 
Objective-C permits a class to replace with another class within a program. The replacing class is said to "pose as" the target class. NSObject contains the poseAsClass: method that enables us to replace the existing class as said above.

[36] Method swizzling


Method swizzling allows the implementation of an existing selector to be switched at runtime for a different implementation in a classes dispatch table. Swizzling allows you to write code that can be executed before and/or after the original method. For example perhaps to track the time method execution took, or to insert log statements

Popular posts from this blog

Animating label text update - choosing a better way

Recently I published a countdown app .  At one point of development - I have to show a timer on a UILabel which ticks on each seconds. As usual I started  setting text to a label object - self .timerLabel.text = someString Easy piece of cake right !?   But wait ... it won't take much user attention when timer ticks on every seconds. So I decided to make use of a simple animation while label gets text update. I found there are dozens of ways to animate a label. In this short article, I listed 3 best way you can animate text on a label. ( Spoiler Alert 👀- I decided to go with 3rd option)  1. Fade In - Fade out animation : CATransition class has got transition type `fade`. With timing function of CATransition - I was able to see the below result. let animation: CATransition = CATransition () animation.timingFunction = CAMediaTimingFunction (name: CAMediaTimingFunctionName .easeInEaseOut) animation.type = CATransitionType .fade animation.subtype = C...

Prevent Navigationbar or Tabbar overlapping Subview - solved for Card view

Recently, I started with a Card view added as a subview of UIView in a view-controller. When a view controller created along subviews, it tends to use entire screen bounds and also slips behind Tab bar or Navigation bar. In my current situation, it's second case. Casually new iOS developers will write a patch by additional value for coordinate y and subtracting bar height from its size. A lot of them posted in SO threads too : How to prevent UINavigationBar from covering top of view? View got hidden below UINavigationBar iOS 7 Navigation Bar covers some part of view at Top So, how I got solved ? self.edgesForExtendedLayout = [] This  will avoid all subviews in a view controller get behind any bars. Read full apple  documentation on here. Full Source code below :  //Simple view controller where its view layed-out as a card. class WidgetCardViewController : UIViewController { var containerView = UIView () //MARK:- View Controller Life Cyc...

Printing Staircase Pattern : Swift coding challenge

In this post, we can try interesting pattern printing challenge in Swift. The problem statement goes like this " Print a staircase of given size 'n'. Make sure that its base and height are both equal to n, and the image is drawn only using `#` symbols and spaces. The last line is not preceded by any spaces." Expected Output : # ## ### #### ##### ###### Working solution: func makePatternOf ( _ size : Int ) { var str = "" // 1 for index in ( 0 ..< size ) { let stop = size -index-1; // 2 for _ in 0 ..< stop { str. append ( " " ) ; } // 3 for _ in 0 .. . index { str. append ( "#" ) ; } print ( str ) str = "" } } makePatternOf ( 6 ) Loop to visit every row of stair case. Loop for appe...

Implementing autocompletion OTP field in iOS

Long waiting is over. !!  iOS 12 brings Autofill for OTP text field which is close to Android provided a decade back. Previously in iOS we used to toggle between OTP text screen and message inbox.  Which was hard to remember and time consuming resulting a bad user experience. Personally, I have been asked from the client/customer couple of times to implement autocompletion for OTP field and took me a lot of time to convey that it is not possible in iOS. Why Autofill was not possible previously?  We all know that Apple gives at most care for user privacy. When we see iOS architecture, each individual app is like a separate island. There is no inter-app bridge between apps (exception for Keychain and URLSchemes APIs which gives very limited scope). Thus we cannot read message content from inbox. Where to start Autofilling? First of all, the target SMS need to have the OTP Code with prefix string "Code" or "Passcode"on its message content. Beware of OTP c...

UICollectionViewCell shows with wrong size on First time - Solved

We commonly use Collection view where its cell size calculated run time. The flow layout delegate is responsible to return individual cell sizes. BUT in most of the cases, delegate method `collectionView: layout sizeForItem:` expects cell size too early. Before generating actual cell size. extension YourViewController : UICollectionViewDelegateFlowLayout { func collectionView ( _ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize (width: externalWidth, height: externalHeight) } } For instance, if a cell size depends on external view and its frame is not yet ready - results with wrong (or outdated) cell size. Typically happens for the first time view controller laid out all views. You can find similar queries in StackOverflow community : Collection view sizeForItemNotWorking UICollectionViewCell content wrong size on first load How to refresh UICollec...