Swift Interview Prep

Swift Interview Prep

memorize.aimemorize.ai (lvl 286)
Section 1

Preview this deck

What is CoreData?

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

6 years ago

Date created

Mar 1, 2020

Cards (37)

Section 1

(37 cards)

What is CoreData?

Front

Is a framework that is used to manage the model layer objects in your application. It provides generalized and automated solutions to common tasks associated with object life cycle and object graph management, including persistence. Advantages Decreases by 50 to 70 percent the amount of code you write to support the model layer. This primarily due to the following built-in features that developer do not have to implement, test, or optimize: Change tracking and built-in management of undo and redo beyond basic text editing. Maintenance of change propagation, including maintaining the consistency of relationships among objects. Lazy loading of objects. Automatic validation of property values. Schema migration tools that simply schema changes and allow developers to perform efficient in-place schema migration. Optional integration with the application's controller layer to support user interface synchronization. Grouping, filtering, and organizing data in memory and in the user interface. Automatic support for storing objects in external data repositories. Effective integration with the macOS and iOS tool chains.

Back

Do you happen to know some objective c?

Front

Yes, Objective-C is the primary programming language you use when writing 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. Rather than creating an entirely new class to provide minor additional capabilities over an existing class, it's possible to define a category to add custom behavior to an existing class. You can use a category to add methods to any class, including classes for which you don't have the original implementation source code, such as framework classes like NSString. Objective-C uses protocols to define a group of related methods, such as the methods an object might call on its delegate, which are either optional or required. The NSString class is used for strings of characters, the NSNumber class for different types of numbers such as integer or floating point, and the NSValue class for other values such as C structures. You can also use any of the primitive types defined by the C language, such as int, float or char. Error Objects Are Used for Runtime Problems.

Back

What's a memory leak?

Front

A memory leak is a portion of memory that is occupied forever and never used again. It is garbage that takes space and causes problems. For Apple: "Memory that was allocated at some point, but was never released and is no longer referenced by your app. Since there are no references to it, there's now no way to release it and the memory can't be used again"

Back

What is a Swift Protocol?

Front

A protocol is a set of methods, properties, etc. that are closely related in order to perform related functionality. Protocols can then be adopted by something (class, struct, enum) which then must provide their own implementation of the requirements. If a type fulfills all the requirements of a protocol, it conforms to the protocol. From Apple: "A protocol defines a blueprint of methods, properties, and other requirements that suit a particular task or piece of functionality. The protocol can then be adopted by a class, structure, or enumeration to provide an actual implementation of those requirements. Any type that satisfies the requirements of a protocol is said to conform to that protocol."

Back

Escaping vs Non-Escaping?

Front

@nonescaping closures: When passing a closure as the function argument, the closure gets execute with the function's body and returns the compiler back. As the execution ends, the passed closure gets out of scope and have no more existence in memory. Lifecycle of the @nonescaping closure: - Pass the closure as function argument, during the function call. - Do some additional work with the flow. - Function runs the closure. - Function returns the compiler back. @escaping closures: When passing a closure as the function argument, the closure is being preserved to be executed later and functions' body gets executed, returns the compiler back. As the execution ends, the scope of the passed closure exist and have existed in memory, till the closure gets executed.

Back

What are the states of the App?

Front

Not running Inactive Active Background Suspended

Back

Exposure with git flow?

Front

Git Flow is a branching model for Git. It has attracted a lot of attention because it is very well suited to collaboration and scaling the development team. Some of the benefits are: - Parallel development: New development is done in feature branches, and is only merged back into main body of code when the developers decide that the code is ready for release. - Collaboration: Each feature branch is a sandbox where where the only changes are the changes necessary to get the new feature working. That makes it very easy to see and follow what each other collaborator is doing. - Release staging area: As new development is completed, it gets merged back into the develop branch, which is staging area for all completed features that haven't yet been released. So when the next release is branched off of develop, it will automatically contain all of the new stuff that has been finished. - Support for emergency fixes: GitFlow supports hotfix branches (branches made from a tagged release). You can use that to make an emergency change, safe in the knowledge that the hotfix will only contain your emergency hotfix. There's no risk that you'll accidentally merge in new development at the same time.

Back

Map vs Compact Map

Front

Compact Map. Returns an array containing the non-nil results of calling the given transformation with each element of this sequence. Use this method to receive an array of non-optional values when your transformation produces an optional value. Map or flatMap returns an array containing the concatenated results of calling the given transformation with each element of this sequence. You would use this method to receive a single-level collection when your transformation produces a sequence or collection for each element.

