Ios Interview QA
Ios Interview QA
Ios Interview QA
1. How to make code thread safe in swi . (Objc - Using atomic and Swi - Proprty wrapper
with lock unlock.)
2. How to download and save thousands of data and reload to UI.
https://developer.apple.com/documentation/coredata/
loading_and_displaying_a_large_data_feed
3. 1 array is accessing same me from two thread then what happened? If crashes then how
to resolved.
4. what is single responsibility principle.
https://clean-swift.com/single-responsibility-principle-for-class/
# iPhone SDK:
A so ware development kit (SDK) released by Apple that allows people to write applica ons
for both the iPhone and the iPod Touch. The iPhone SDK includes the Xcode IDE,
Instruments, iPhone simulator, frameworks and samples, compilers, Shark analysis tool, and
more.
1. NSArray VS Array
ti
ft
ti
ft
fi
ti
ti
tt
fi
ti
ti
ti
ft
ft
ti
⁃ NSArray is an immutable Objective C class,
therefore it is a reference type in Swift
⁃ and it is bridged
to Array<AnyObject>. NSMutableArray is the
mutable subclass of NSArray.
1. NSString VS String
⁃ While String and NSString are mostly
interchangeable,
Q : What is Abstraction
Concepts : This is one of the concepts of OOPs
Definition : It mean hiding the complexity of class
Example : Working of car engine is hide from the user
Abstraction
https://cocoacasts.com/how-to-create-an-abstract-class-in-swift
Animation
https://www.yudiz.com/uiview-animation-with-swift-4/
Abstraction Encapsulation
Abstraction solves the problem and issues Encapsulation solves the problem and issue
that arise at the design stage. that arise at the implementation stage.
Abstract class is incomplete class This is complete or Concrete class
Abstraction is about hiding unwanted details Encapsulation means hiding the code and
while giving out most essential details data into a single unit
Exp: In other words, Abstraction means Exp: Class or method to protect the inner
extracting common details or generalizing workings of an object from the outside world.
things
Abstraction lets you focus on what the object Encapsulation means hiding the internal
does instead of how it does details of how an object works. When you
keep internal working details private, you can
change it later with a better method
Abstraction allows you to focus on what the Encapsulation enables you to hide the code
object does instead of how it does it and data into a single unit to secure the data
from the outside world.
Focus mainly on what should be done. Focus primarily on how it should be done.
Abstraction is the method of hiding the Whereas encapsulation is a method to
unwanted information. hide the data in a single entity or unit
along with a method to protect
information from outside.
In Swift we can implement abstraction Whereas encapsulation we can
using protocol implement using access modifier i.n.
private and public.
Abstraction is used to hiding something too Encapsulate hides variables or some
but in a higher degree(class, implementation that may be changed so often
protocol(interface) ). in a class to prevent outsiders access it directly.
They must access it via getter and setter
Clients use an abstract class(or interface) do methods.
not care about who or which it was, they just
need to know what it can do.
Example = When you first describe an Encapsulation is all about implementation. Its
object, you talk in more abstract term e.g. a sole purpose is to hide internal working of
Vehicle which can move, you don't tell how
Vehicle will move, whether it will move by objects from the outside world so that you
using tires or it will fly or it will sell. It just can change it later without impacting outside
moves. This is called Abstraction. We are clients
talking about a most essential thing,
which is moving, rather than focusing on For example, we have a HashMap which
details like moving in plane, sky, or water. allows you to store the object using put()
method and retrieve the object using the get()
There are also different levels of Abstraction
and it's good practice that classes should method. How HashMap Implements this
interact with other classes with the same level method (see here) is an internal detail of
of abstraction or higher level of abstraction. As HashMap, the client only cares that put stores
you increase the level of Abstraction, things the object and get return it back, they are not
start getting simpler and simpler because you
leave out details. concerned whether HashMap is using an
array, how it is resolving the collision,
whether it is using linked list or binary
tree to store object landing on same bucket
etc.
https://javarevisited.blogspot.com/2017/04/difference-between-abstraction-and-
encapsulation-in-java-oop.html
Single Each an every class you Each an every class should have Normal
Responsibil create/change should have only one responsibility Class
ity only one responsibility
Principle
Open Close Classes and Modules should Should not modify the existing Extensions
Principle be open for extension but class for change requirement,
closed for modification rather extent the class
Liskov Child classes should never Extending or Inheriting a child/ Inheritance
substitution break the parent class type derived class should not break
principle definitions any parent or base class
functionality
Interface Make fine grained interfaces The Interface or class API’s to Protocol
Segregation that are client specific client should have minimum
Principle information required by the client
Dependenc High level modules should Class A should not depend on Cocoa pods
y Inversion not depend on low level Class B or vice versa, both should Carthage
Principle modules both should depend be loosely coupled
on Abstractions
Adaptive Layout was introduced in iOS 8 to address the problem of designing user interfaces
for different devices and screen sizes.
In the earlier version of iOS, we had to maintain different storyboards for iPad and iPhone
and with Adaptive Layout we just needed a storyboard for all the devices.
Some of the main components of Adaptive Layout are Auto Layout, Size Classes and
Trait Collections.
Let us try to understand Adaptive Layout by designing the following user interface for
various devices and screen sizes.
Dependency Injection is a technique where you would inject dependencies into an object.
Dependency Injection mean It’s just another Object that our class need to function
● Property Injection
● Constructor Injection
● Method Injection
Property Injection
class LibraryViewModel {
var library = Library?
}
let libraryViewModel = LibraryViewModel()
let library = Library()
libraryViewModel.library = library
Here have the same view model object, but now it is no longer responsible for creating
its own dependency. In this particular example, the dependency is injected into the
LibraryViewModel via the library property and it receiving it from the outside. This kind of
dependency injection is called property injection.
Constructor Injection
class LibraryViewModel {
var library: Library
init(library: Library) {
self.library = library
}
}
Method Injection
protocol LibraryManager {
func deleteAllBooks(in library: Library)
}
class DataManager {
func serializeRequest(request: Request, withSerializer serializer: Serializer) -> Data? {
}
}
Next we have method injection, and if you’re guessing that this is where we inject
dependencies through our methods, you are correct! Here is an example of method injection at
play.
In Swift, UIApplicationMain handles the application’s autorelease pool & we don’t have
to use autorelease by our self. But in some special cases we might need to add our own
autorelease pool.
Here we are using data variable of significant size in a loop. This may take a lot of
device’s memories. To optimize this code we can add autorelease pool as follows:
func processDirectory(){
if let path = NSBundle.mainBundle().pathForResource("directory", ofType: "txt") {
for i in 1...90000{
autoreleasepool {
let data = NSData.dataWithContentsOfFile(path, options: nil, error: nil)
self.processData()
}
}
}
}
Here we are using data in autorelease pool, which gets drained with each iteration of the
for loop when for loop’s scope ends. As releasing the small chunk of memory in each loop may
cause performance issues, we can further optimize it to use autorelease pool in every n
iterations instead of each iteration.
Swift does its memory management very efficiently and does not recommend to
use autorelease.
Still having knowledge of autorelease & using it wisely can help you app to avoid
memory leaks.
200 OK
201 Created
202 Accepted
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
500 Internal Server Error
Operation States
● isReady
● isExecuting
● isFinished
● isCancelled
printerOperation.addExecutionBlock { print("I") }
printerOperation.addExecutionBlock { print("am") }
printerOperation.completionBlock = {
print("I'm done printing")
}
A class you use as-is to create an operation object based on an object and selector from
your application.
In objective C we can create NSInvocationOperation while it’s not available in
Swift.
Example:
@implementation MyCustomClass
- (NSOperation *) taskWithData: (id) data {
NSInvocationOperation *Op = [[NSInvocationOperation alloc] initWithTarget: self
selector: @selector(myTaskMethod :) object: data];
return Op;
}
// This is the method that does the actual work of the task.
- (void) myTaskMethod: (id) data {
// Perform the task.
}
@end
3) Custom Operations
Subclassing Operation gives you complete control over the implementation of your
own operations, including the ability to alter the default way in which your operation executes
and reports its status
https://www.allaboutswift.com/dev/2016/5/21/gcd-with-qos-in-swift
Types of QualityOfService
● User Interactive
All UI related tasks need to be assigned that QoS class. It basically tells iOS to
run them on the main thread.
● User Initiated
This is the class to choose if a task is triggered by the user but doesn't have to be
run necessarily on the main thread.
● Default
This class is only listed for informational purposes only. The system defaults to
this class when not enough information is available to determine QoS.
● Utility
This class needs to be chosen for tasks that have a dependency on other system
resources like file I/O or network I/O. Those tasks need to wait for a certain
amount of time before they are able to complete. They are always in one way or
another initiated by the user who waits for their completion.
● Background
This class is supposed to be used for maintenance tasks - Tasks that don't depend
on their fast execution and that are oblivious to the user.
● Grand Central dispatch (Multi threading concept) GCD is a library that provides a low-
level and object-based API to run tasks concurrently while managing threads behind the
scenes. Terminology
● Dispatch Queues:- A dispatch queue is responsible for executing a task in the first-in,
first-out order
● Serial Dispatch Queue :- A serial dispatch queue runs tasks one at a time.
● Concurrent Dispatch Queue:- A concurrent dispatch queue runs as many tasks as it can
without waiting for the started tasks to finish.
● Main Dispatch Queue:- A globally available serial queue that executes tasks on the
application’s main thread.
8.1)NSOperation — NSOperationQueue —
NSBlockOperation?
https://www.appcoda.com/ios-concurrency/
NSOperation :- Adds a little extra overhead
compared to GCD, but we can add
dependency among various operations and re-use, cancel or suspend them
NSOPERATION:
https://medium.com/shakuro/nsoperation-and-nsoperationqueue-to-improve-concurrency-in-
ios-e31ee79c98ef
Class Structure
Class is a reference type and its Structure is a value type hence
object is created on Heap its object is created on Stack
memory. memory.
fi
s
Example:
Int,String,
Class, Functions and Double,Array,Set,Dictionary,
closer Struct, Enum and Tuple
Class can have a constructor Structure can only have the
and destructor of all types. parameterized constructor. it
means a structure can not have
the non-parameterized
constructor,the default
constructor and destructor also.
The member variable can be The member variable cannot be
initialized directly. initialized directly.
We can call diinit in class We can not call diinit in struct
Object of class can be let if Object of struct should be var if
you want to change the value you want to change the value of
of property property
ARC will the object of class ARC is not work on Value type
if object reference count is
zero
Note: Stack is used for static memory allocation and Heap for dynamic memory
allocation, both stored in the computer’s RAM
===================================================================
===
SWIFT
===================================================================
===
fi
❖ You can "extend" an existing class (with an extension), but even then you
must define completely at compile time what that extension consists of.
Ref : https://stackoverflow.com/questions/29924477/is-swift-a-dynamic-or-static-language
Objective-C:
Objective-C is dynamic, and since, in real life, you will probably be using Swift in the
presence of Cocoa, you can use the Objective-C runtime to inject / swizzle methods in a Swift class
that is exposed to Objective-C
You can do this even though you are speaking in the Swift language. But Swift itself is
static, and in fact is explicitly designed in order to minimize or eliminate the use of Objective-C-
type dynamism.
https://www.hackingwithswift.com/example-code/language/whats-the-difference-
between-a-static-variable-and-a-class-variable
Where static and class differ is how they support inheritance: When you make a
static property it becomes owned by the class and cannot be changed by
subclasses, whereas when you use class it may be overridden if needed.
For example, here’s a Person class with one static property and one class
property
class Person {
static var count: Int {
return 250
}
class var averageAge: Double {
return 30
}
}
If we created a Student class by inheriting from Person, trying to override count (the static
property) would fail to compile if uncommented, whereas trying to override averageAge (the class
property) is OK:
class Student: Person {
// THIS ISN'T ALLOWED
// override static var count: Int {
// return 150
// }
// THIS IS ALLOWED
override class var averageAge: Double {
return 19.5
}
}
You implement this initialization process by de ning initializers, which are like
special methods that can be called to create a new instance of a particular type.
Unlike Objective-C initializers, Swift initializers do not return a value. Their primary
role is to ensure that new instances of a type are correctly initialized before they are
used for the rst time
Instances of class types can also implement an initializer, which performs any
custom cleanup just before an instance of that class is deallocated. For more
information about deinitializers, see Deinitialization.
Swift de nes two types of initializers for class types to help ensure all stored
properties receive an initial value. These are known as designated initializers and
convenience initializers.
Designated initializers and deinitializers must always be provided by the
original class implementation.
Ans: https://docs.swift.org/swift-book/LanguageGuide/Initialization.html
1) Default Initializers
Swift provides a default initializer for any class or structure that provides default
values for all of its properties and does not provide at least one initializer itself. The
default initializer simply creates a new instance with all of its properties set to their
default values.
Exp:
class ShoppingListItem {
var name: String?
var quantity = 1
var purchased = false
}
var item = ShoppingListItem()
fi
fi
fi
.
init(parameters) {
statements
}
3) Convenience Initializers
● Convenience Initializers give me an easy way to create a speci c type of
Object
● Convenience Initializers is optional and create an object and present the value
of Property of Clas
● Convenience Initializers must call default or designated initialize
convenience init(parameters) {
self.init()
}
https://www.youtube.com/watch?v=LxKZf0LyRbA
https://medium.com/@abhimuralidharan/initializers-in-swift-part-1-intro-convenience-and-
designated-intializers-9adf5632fb52
4) Failable Initializers
https://www.youtube.com/watch?v=RXnCNQBLiEQ
init?(age:Int) {
if age < 0 {
return nil
}
}
6) Required Initializers
fi
fi
r
Write the required modi er before the de nition of a class initializer to indicate
that every subclass of the class must implement that initializer:
class SomeClass {
required init() {
// initializer implementation goes here
}}
You must also write the required modi er before every subclass implementation
of a required initializer, to indicate that the initializer requirement applies to further
subclasses in the chain. You do not write the override modi er when overriding a
required designated initializer
class SomeSubclass: SomeClass {
required init() {
// subclass implementation of the required initializer goes
here
}
}
var userName:String?
userName = "Value"
//if let
if let name = userName {
print(name)
}
//Guard
func getName()->String?{
guard let name = userName else { return nil }
return name
}
getName()
fi
fi
fi
fi
● https://www.youtube.com/watch?v=9fa3tNZcNJU
● https://www.youtube.com/watch?v=ZL8BFK8bVjk
❖ What is a Subscript ?
❖ Subscripts are used to store and retrieve the values without the use of
separate method with the help of index
❖ To access elements via subscripts write one or more values between square
brackets after the instance name
Re
● https://medium.com/@abhimuralidharan/subscripts-in-swift-51e73cc5ddb5
Example:
class Sample {
private var days = ["One", "Two" , "Three"]
subscript(index: Int) -> String {
get {
return days[index]
}
set(newValue) {
self.days[index] = newValue
}
}
}
var p = Sample()
print(p[0]) // prints One
p[0] = "Monday"
print(p[0]) // prints Monday
struct subexample {
let decrementer: Int
subscript(index: Int) -> Int {
return decrementer / index
}
}
enum Mobile:Int
case iPhone =
case Android =
var name:String
return "Os "
Ref: https://docs.swift.org/swift-book/LanguageGuide/Properties.html
Example
class TestClass
lazy var testString: String =
print("about to initialize the property"
}
fi
return "TestString
}(
Weak Unowned
If Property can be nil then we will use If Property can not be nil then we will
weak use Unowned
We can set nil value to it We can’t set nil value
It must be Var It can be Var or Constant
Weak alway be an optional Unowned always be Non-Optional
❖ Both the static and class keywords allow us to attach variables to a class
rather than to instances of a class.
❖ Create a Student class with properties such as name and age, then
create a static numberOfStudents property that is owned by the Student
class itself rather than individual instances
❖ Where static and class differ is how they support inheritance
❖ When you make a static property it becomes owned by the class and
cannot be changed by subclasses, whereas when you use class it may
be overridden if needed
❖ Type properties are part of a type but not of an instance – also known as
static properties.
❖ Both stored and computed properties can be type properties. For that, you
use the keyword static
Example
}
fi
"
enum Work{
case start
case InProgress
case Finish
case status(total:Int,done:Int)
}
let task = Work.status(total: 10, done: 7)
Example :
indirect enum LinkedListItem<T> {
case endPoint(value: T)
case linkNode(value: T, next: LinkedListItem)
}
fi
Ref:
https://www.hackingwithswift.com/example-code/language/what-are-indirect-enums
===================================================================
===
Ref:
● https://www.youtube.com/watch?v=DBWu6TnhLeY
● https://www.tutorialspoint.com/objective_c/objective_c_protocols.htm
● https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/
ProgrammingWithObjectiveC/WorkingwithProtocols/WorkingwithProtocols.html
Design Patterns:
1 KVO (Key-Value Observing) in Swift
Notify objects about changes to the properties of other objects.
2 Delegates ( to Customize Object Behavior)
Respond to events on behalf of a delegator.
3.Singleton (Managing a Shared Resource Using a Singleton)
Provide access to a shared resource using a single, shared class instance.
4.Build-Up pattern
Ans:
5.Protocol
Ans:
Architecture:
fi
● MVC
● MVVM
● MVP -
● VIPER
https://developer.apple.com/documentation/swift/cocoa_design_patterns#topics
https://www.youtube.com/watch?v=qb05nLPYKz8
https://www.raywenderlich.com/477-design-patterns-on-ios-using-swift-part-1-2
https://medium.com/@saad.eloulladi/ios-swift-mvp-architecture-pattern-a2b0c2d310a3
https://www.cs.colorado.edu/~kena/classes/5448/f12/presentation-materials/myrose.pdf
https://www.youtube.com/watch?v=VcoZJ88d-vM
❖ What is a delegate ?
❖ Delegate is communication pattern through which two classes can communicate
with each other
❖ Delegate is used for one to one communication
❖ Delegate use protocols to create a relationship between two classes
❖ Using delegate you can return something back
Ref:
● https://medium.com/@rguruonline/swift-computed-properties-and-property-
observers-56374675c9e2
fi
fi
fi
fi
fi
fi
fi
● https://medium.com/the-andela-way/property-observers-didset-and-willset-
in-swift-4-c3730f26b1e9
● https://www.appcoda.com/understanding-key-value-observing-coding/
https://www.bignerdranch.com/blog/designing-for-size-classes-in-ios/
❖ What is “dispatch_once” ?
❖ Is dispatch only one time, this is used when we initialize singleton class once.
● If he found that object is no longer used by any one then he will release
that object and memory will be automatically deallocated
● ARC is only apply on reference type like class or Closer not Value type
like Struct, Enum etc.
● ARC work on
❖ Ans: https://www.youtube.com/watch?v=zS4AcyjhKFQ
Example
struct City
var population : In
mutating func changePopulation(new : Int)
population = new
Extension in Same le Y Y Y Y Y
Extension in Other le Y N N Y Y
Same Module / Framework Y Y Y Y Y
Other Module / Framework N N N Y Y
Can Inherited class in same Module Y Y
Can Inherited class in other Module N N N N Y
Open -
1. Can be accessed from anywhere an app or external framework
2. It’s also allow inherited from it
3. It’s method also allow to override it
//module 1
open class Test(){
open func A(){}
}
//module 2
override func A(){} //success
Public-
1. Can be accessed from anywhere an app or external framework
2. It’s not allowed inherit init() and override init()
//module 1
public class TestB(){
public func B(){}
}
//module 2
override func B(){} //error
Internal -
1. Internal is the default access level.
2. Internal classes and members can be accessed anywhere within the same
module(target)/Framework they are de ned
fi
fi
fi
B()
B().name // Error even if accessed from outside the class B{} of B.swift le.
File-private -
1. Only within source le
2. Restricts the use of an entity to its de ning source le
// A.swift
Class A {
fileprivate func someFunction() {
print("I will only be called from inside A.swift file")
}
}
// viewcontroller.swift
override func viewDidLoad() {
super.viewDidLoad()
let obj = A()
obj.someFunction() // error
}
❖ What is method swizzling in Objective C and why would you use it?
❖ As I
Ans:(https://spin.atomicobject.com/2014/12/30/method-swizzling-objective-c/)
fi
fi
fi
fi
VVV IMP
Objective-C => NSArray,NSSet and NSDictionary are the reference typ
Swift => Array, Dictionary and Set are value type
Example:
Objective-C
NSMutableArray * rstArr = [[NSMutableArray alloc] initWithObjects:@"1", nil]
NSMutableArray *secondArr = rstArr
//Case
NSLog(@"%@", rstArr); output : [”1”
NSLog(@"%@",secondArr); output : [”1”
//Case
[ rstArr addObject:@"2"
NSLog(@"%@", rstArr)
NSLog(@"%@",secondArr)
print( rstArr) output : [”1”,”2”
print(secondArr) output : [”1”,”2”]
Swift:
var rstArr = [“1“
var secondArr = rstAr
//Case 1
print( rstArr) output : [”1”
print(secondArr) output : [”1”
//Case
rstArr.append(2
print( rstArr) output : [”1”,”2”
print(secondArr) output : [”1”
If you want to use reference type in Swift then we have to user NSArray,NSSet and
NSDictionary in swift which is available
1.Optionals
● which handle the absence of a value.
fi
fi
fi
fi
fi
fi
2
fi
)
fi
fi
fi
fi
● Optionals say either “there is a value, and it equals x” or “there isn’t a value at
all”
2.Type safety
● Once a variable is declared with a particular type, its type is static and cannot
be changed.
● Swift is a type-safe language, which means the language helps you to be clear
about the types of values your code can work with
● Example: If part of your code requires a String, type safety prevents you from
passing it an Int by mistake
3.Tuples
● Tuple to return multiple values from a function as a single compound value.
var person = ("John", "Smith"
var rstName = person.0 // Joh
var lastName = person.1 // Smith
4.Multiline string
var text = """
This is some text "HI"
over multiple lines
"""
O/P = This is some text "HI"
over multiple lines
print(text)
● let 🐶 🐮 = "dogcow"
7.Semicolons
● Unlike many other languages, Swift doesn’t require you to write a semicolon (;)
after each statement in your code, although you can do so if you wish.
However, semicolons are required if you want to write multiple separate
statements on a single line:
fi
● Integers are whole numbers with no fractional component, such as 42 and -23.
Integers are either signed (positive, zero, or negative) or unsigned (positive or
zero)
9.Floating-Point Numbers
● Floating-point numbers are numbers with a fractional component, such as
3.14159, 0.1, and -273.15
Defer
Swift also gives us the defer keyword, which provides a safe and easy way to handle
code which we want executed only when the program leaves the current scope
It’s execute the code end of function and for that we need to declare that rst
Web Service:
A Web Service is de ned by the W3C as "a software system designed to
support interoperable machine-to-machine interaction over a network" clearly, both are
means of communications.
The difference is that Web Service almost always involves communication over
network and HTTP is the most commonly used protocol. Web service also uses
SOAP, REST, and XML-RPC as a means of communication. While an API can use
any means of communication e.g. DLL les in C/C++, Jar les/ RMI in java, Interrupts
in Linux kernel API etc.
So, you can say that-
fi
fl
fi
fi
fi
Ans: https://www.w3schools.com/tags/ref_httpmethods.asp
test/demo_form.php?name1=value1&name2=value2
Ans:
var a :Int = is Sign Integer which can contain +- value (exm. -10 to 10)
var b : UInt = 10 this is Unsigned Integer which can contain only + value ( 0 to n)
Certificates
What is certificate ?
It’s tells your Mac or Xcode that you have access (right) to run the app on the device and you
have the right to upload app on the device
What is device ID ?
With this device ID you can run your application on your iPhone/iPad
Developer account
We can create Two types of certificate
A.Development
B.Production
A. Development
--We can create max to max 3 certificate
--It’s use to test app internally
B.Production
--We can create max to max 3 certificate
--It’s use to upload app on app store
Enterprise account
We can create Two types of certificate
A.Development
B.Production
A. Development
--We can create max to max 3 certificate
--It’s use to test app internally
B.Production
Profiles
There are two types of Profile
1.Development
2.Distribution
1.Development
Use this profile for team (internal development purpose)
2.Distribution
It’s use to upload app on app store
Attribute
● Atomic,Nonatomic,Strong and weak and Copy and retain
iOS SDK provides classes for handling both of them. For managing JSON data, there is
the NSJSONSerialization class. This one allows to easily convert a JSON data into a
Foundation object (NSArray, NSDictionary), and vise versa.
For parsing XML data, iOS offers the NSXMLParser class, which takes charge of
doing all the hard work, and through some useful delegate methods gives us the tools we need
for handling each step of the parsing.
https://www.appcoda.com/parse-xml-and-json-web-service/
SOAP defines its own security whereas REST inherits security from underlying transport.
SOAP does not support error handling but RESThas built-in error handling. REST
is lightweight and does not require XML parsing
SOAP will return XML based data
REST can return XML, plain text, JSON, HTML etc
NSArray
● NSArray store object in sorted order
NSSet
NSDictionary
● It stores objects as key value pairs.
● Objects are not ordered, but can be retrieved simply by addressing them with an
arbitrary string value.
class Calculator {
private init() { }
static let shared = Calculator()
func addition(num1:Int,num2:Int)->Int {
print("Parent")
return num1 + num2
}
}
!
(In Active) application willResignActive
!
(Background) application didEnterBackground
!
(In Active) "##$%&"'%()*2%$$3)'-45(4-64(7)+8888
!
(Not Running) application willTerminate
Not running:
Inactive:
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 app is running in the foreground and is receiving events. This is the normal mode for foreground apps.
When your app is running but something happens to interrupt it, like a phone call, it becomes
inactive. Inactive means that the app is still running in the foreground but it’s not receiving events.
Active:
Backgrounded:
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. For
information about how to execute code while in the background, see Background Execution.
In this state, your app is not in the foreground anymore but it is still able to run code.
Suspended:
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.
19)Push notification?
Ans:
20)what is layer?
Ans:
● CALayers are simply classes representing a rectangle on the screen with visual content.
● Layers are a lower-level, complex version of the UIView. In reality, it's the UIView
which is a thin layer on top of CALayer
● The size and position of the layer
● The layer’s background color
● The contents of the layer (an image, or something drawn with (CoreGraphics)
● Whether the corners of the layers should be rounded
● Settings for applying a drop shadow to the layer
● Applying a stroke around the edges of the layer
Protocol Extension
Difference between Category/Extension and Inheritance
Category or extention
1. We can add additional functionality in Class without creating Subclass
2. We can not create store property
3. We can create computed property
Inheritance
We can create store and computed property
Ans:
● User default
https://stackoverflow.com/questions/7510123/is-there-any-limit-in-storing-values-in-
nsuserdefaults
26) Current version of Obj C and Main method has 2 arguments arc & argv, what are
those?
Ans: Current version of Obj C 2.0
29)what is posing?
- Objective c allows calss replace fully with another class, that another class is called
“pose as”
https://www.tutorialspoint.com/objective_c/objective_c_posing.htm
Primitive data types are predefined types of data, which are supported by the programming
language. For example, integer, character, and string are all primitive data types
Non-primitive data types are not defined by the programming language, but are instead
created by the programmer. They are sometimes called "reference variables," or "object
references," since they reference a memory location, which stores the data
The primitive data types include byte, int, long, short, float, double, and char. They are part of
the core of Java and you don't need anything special to use them. For example, the following
declares a long variable for a partNumber
Or
Piece of code is thread safe, if its giving proper output even if working with different
thread. Ex : value type are thread safe.
https://stackoverflow.com/questions/28005734/making-a-class-thread-safe-in-ios
@Objc
A function/variable declared as @objc is accessible from Objective-C, but Swift will
continue to access it directly via static or virtual dispatch. This means if the function/
variable is swizzled via the Objective-C framework, like what happens when using Key-
Value Observing or the various Objective-C APIs to modify classes, calling the method
from Swift and Objective-C will produce different results.
Dynamic Keyword:
Using dynamic tells Swift to always refer to Objective-C dynamic dispatch. This is required
for things like Key-Value Observing to work correctly. When the Swift function is called, it
refers to the Objective-C runtime to dynamically dispatch the call.
Example Obj-C =
+ (WebServiceHelper *)sharedInstance
{
static WebServiceHelper *shared = nil;
static dispatch_once_t pred;
dispatch_once(&pred, ^{
shared = [WebServiceHelper new];
});
shared.BaseUrl= BaseUrl;
shared.loadingText = @"Loading";
return shared;}
URLSession In Swift:
URLSession:
The URLSession class and related classes provide an API for downloading data from and
uploading data to endpoints indicated by URLs. The API also enables your app to perform
background downloads when your app isn’t running or, in iOS, while your app is
suspended. A rich set of delegate methods support authentication and allow your app to
be noti ied of events like redirection.
URLCon iguration:
An URLSessionConfiguration object de ines the behavior and policies to use when
uploading and downloading data using an URLSession object. When uploading or
downloading data, creating a con iguration object is always the irst step you must take.
You use this object to con igure the timeout values, caching policies, connection
requirements, and other types of information that you intend to use with
your URLSession object.
URLRequest:
URL request is used to define information related to request which includes http methods, http
body and other fileds.
NSURLSession
f
f
fi
f
of the requests associated with a particular work unit,such as canceling all loads
associated with loading a web page when the user closes the window or tab
4) NSURLSession also provides nicer interfaces for requesting data using blocks,n
that it allows you to combine them with delegate methods for doing custom
authentication handling, redirect handling, etc.
1) defaultSessionCon guration
The default session con iguration uses a persistent disk-based cache (except when the
result is downloaded to a ile) and stores credentials in the user’s keychain. It also stores
cookies (by default) in the same shared cookie store as
the NSURLConnectionand NSURLDownload classes.
2) ephemeralSessionCon guration
An ephemeral session con iguration object is similar to a default session con iguration
(see default), except that the corresponding session object doesn’t store caches, credential
stores, or any session-related data to disk. Instead, session-related data is stored in RAM.
The only time an ephemeral session writes data to disk is when you tell it to write the
contents of a URL to a ile.
3) backgroundSessionCon guration
Lets the session perform upload or download tasks in the background. Transfers
continue even when the app itself is suspended or terminated.
Types of NSURLSessionTasks
Data tasks are used for requesting data from a server, such as JSON data. These
data are usually stored in memory and never touches the File System We can use
NSURLSessionDataTask.
Upload tasks are used to upload data to a remote destination. We can use
NSURLSessionUploadTask.
NSURLConnection:
ff
fi
fi
f
f
fi
f
f
fi
fi
f
if we have an open connection with NSURLConnection and the system interrupt our
App, when our App goes to background mode, everything we have received or sent
were lost.
NSURLSession
solve this problem and also give us out of process downloads. It manage the
connection process even when we don’t have access. You will need to use
application:handleEventsForBackgroundURLSession:completionHandler in your
AppDelegate
1.UITabbarviewcontroller
• Each tab of a tab bar controller interface is associated with a custom view
controller. When the user selects a speci c tab, the tab bar controller
displays the root view of the corresponding view controller, replacing any
previous views. (User taps always display the root view of the tab, regardless
of which tab was previously selected. This is true even if the tab was already
selected.)
1.Navigation controller
1.UITableview
fi
• Table views can have one of two
styles, UITableView.Style.plain and UITableView.Style.grouped.
1.Collectionview
• Collection view display the list of items in multiple column and also allow to
scroll items vertical and horizontal also.
• An item is the smallest unit of data you want to present. For example, in a
photos app, an item might be a single image. The collection view presents
items onscreen using a cell, which is an instance of
the UICollectionViewCell class that your data source con gures and
provides.
• in addition to its cells, a collection view can present data using other types of
views too. These supplementary views can be things like section headers
and footers that are separate from the individual cells but still convey some
sort of information. Support for supplementary views is optional and de ned
by the collection view’s layout object, which is also responsible for de ning
the placement of those views.
Stack view
Stack views provide an easy way to lay out a series of views horizontally or vertically.
1. Horizontal stack view. 2. Vertical Stack view.
The stack view manages the layout of all the views in its arranged Subviews property
Overview. Stack views let you leverage the power of Auto Layout, creating user
interfaces that can dynamically adapt to the device's orientation, screen size, and any
changes in the available space
This is for iOS 9 and above feature ( https://www.appcoda.com/stack-views-intro/
Autolayout
Auto layout is a constraint-based layout system. It allows developers to create an
adaptive UI that responds appropriately to changes in screen size and device
orientation.
IMP LINK
#MVVM – In deep
https://medium.com/swift-india/mvvm-1-a-general-discussion-764581a2d5d9
fi
fi
fi
#Prototype in sswi
https://theswiftdev.com/swift-prototype-design-pattern/
#coredata
h ps://developer.apple.com/documenta on/coredata/se ng_up_a_core_data_stack -
Se ng up core data
h ps://www.raywenderlich.com/7569-ge ng-started-with-core-data-tutorial - Sample app
and key points + integra on
h ps://medium.com/@chetan15aga/ios-interview-ques ons-part-5-core-data-dc97e29835f8
#cocoapods vs caertage
h ps://www.codementor.io/blog/swi -package-manager-5f85eqvygj
#Swi 5 Feature
tt
tt
tt
tt
tt
tt
tt
tt
tt
tt
tt
tt
tt
tt
tt
tti
ti
ft
ft
tt
ti
fi
ti
fi
ft
ti
ft
ti
ft
ti
tti
fi
ft
ti
tti
ti
ft
ti
ft
Security:
h ps://www.netguru.co/blog/ios-app-security-how-to-protect-users-sensi ve-data-in-mobile-
applica ons\
#SSL Pinning :
h ps://appinven v.com/blog/ssl-pinning-in-ios-app/
Codable :
h ps://hackernoon.com/everything-about-codable-in-swi -4-97d0e18a2999
h ps://learnappmaking.com/codable-json-swi -how-to/
#Factory Method
• Class factory methods are implemented by a class as a convenience for clients. They
combine alloca on and ini aliza on in one step and return the created object.
#Map
h ps://medium.com/@abhimuralidharan/higher-order-func ons-in-swi - lter-map-reduce-
atmap-1837646a63e8
#Closures in swi
h ps://docs.swi .org/swi -book/LanguageGuide/Closures.html
h ps://medium.com/the-andela-way/closures-in-swi -8aef8abc9474
Block:
h ps://stackover ow.com/ques ons/39609727/di erence-between-comple on-handler-
and-blocks-ios
h ps://www.appcoda.com/objec ve-c-blocks-tutorial/
GCD:
h ps://www.appcoda.com/grand-central-dispatch/
Design pa erns:
h ps://www.raywenderlich.com/477-design-pa erns-on-ios-using-swi -part-1-2
ti
tt
ti
ft
ft
ti
fl
fl
ft
ti
ti
ti
ti
ti
ft
tt
ff
ft
ft
ti
ft
ft
ft
fi
ti
ti
#Tuples
h ps://www.tutorialspoint.com/swi /swi _tuples.htm
# UI Development Basics
#Mul plier
h ps://www.youtube.com/watch?v=d4UOV0QPVUI
#Auto layout, Size class and vary for trait
h ps://www.youtube.com/watch?v=k 9xJRuVEk
#UICollec onview Flow layout
h ps://www.youtube.com/watch?v=6HiX8SlEKnc
#How to add delete swap bu on to tableview
h ps://www.hackingwithswi .com/example-code/uikit/how-to-customize-swipe-edit-
bu ons-in-a-uitableview
#UI related Interview Ques ons
h ps://medium.com/@chetan15aga/ios-interview-ques ons-part-4-uikit-a8b6c8fda042
#Architectures basics
h ps://mindster.com/ios-app-architecture-best-prac ces/
h ps://yellow.systems/blog/guide-to-the-chat-architecture
h ps://hackernoon.com/how-to-build-an-ecommerce-app-feeea1c10808
Op onal:
#react na ve - Interview ques on
h ps://www.fullstack.cafe/blog/react-na ve-interview-ques ons
h ps://github.com/sudheerj/reactjs-interview-ques ons#what-is-react
h ps://www.netguru.com/codestories/react-na ve-component-lifecycle
h ps://blog.logrocket.com/naviga ng-react-na ve-apps-using-react-naviga on/
h ps://enappd.com/blog/how-to-make-api-calls-in-react-na ve-apps/125/
Firebase No ca on
h ps://www.iosapptemplates.com/blog/ios-development/push-no ca ons- rebase-swi -5
MACOS:
h ps://www.raywenderlich.com/731-macos-development-for-beginners-part-1
//Facebook post
h ps://developers.facebook.com/docs/sharing/ios/
ti
ti
ti
fi
ti
fl
fl
ti
tt
ft
ti
ti
ti
ti
ft
fl
ti
ft
ti
ff
ti
ti
ti
ti
ti
ti
ti
fi
ti
ti
fi
ft
h ps://instabug.com/blog/how-to-submit-app-to-app-store/
h ps://medium.com/@the_manifest/how-to-publish-your-app-on-apples-app-store-in-2018-
f76f22a5c33a
#what is appgroup:
h p://www.theappguruz.com/blog/ios8-app-groups
#Google Maps:
h ps://stackover ow.com/ques ons/20905797/google-maps-ios-sdk-ge ng-direc ons-
between-2-loca ons
#Realm database
https://dzone.com/articles/how-realm-is-better-as-compared-to-sqlite in details
h ps://realm.io/docs/swi /latest/ imp to understand realm opera ons
h ps://www.appcoda.com/realm-database-swi / - details all
What is Realm database? In simple terms, Realm is a non-relational
database management system which allows you to declare relationships
between objects the same as you would do in any object graph in your
language of choice. Realm is mostly used for mobile app development.
Set 9:
Delegate protocol - No ca on
KVO deep - how is know no fy
Closure - (Di between block and closure)
MVC and MVVM
What will use when you give build to user to handle crash - crashes analy cs etc or other ways
What r u using to delivery build - gen ans , circle CI
Google map handling.
Unit test cases.
Objec ve c and swi di erences - as per developer
tt
tt
tt
tt
tt
tt
ti
ff
ti
fl
ft
ti
ff
fi
ft
ti
ti
ti
ti
ft
ti
tti
ti
ti
Architecture for app like amazon there is di erent modules like payment etc.
• Analysis the requirement of the applica on and features.
• Will decide architecture asper project complexity for modulraty , testability and
reusability
There will be products list where user can order and manage their items.
Also there is accoun ng modules for payment and invoice for order.
⁃ If there are mul ple modules
• How to make tableview cell with mul ple controller lets say 10 and some me show 5
or 8 etc how will you do?
• When you do load more how to reload table with reloaddata or else, if reload data
then it will be very s cky.
• What is layout and layout if needed?
• What happened if controller dismissed then can couture retain cycle breaks or not.
Set 10:
⁃ Access speci ers in swi . Di erence between open & public && private le private.
⁃ Cocoapods and carthage di erence.
⁃ Di rence In pod update vs pod install.
⁃ Lazy in swi di erent cases.
⁃ Objec ve C vs Swi .
⁃ How to communicate to view to viewmodel – ex delegate/protocol/no ca on
observer/closures.
⁃ UIWebview vs WKWebview
⁃ What is abstract class and can we provide body in abstract method in abstract class.
ff
ft
ti
fi
fi
tt
ft
fi
ff
ti
ft
ti
ti
ti
ti
ft
ff
ff
ti
ti
ti
ff
ti
ti
fi
fi
ti
ti
⁃ A class that is declared using “abstract” keyword is known as abstract class. It can have
abstract methods(methods without body) as well as concrete methods (regular
methods with body). A normal class(non-abstract class) cannot have abstract
methods.
OOPS:
abstrac on and interface di erence
Mul ple inheritance
Sta c and nal sta c
Are we able to do mul ple inheritance with two abreac on classes
Programs:
Array Manipulation:
ti
ti
ti
fl
fi
ti
ti
ti
ti
ff
ft
fi
ti
fl
ti
String Manipulation:
//*****************************************
//Reverse String
//*****************************************
var str = "Hello, playground"
printArrayWithStandard()
}
print("Fact of 5 is \(fact)")
}
for _ in 0..<10 {
sum = x+y;
x = y;
y = sum;
seriesArr.append(sum)
}
print("Fibbonacci series \(seriesArr)");
}
if flag == 1 {
numbers.append(i)
}
else {
flag = 1
}
}
for i in 0...endIndex {
if palString[i] != palString[endIndex] {
flag = false
break
}
endIndex = endIndex - 1
}
if flag {
print("String is palindrom")
}
else {
print("String is not palindrom")
}
}
seccondMin = min
min = number
}
else if number < seccondMin && number != min {
seccondMin = number
}
}
print(array[index])
index += 1
printElementWitoutLoop(array, index: &index)
}
extension StringProtocol {
subscript(offset: Int) -> Character {
self[index(startIndex, offsetBy: offset)]
}
}
Program to print:
*
*$*
*$*$*
*$*$*$*
column = 7
rows = 4
counter = 1
print(“/n”)
counter += 2
}