Explain the difference between Generics and AnyObject in Swift.

Generics are type safe, meaning if you pass a string as a generic and try to use as a integer the compiler will complain and you will not be able to compile your. Because Swift is using Static typing, and is able to give you a compilererror.

If you use AnyObject, the compiler has no idea if the object can be treated as a String or as an Integer. It will allow you to do whatever you want with it.


Explain Encoding, Decoding and Serialization, Deserialization.

Serialization is the process of converting data into a single string or json so it can be stored or transmitted easily. Serialization, also known as encoding. The reverse process of turning a single string into a data is called decoding, or deserialization. In swift we useCodable protocol that a type can conform to, to declare that it can be encoded and decoded. It’s basically an alias for the Encodable and Decodable protocols.


Explain CAShapeLayer.

CAShapeLayer is a CALayer subclass, its provides hardware-accelerated drawing of all sorts of 2D shapes, and includes extra functionality such as fill and stroke colors, line caps, patterns and more.


Explain UIBezierPath.

UIBezierPath class allows us define custom paths that describe any shape, and use those paths to achieve any custom result we want.


What is the difference Stack and Heap ?

Stack is used and automatically removes itself from memory after work is finished. But in Heap the user could do it by writing manual code for deleting from memory.

Stack:

  • Stack is easy to use.
  • It’s kept in RAM on the computer.
  • Created variables are automatically deleted when they exit the stack.
  • It is quite fast compared to Heap.
  • Constructed variables can be used without a pointer.

Heap:

  • Compared to Stack, it is quite slow.
  • It creates memory problems if not used correctly.
  • Variables are used with pointers.
  • It is created at runtime.

What is the difference between Array vs NSArray ?

Array can only hold one type of data, NSArray can hold different types of data. The array is value type, NSArray is immutable reference type.


Explain Queues.

Queues are used to store a set of data, but are different in that the first item to go into this collection, will be the first item to be removed. Also well known as FIFO which means, ’first in first out’.


What is Safe area ?

Safe area allows us to create constraints to keep our content from being hidden by UIKit bars like the status, navigation or tab bar. Previously we used topLayoutGuide and bottomLayoutGuide.


What are generics? How to make a method or variable generics in Swift?

Generic is efficient to write sensitive and reusable functions and types. It is provided in Swift 4. Most of the people use this feature to evade the risk of duplication. 'Arrays' and 'Dictionary' are also referred to generic collection. The libraries of Swift 4 are comprised of generic code.

You can add generics to a method (function) but can’t add to a variable. Understand it with an example:

func Vector3D(x: [T], y: [T], z: [T])
 {    self.xCord = x
    self.yCord = y
    self.zCord = z}

In this example, the generic created here is in a function. You can change the T with anything you want. This is how you can add generic in function.


Explain completion handler.

When our application is making an API call and we are supposed to update the UI to show the data from the API call, then Completion Handler becomes handy and is super convenient.

What is the difference between atomic and nonatomic properties? Which is the default for synthesized properties?

Properties specified as atomic always return a fully initialized object. This also happens to be the default state for synthesized properties. But, if you have a property for which you know that retrieving an uninitialized value is not a risk (e.g. if all access to the property is already synchronized via other means), then setting it to nonatomic can give you better performance than atomic.


What are layer objects?

Layer objects are data objects which represent visual content and are used by views to render their content. Custom layer objects can also be added to the interface to implement complex animations and other types of sophisticated visual effects.

What is SpriteKit and what is SceneKit?

SpriteKit is a framework for easy development of animated 2D objects. SceneKit is a framework inherited from OS X that assists with 3D graphics rendering. SpriteKit, SceneKit, and Metal are expected to power a new generation of mobile games that redefine what iOS devices’ powerful GPUs can offer.


What is Swift and what is Objective-C?

Objective-C is the primary programming language you use to write software for OS X and iOS. It’s a superset of the C programming language and provides object-oriented capabilities and a dynamic runtime. Objective-C inherits the syntax, primitive types, and flow control statements of C and adds syntax for defining classes and methods. It also adds language-level support for object graph management and object literals while providing dynamic typing and binding, deferring many responsibilities until runtime.

Swift is a new programming language for iOS, OS X, watchOS, and tvOS apps that builds on the best of C and Objective-C, without the constraints of C compatibility. Swift adopts safe programming patterns and adds modern features to make programming easier, more flexible, and more fun. Swift feels familiar to Objective-C developers and is friendly to new programmers.


Differentiate app ID from bundle ID. Explain why they are used.

An App ID is a two-part string used to identify one or more apps from a single development team. The string consists of a Team ID and a bundle ID search string, with a period (.) separating the two parts. The Team ID is supplied by Apple and is unique to a specific development team, while the bundle ID search string is supplied by the developer to match either the bundle ID of a single app or a set of bundle IDs for a group of apps.

The bundle ID defines each App and is specified in Xcode. A single Xcode project can have multiple targets and therefore output multiple apps. A common use case is an app that has both lite/free and pro/full versions or is branded multiple ways.


What is Cocoa and Cocoa Touch?

Cocoa vs Cocoa Touch

 
Cocoa Cocoa Touch
 Application development environments for OS X Application development environments for iOS
 Includes the Foundation and AppKit frameworks Includes Foundation and UIKit frameworks
 Used to refer any class/object which is based on the Objective-C runtime & inherits from the root class Used to refer the application development using any programmatic interface

Which are the ways of achieving concurrency in iOS?

The three ways to achieve concurrency in iOS are:

  • Threads
  • Dispatch queues
  • Operation queues

What is Any in Swift?

What is Any in Swift?
Any is the most generic type, representing all objects, including functions. This enables Swift to be more of a functional programming language, allowing you to write very flexible parameters.

AnyObject is the generic type for objects from classes.

NSObject is less generic, representing all of Apple’s special Foundation objects.


What is use of repeat keyword in swift?

The repeat-while loop does not check its condition before the loop body is entered. So a variable (like x in this program) can have any value.

var x = 999
repeat {
// This block is entered on any value of x.
// ... The value is not checked before the block is executed.
print(x)
} while x < 10

What is where keyword in swift?
The where in that context is used as pattern matching.
switch vegetable {

... omissis ...

case let x where x.hasSuffix("pepper"):
let vegetableComment = "Is it a spicy \(x)?"
default:
let vegetableComment = "Everything tastes good in soup."
}


What is use of fallthrough keyword in swift?

A fallthrough statement causes program execution to continue from one case in a switch statement to the next case.
Program execution continues to the next case even if the patterns of the case label do not match the value of the switch statement’s control expression.
var sum = 0
var i = 3
switch i {
case 1:
sum += i
case 2:
sum += i
case 3:
sum += i
fallthrough //allows for the next case to be evaluated
case i % 3:
sum += i
}


Back to Top