Back

What is an urlSession?

Front

An object that coordinates a group of related network data transfer tasks. 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 notified of events like redirection.

Back

Forced unwrapping.

Front

Force unwrapping is used when you are sure that the optional does contain a value, and you can access its underlying value by adding an exclamation mark to the end of the optional's name. There are some scenarios in which forced unwrapping an Optional can make sense, such as the outlets' scenario.

Back

Reuse identifier.

Front

A string used to identify a cell that is reusable. The reuse identifier is associated with a UITableViewCell object that the table-view's delegate creates with the intent to reuse it as the basis (for performance reasons) for multiple rows of a table view. It is assigned to the cell object in initWithFrame:reuseIdentifier: and cannot be changed thereafter. A UITableView object maintains a queue (or list) of the currently reusable cells, each with its own reuse identifier, and makes them available to the delegate in the dequeueReusableCell(withIdentifier:) method.

Back

Any vs Any Object.

Front

AnyObject refers to any instance of a class and is equivalent to id in Objective-C. It's useful when you specifically want to work with a reference type because it won't allow any of Swift's structs or enums to be used. AnyObject is also used when you want to restrict a protocol so that it can be used only with classes. Any refers to any instance of a class, struct, or enum - literally anything at all. You'll see this in Swift wherever types are unknown or are mixed in ways that can be meaningfully categorized

Back

Experience with different size classes and auto layout:

Front

AutoLayout Defines relationships between objects, using constraints instead of defining what position an object should be in based on pixels. Allows the view to adapt to different screen sizes, since its relationship based The UI equivalent of SVG Size Classes Groups of screen sizes based on height and width 2 options for each, compact, and regular wC (compact width) hC (compact height) wR (regular width) hR (regular height) wCxhR, wCxhC, wRxhR, wRxhC Can set different constraints for different size classes using InterfaceBuilder and AutoLayout

Back

Grand Central Dispatch (GCD) / NSOperation

Front

Both technologies are designed to encapsulate units of work and dispatch them for execution. GCD is a low-level C API that interacts directly with Unix level of the system. NSOperation is an Objective-C API and that brings some overhead with it. Instances of NSOperation need to be allocated before they can be used and deallocated when they are no longer needed. Even though this is a highly optimized process, it is slower than GCD, which operates at a lower level. The NSOperation API is great for encapsulating well-defined blocks of functionality. GCD is ideal if you just need to dispatch a block of code to a serial or concurrent queue.

Back

What kind of options does iOS provide for data persistence?

Front

Persistance options: CoreData (Quick, SQLite database under the hod, can store custom objects, Apple provided API and framework, 1st party solution) KeyChain UserDefaults (It can only contains certain data types) SQLite Database Saving files directly to file system NSKeyedArchived (NSCoding) REALM (Third-Party Framework to help manage objects and a SQLite database) Property List (p-List Something every app has can store very little data, A solution)

Back

What is tuple?

Front

A tuple is a group of different values represented as one. According to Apple, tuple type is a comma-separated list of zero or more types, enclosed in parentheses.

Back

1.- Have you worked with Agile?

Front

Agile software development refers to a group of software development methodologies based on iterative development, where requirements and solutions evolve through collaboration between self-organizing cross-functional teams. Agile methods or Agile processes generally promote a disciplined project management process that encourages frequent inspection and adaptation, a leadership philosophy that encourages teamwork, self-organization and accountability, a set of engineering best practices intended to allow for rapid delivery of high-quality software, and a business approach that aligns development with customer needs and company goals. Agile development refers to any development process that is aligned with the concepts of the Agile Manifesto.

Back

Delegate vs notification.

Front

Delegation allows an object to send a message to another object( the delegate), so that it can customize the handling of an event. The important point about delegation is the way it is implemented allows for minimal dependency between the delegating object and its delegate. The delegating object needs to have a reference to its delegate so that it can call methods in the delegate. Notification differs from the delegation in that it allows a message to be sent to more than one object. It is more like a broadcast rather than a straight communication between two objects. It removes dependencies between the sending and receiving objects by using a notification center to manage the sending and receiving notifications. The sender does not need to know if there are any receivers registered with the notification center. There can be one, many or even no receivers of the notification registers with the notification center. The other difference between notifications and delegates is that there is no possibility for the receiver of a notification to return a value to the sender.

Back

What are the four principals of object oriented programming (OOP)?

Front

Encapsulation Abstraction Inheritance Polymorphism

