Part 3— iOS Interview Preparation Questions and Explanations

Yasir
3 min readOct 7, 2020

--

100 + Que/Ans Series , I am posting a continue series on iOS Interview questions from a basic concept to advance . 😎

17. Explain Core Data ?

~AppleDocumentation

  • Its a Framework 💯

Apple Says : “Use Core Data to save your application’s permanent data for offline use, to cache temporary data, and to add undo functionality to your app on a single device.” 😮

Core data gives you these features : Persistence , Undo and Redo of Individual or Batched Changes , Background Data Tasks , View Synchronization , Versioning and Migration etcc.. .

Creating a Core Data Model

The first step in working with Core Data is to create a data model file. Here you define the structure of your application’s objects, including their object types, properties, and relationships.

You can create core data model while creating project by check the box “use core data” .

Core Data Stack

After you create a data model file , set up the classes that collaboratively support your app’s model layer. These classes are referred to collectively as the Core Data stack .

There are few Core Data Components :

~ AppleDocumentation
  • An instance of NSManagedObjectModel represents your app’s model file describing your app’s types, properties, and relationships.
  • An instance of NSManagedObjectContext tracks changes to instances of your app’s types.
  • An instance of NSPersistentStoreCoordinator saves and fetches instances of your app’s types from stores.
  • An instance of NSPersistentContainer sets up the model, context, and store coordinator all at once.

Different Data Types in Core Data

Many apps need to persist and present different kinds of information. Core Data provides different attributes, including those common for all databases, such as Date or Decimal type, and non-standard attributes handled with Transformable type.

18. What is Sentinel Value ?

A valid value that represents a special condition such as the absence of a value is known as a sentinel value. That’s what your empty string would be . 🙂

19. Automatic Reference Counting (ARC)

Swift uses ARC to track and manage your app’s memory usage. ARC automatically frees up the memory used by class instances when those instances are no longer needed , you do not needed to think about memory management .

But in few cases ARC requires more information about the relationships between parts of your code in order to manage memory for you .

Reference counting applies only to instances of classes. Structures and enumerations are value types, not reference types, and are not stored and passed by reference.

I Will PUBLISH an entire article on this topic with more detail !

20. What is nested optional ?

Consider the following nested optional — it corresponds to a number inside a box inside a box inside a box.

21. What are Property observers ?

A willSet observer is called when a property is about to be changed while a didSet observer is called after a property has been changed. Their syntax is similar to getters and setters :

struct S {
var stored: String {
willSet {
print("willSet was called")
print("stored is now equal to \(self.stored)")
print("stored will be set to \(newValue)")
}

didSet {
print("didSet was called")
print("stored is now equal to \(self.stored)")
print("stored was previously set to \(oldValue)")
}
}
}
var s = S(stored: "first")
s.stored = "second"
  • willSet was called
  • stored is now equal to first
  • stored will be set to second
  • didSet was called
  • stored is now equal to second
  • stored was previously set to first

Where to go from here ?

Be updated of the series I am uploading , check this link .

My LinkedIn Profile : linkedin.com/in/my-pro-file

--

--