在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:onthecodepath/iOS-Interview-Questions开源软件地址:https://github.com/onthecodepath/iOS-Interview-Questions开源编程语言:开源软件介绍:Hello fellow iOS Developers!What is this for?Time is important. It's frustrating and time-consuming to have to search endlessly in order to practice iOS interview questions. The goal of this open-source project is to collect as many iOS interview questions together along with answers in order to save you time. PracticeUse the Table of Contents to practice and test your knowledge. It doesn't show the answer so you'll be able to go over the questions without relying on the answer for help. Table of Contents
Interview Questions & AnswersDatabaseWhat is Core Data?Core Data is a framework that is used to manage model layer objects. It has the ability to persist object graphs to a persistent store. Data is organized into relational entity-attribute model. When would you use Core Data over NSUserDefault?NSUserDefault is typically used to store small bits of data (settings, preferences, etc.). Core Data is used to store a large list of elements. What is a managed object context?First, managed object context is an instance of NSManagedObjectContext. It is the central object in the Core Data stack. It is used to create and fetch managed objects, and to manage undo and redo operations. Although it is allowed to have multiple managed object contexts, there is typically at most one managed object to represent any given record in a persistent store. What is NSFetchRequest?NSFetchRequest is the class responsible for fetching from Core Data. Fetch requests can be used to fetch a set of objects meeting a certain criteria, individual values and more. (source) DebuggingWhat are some ways of debugging in iOS?
Design PatternsWhat is Singleton Pattern?The Singleton design pattern ensures that only one instance exists for a given class and that there’s a global access point to that instance. It usually uses lazy loading to create the single instance when it’s needed the first time. (source) What is the delegation pattern?The delegation pattern is a powerful pattern used in building iOS applications. The basic idea is that one object will act on another object's behalf or in coordination with another object. The delegating object typically keeps a reference to the other object (delegate) and sends a message to it at the appropriate time. It is important to note that they have a one to one relationship. What is MVC?MVC stands for Model-View-Controller. It is a software architecture pattern for implementing user interfaces. MVC consists of three layers: the model, the view, and the controller.
What is MVVM?MVVM stands for Model-View-ViewModel. It is a software architecture pattern for implementing user interfaces. MVVM is an augmented version of MVC where the presentation logic is moved out of the controller and into the view model. The view model is responsible for handling most, if not all, of the view's display logic. A common occurence in MVC is where you have a massive-view-controller (some joke this is what MVC stands for). In order to shrink the size of your view controller and make the logic and readibility of your code easier to follow along, the MVVM will be used. General / UncategorizedWhat considerations do you need when writing a UITableViewController which shows images downloaded from a remote server?
What is a protocol? How do you define your own protocol?A protocol defines a list of required and optional methods for a class that adopts the protocol to implement. Any class is allowed to implement a protocol so that other classes can send message to it based on the protocol methods without knowing the type of class. An example of how a protocol is defined: Objective-C@protocol MyCustomDataSource
- (NSUInteger)numberOfRecords;
- (NSDictionary *)recordAtIndex:(NSUInteger)index;
@optional
- (NSString *)titleForRecordAtIndex:(NSUInteger)index;
@end A common instance protocols are used is providing a DataSource for UITableView or UICollectionView (source) What is waterfall methodology and Agile methodology? What are the differences between them?Waterfall methodology is a sequential model for software development. It is separated into a sequence of pre-defined phases including feasibility, planning, design, build, test, production, and support. On the other hand, Agile development methodology is a linear sequential apporach that provides flexibility for changing project requirements. List of differences:
What is the difference between a class and an object?In the simplest sense, a class is a blueprint for an object. It describes the properties and behaviors common to any particular type of object. An object, on the other hand, is an instance of a class. What is JSON? What are the pros and cons?JSON stands for JavaScript Object Notation. According to wiki, it is a file format that uses human-readable text to transmite data objects consisting of attribute-value pairs and array data types. Pros:
Cons:
What is the difference between not-running, inactive, active, background and suspended execution states?
Is it faster to search for an item in an NSArray or an NSSet?It depends. NSSet is faster to lookup an item in but can hold at most one of any given object. The reason is because NSSet uses hash values in order to find items. NSArray can hold multiple copies of an object but is slower to search for an item as it has to iterate through its entire contents to find it. (source - #25) What is KVO?KVO stands for Key-Value Observing. It allows a controller or class to observe when a property value changes. Memory ManagementWhy do you generally create a weak reference when using self in a block?Sometimes it is necessary it capture self in a block such as when defining a callback block. However, since blocks maintain strong references to any captured objects including self, this may lead to a strong reference cycle and memory leak. Instead, capturing a weak reference to self is recommended in order to avoid this issue: Objective-CSomeBlock* __weak weakSelf = self; What is memory management handled on iOS?iOS uses something called ARC which stands for Automatic Reference Counting. When an object is said to have a strong reference to it, ARC increase its retain count by 1. When the retain count of an object reaches 0, the object will typically be deallocated if there are no more strong references to it. Unlike garbage collection, ARC does not handle reference cycles automatically. What is the difference between weak, strong and unowned?First, objects are strong by default.
Common instances of weak references are delegate properties and subview/controls of a view controller's main view since those views are already strongly held by the main view. (source) What is a memory leak?A memory leak commonly occurs when an object is allocated in such a way that when it is no longer in use or needed, it is not released. In iOS programming, you create certain objects with weak references in order to avoid a strong to strong relationship that creates a retain cycle and a memory leak. What is a retain cycle?Retain cycles can occur when memory management is based on retain count. This typically occurs when two objects strongly reference each other. As a result, the retain count of either object will never reach zero and deallocated from memory (hence retaining each other). What is the difference between copy and retain?Calling retain on an object will increase its retain count by one. When the retain count of an objective reaches 0, the object will be deallocated and released from memory. When you retain an object, you share the same version with whoever passed the object to you. But when you copy an object, you do not share the same version of the object that was passed to you. Instead, a duplicate of that object is created with duplicated values. What is the difference between a stack vs a heap?A stack is a region of memory where data is added or removed in a last-in-first-out (LIFO) order. According to Ates Goral, it is the memory set aside as scratch space for a thread of execution. Meanwhile the heap is memory set aside for dynamic allocation. Unlike the stack, you can allocate a block at any time and free it at anytime. Note: In Objective-C, all objects are always allocated on the heap, or at least should be treated as if on the heap. NetworkingObjective-CWhat is synthesize in Objective-C?Synthesize generates getter and setter methods for your property. What is dynamic in Objective-C?Dynamic is used for subclasses of NSManagedObject. @dynamic can also be used to delegate the responsibility of implementing the accessors. (source) What is the difference between _ vs self. in Objective-C?You typically use either when accessing a property in Objective-C. When you use _, you're referencing the actual instance variable directly. You should avoid this. Instead, you should use self. to ensure that any getter/setter actions are honored. In the case that you would write your own setter method, using _ would not call that setter method. Using self. on the property, however, would call the setter method you implemented. What are blocks in Objective-C?Blocks are a language-level feature of Objective (C and C++ too). They are objects that allow you to create distinct segments of code that can be passed around to methods or functions as if they were values. This means that a block is capable of being added to collections such as NSArray or NSDictionary. Blocks are also able to take arguments and return values similar to methods and functions. The syntax to define a block literal uses the caret symbol(^): Objective-C^{
NSLog(@"This is an example of a block")
} What is the difference between category and extension in Objective-C?A category and extension are similar in functionality where they can add additional instance and class methods to a class. However, an extension can only do so if the source code for the class being extended is available at compile time. This means that classes such as NSString cannot be extended. Instead, a category would be used to add additional methods to the NSString class SwiftWhat is the difference between public and open? Why is it important to have both?Open access imposes limitations on class inheritance. Classes declared with open level access can be subclassed by modules they are defined in, modules that import the module in which the class is defined, and class members as well. While this sounds similar to the public access level defined in Swift 2, there is a small difference. In Swift 3, the meaning of public access level means that classes declared public can only be subclassed in the module they are defined in. This includes public class members which can be overridden by subclasses defined int he module they are defined in. Some classes of libraries and frameworks are not designed to be subclasses. For example, in the Core Data framework, Apple states that some methods of NSManagedObject should not be overridden. To prevent any unexpected behavior that may result from overriding those methods, Apple declares those methods public rather than open. As a result, those methods are not marked as open for developers to override. (source) What is the difference between var and let?var is a variable that can be changed while let denotes a constant that cannot be changed once set. What is the difference between a struct and a class?The main difference to note is that structs are value types (stored on stack) while classes are reference types (stored on heap). Classes have capabilities that structs do not:
What is the difference between implicit and explicit?When referring to something as implicit or explicit, it is often referring to how an object is declared. In the two examples below: Swiftvar name: String = "onthecodepath" // explicit
var name = "onthecodepath" // implicit In the first line above, the name variable is explicitly declared since the type of the variable follows the name of the variable. In the second line, the String type is not explicitly declared. However, Swift is able to infer that name is of a String type since the value that it is being set as is of a String type. Thread ManagementWhat is the difference between synchronous and asynchronous task?Synchronous tasks wait until the task has been completed while asynchronous tasks can run in the background and send a notification when the task is complete. What is the difference between atomic and non-atomic synthesized properties?First, properties are set to atomic by default. Atomic properties are more likely to guarentee thread-safety because it will ensure that a value is fully set (by the setter method) or fully retrieved (by the getter method) when accessor methods are called simultaneously. Non-atomic properties, however are not thread-safe. While they run faster, they may cause race conditions. In the event that accessor methods are called simultaneously and a race condition occurs, a setter value would first release the old value and a getter method would retrieve nil since no value has not been set yet. What is GCD and how is it used?GCD stands for Grand Central Dispatch. According to Ray Wenderlich, it offers the following benefits
In other words, GCD provides and manages queues of tasks in the iOS app. This is one of the most commonly used API to manage concurrent code and execute operations asynchronously. Network calls are often performed on a background thread while things like UI updates are executed on the main thread. Explain the difference between Serial vs ConcurrentTasks executed serially are executed one at a time while tasks that are executed concurrently may be executed at the same time. Spot the bug that occurs in the code:Swiftclass ViewController: UIViewController {
@IBOutlet var alert: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
let frame: CGRect =< |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论