Back

What differences are between Strong, Weak and Unowned references?

Front

Strong: * Can be constant (let) * variable (var) * optional * or non-optional * increases retain count by 1 * default in Swift Weak: * variable only (var) * optional only (can not be non-optional) * does not increase retain count * typical use case is for delegates. You don't want to create a retain cycle between a delegator and a delegate. Unowned: * can be constant (let), * variable (var), * non-optional only (cannot be optional), * does not increase retain count * typical use case: capture list for a closure in order to avoid retain cycles From Apple: "Use a weak reference whenever it is valid for that reference to become nil at some point during its lifetime. Conversely, use an unowned reference when you know that the reference will never be nil once it has been set during initialization."

Back

Value Types vs Reference Types - describe the difference, and how are these related to Swift?

Front

Swift has only two categories for types. Value, and reference. "A Value Type holds the data within its own memory allocation and a Reference Type contains a pointer to another memory location that holds the real data." Value type: each instance holds an independent value after copying. So, if you have a value type, we'll call it 'a', and you assign it to another variable, 'var b = a', you now have two different values. Changing the value of either will not effect the value of the other. In Swift, value types are structs, enums, or tuples. Reference type: each instance holds a reference to the same value, after copying. If we have a reference type, we'll call it 'a' and we assign it to another variable, 'var b = a', we now have two things that reference the same value. Changing either a or b will change the value of the other as well, since they reference the same value. In Swift, reference types are classes. From Apple: "Types in Swift fall into one of two categories: first, "value types", where each instance keeps a unique copy of its data, usually defined as a struct, enum, or tuple. The second, "reference types", where instances share a single copy of the data, and the type is usually defined as a class. In this post we explore the merits of value and reference types, and how to choose between them."

Back

Differences between MVVM vs MVC?

Front

Model-View-Controler (MVC) Is a software architectural pattern for implementing user interfaces on computers. Model: Your data model (the class or struct that is the model or models for your app) View: The UI component. The user can interact with the app via the View Controller: Responsible CRUD operations go here. The go-between for the Model and View. Would handle fetching the data, controlling the data and model, and providing the tools and functions so the View can configure and operate correctly Model-View-View-Model (MVVM) Adds a layer of abstraction Takes the business logic out of the View or View-Controller Provides access to the data model to the view in such a way that the objects are easily presented Model: Your data model View: The UI component of the app View-Model: the part of the app that provides access to the data in an easy to handle format, so the view is not responsible for any business logic.

Back

What are your options for saving things to the device?

Front

UserDefaults Data Archiving and Unarchiving Property lists Keychain Saving Files Core Data

Back

What is a closure in Swift?

Front

Closure: A block of code. Closures: Can be passed around and used in your code Can be parameters/arguments to functions Very useful if you want to wait for something to be done, and then run some code, like with a network call, you can wait for the data to get back, and then run the block of code that is the closure, or parameter, to your method.

Back

Talk to me about your work with network controllers.

Front

The first thing that we need is to define our EndPointType protocol. This protocol will contain all the information to configure an EndPoint, which is basically a URLRequest with all its comprising components such as headers, query parameters, and body parameters. Then, I would configure parameters for a specific endPoint. Also, we need to make HTTPHeaders as well as parameters and encoding as type aliases probably inside a group, just to keep some order. We use a type alias to make our code cleaner and more concise. Next step is to define a protocol ParameterEncoder with one static function encode. The encode method takes two parameters an inout URLRequest and Parameters. INOUT is a Swift keyword that defines an argument as a reference argument. The ParameterEncoder protocol will be implemented by a JSONParameterEncoder and URLPameterEncoder. A ParameterEncoder performs one function which is to encode parameters. This method can fail so it throws an error and we need to handle. To do this I simply create an enum that inherits from Error. The next step is to encode the parameters. These are encoded to JSON and with the appropriate headers. Following that, we make a completion type alias. This would have an EndPoint which it uses to make requests and once the request is made, it passes the response to the completion. Then we declare a private variable of type URLSessionTask, which essentially does all of the work. Next step is to create a URLSession using the shared session. This is the simplest way of creating a URLSession. Then we create our request by calling a function and giving it a route which is an EndPoint. This call is wrapped in a do-try-catch block, as errors could be thrown by our encoders. We simply pass all response, data, and error to the completion. The function is responsible for all the vital work in our network layer. Essentially converting EndPointType to URLRequest. Since most API expect all bodyParameters as JSON and URLParameters to be URL encoded we just pass the appropriate parameters to its designated encoder.

