What is repeat keyword in swift?

The repeat-while loop execute the body of loop once ,it does not matter condition is false or true then its check condition.The repeat-while loop in Swift is same as do-while loop in other programming languages like c,c++ and PHP etc.

var y = 999
repeat {
// This block will get executed for any value of y.
// The value of y will not check before the block is executed.
print(y)
} while y < 10

What is Any in Swift?

Any is generic type, represent all objects of all the types(value type and reference type), including function and optional types.
AnyObject is the generic type that represent all objects of reference type or class type.
NSObject represent all of Apple’s special Foundation objects.


Which are the ways of achieving concurrency in iOS?

There are three ways to achieve concurrency in iOS:

  • By Threads
  • By Dispatch queues
  • By Operation queues

What is Cocoa and Cocoa Touch?

Cocoa and  Cocoa Touch differences-

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

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

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

The bundle ID defines each App and it is given in Xcode. A single Xcode project can have multiple targets and can be output multiple apps.


What is Objective-C?

Objective-C was the main primary programming language to write software for OS X and iOS before development of swift. It is a superset of C programming language that provides object-oriented capabilities and dynamic runtime. Objective-C adds Smalltalk-style messaging to the C programming language with maintaining the compatibility of c.

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 are layer objects?

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

What is the difference between atomic and nonatomic properties?

Atomic is default behavior of properties. Nonatomic is not default behavior of properties. atomic will ensure the present process is finished by the processor, before another process accesses the variable. nonatomic is not thread safe. atomic is thread safe. nonatomic is faster and it may result in unexpected behavior when same variable is accessed by different process at the same time. Atomic is not fast ,as it ensures the process completed entirely


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 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.


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 is Queue?

Queue is a data structure designed to hold same type of objects in FIFO (First in First out) manner. In queue elements are inserted from rear and get removed from front.

What is the difference between Array vs NSArray ?

Array can hold homogeneous(same type) type of data, NSArray can hold hetrogeneous (different type of objects) types of data.The array is value type and NSArray is immutable reference type.

What is the difference Stack and Heap?

Difference between Stack and Heap-

Stack:

  • When variables go out of scope are deallocated automatically.
  • Faster variable allocation in comparison to variables on the heap.
  • Implemented with an actual stack data structure.
  • Stores local data, return addresses, used for parameter passing.
  • Can have a stack overflow when too much of the stack is used (in case of infinite or too deep recursion or very large memory allocations).
  • You can create stack of data without pointers.
  • Use the stack if you know exactly how much data you need to allocate memory before compile time and it should not be too big.
  • The maximum size already determined when program starts.

Heap:

  • In C++, variables on the heap must be deallocated manually and never deallocate when go out of scope. The allocated variable is freed with delete, delete[], or free.
  • Slow allocation when compare to variables allocation on the stack.
  • On demand allocation a block of data for use by the program.
  • When there are a lot of allocations and deallocations cause memory fragmentation.
  • In C++ or C, data created on the heap will be pointed to by pointers and allocated with new or malloc respectively.
  • Memory allocation failures can occurred if too big of a buffer is requested to be allocated.
  • Use heap if don't know how much memory allocation is needed.
  • Heap can causes of memory leaks.

What is UIBezierPath?

UIBezierPath class help us to create custom drawing such as straight and curved line segments on your custom views.


What is  CAShapeLayer explain?

CAShapeLayer is a CALayer subclass, Shape layers are very useful for creating UI elements, and because they are vector-based, they provide resolution independent drawing of all sorts of 2D shapes, and includes extra functionality such as path, fill and stroke colors, line caps, patterns and more.


Explain Encoding, Decoding and Serialization, Deserialization.

Serialization is a process of converting an object into a stream of bytes to transmit over network, save to database or store in a file. Serialization is also called encoding. The reverse process is called decoding or deserialization. In Swift programming if you want to encode and decode a custom object ,you have to implement Encodable and Decodable protocols.


Explain the difference between Generics and AnyObject in Swift.

Generics are type safe, means if you pass a string as a generic and try to use as a integer the compiler will not compel the code because Swift is static typing, and is able to give you a compile time error.

If you use AnyObject, the compiler will treat as object it does not matter it is String type, Integer or anything else. It will allow you to pass whatever you want with it.


What is the singleton class in iOS?

A singleton class returns the same instance ,it does not matter how many times called from application. A singleton object provides a global access the resources of its class. Singletons are used in conditions where single point of control is desirable.


Back to Top