Back

What is Singleton?

Front

"A singleton class is a design pattern that only allows a single instantiated instance of a class. You do this by making the constructor private and having a static method that "getInstance" that will be a pointer to a local copy. NOTE, in general, it's NOT thread safe" From Apple: "Several Cocoa framework classes are singletons. They include NSFileManager, NSWorkspace, and, in UIKit, UIApplication and UIAccelerometer. The name of the factory method returning the singleton instance has, by convention, the form sharedClassType. Examples from the Cocoa frameworks are sharedFileManager, sharedColorPanel, and sharedWorkspace."

Back

Exposure to Jenkins?

Front

Jenkins offers a simple way to set up a continuous integration or continuous delivery environment for almost any combination of languages and source code repositories using pipelines, as well as automating other routine development tasks. While Jenkins doesn't eliminate the need to create scripts for individual steps, it does give you a faster and more robust way to integrate your entire chain of build, test, and deployment tools than you can easily build yourself.

Back

What is the security you have implemented in your apps?

Front

Keychain service is the best place to store small secrets, like passwords and cryptographic keys. You use the functions of the keychain services API to add, retrieve, delete, or modify keychain items. Secure Transport using standardized transport layer security mechanisms. CryptoSwift is a growing collection of standard and secure cryptographic algorithms implemented in Swift. This method takes an account and password and saves a hashed string on Keychain instead of a direct string.

Back

Talk to me about downloads on the main thread.

Front

In iOS the main thread executes synchronously. Synchronous queue means that operations run one after the other in order. For development purposes what that means is that if something is running synchronously, it waits for each operation to finish before moving on to the next one. UIApplication runs on the applications main thread. So, if there is an operation blocking your main thread takes a long time to complete, it could wreak serious havoc with your application.

Back

SOLID Principals

Front

Single responsibility principle Open/closed principle "Liskov substitution principle" Interface segregation principle Dependency inversion principle

Back

What is the use of guard?

Front

A guard statement is used to transfer program control out of scope if one or more conditions aren't met. The value of any condition in a guard statement must be of type Bool or a type bridged to Bool. The condition can also be an optional binding declaration.

Back

Talk about the use of bridging headers in Swift.

Front

A bridging header serves as a link between your Swift code and Objective C code when it's in the same project. It allows you to access objc classes in your swift code, and to access swift classes in your objc code. Objective C is not able to use Swift structs.

Back

View Controller Life Cycle:

Front

ViewController lifecycle functions viewDidLoad() * called only once during the entire life of the VC * generally, this is a place where you can do an initial network call to begin to load data for the VC viewWillAppear() * called right before the view appears. Good place to refresh the data set you have from the network * good place to make some adjustments to the view, if needed * gets called every time the view is about to appear viewDidAppear() * called right after the view appears * gets called every time after the view appears viewWillDisappear() * called just before the view disappears * good place to cancel network calls for data/assets that are no longer needed viewDidDisappear() * also a good place to cancel network calls/loading of resources, etc. * called every time the view did disappear.

Back

Compare protocols and subclassing:

Front

Subclassing The subclass inherits functions and properties from the superclass Can override some functions, if you need a custom implementation Protocols Not a class Just set of requirements for closely related functionality Can be adopted to provide that functionality for an object Creates more module code

Back

Do you know how to call an API/additional experience?

Front

Once we have a valid URL where we are going to ask for data, best known as API, is the moment to make a request for this network. Most common way to do that is URLSessions class, which helps us to manage network requests. It can be created with our own settings, or just call share attribute which contain default setting for us. Then we are ready to create the request or task to the URL using dataTask function.

Back

Differences between Swift 3 vs Swift 4?

Front

Strings now conforms to Collection protocol. New substring type which represents a subsequence String. Simple syntax for multiline string literals using three double-quotes without any escaping. Dictionary can be initialized with sequence now, but not all sequences can be passed in this initializer. Introduction of Codable protocol instead of Serialization by NSCoding. Smart KeyPaths, unlike #keyPath(), which is not strongly typed and works only for Objective-C members, is a generic class, which means key paths are now strongly typed.

Back

What are extensions?

Front

An extension allows you to add functionality to a class, struct, enum, protocol, etc. It's highly useful when you don't have access to the class (Such as the classes that are part of apple's iOS SDK/Framework) Can be used to conform to protocols. Can be used to organize code (conforming to protocols in extensions, keeps all the functionality of that protocol in the same place)

Back