{"id":26361649,"url":"https://github.com/prashuk/ios-interviewques","last_synced_at":"2025-03-16T17:39:41.827Z","repository":{"id":106711944,"uuid":"323924560","full_name":"prashuk/iOS-InterviewQues","owner":"prashuk","description":null,"archived":false,"fork":false,"pushed_at":"2025-02-23T06:38:50.000Z","size":40,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T07:28:33.563Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prashuk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-23T14:33:12.000Z","updated_at":"2025-02-23T06:38:54.000Z","dependencies_parsed_at":null,"dependency_job_id":"a41dd682-8c6b-4d33-b742-6070bfd945f2","html_url":"https://github.com/prashuk/iOS-InterviewQues","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prashuk%2FiOS-InterviewQues","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prashuk%2FiOS-InterviewQues/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prashuk%2FiOS-InterviewQues/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prashuk%2FiOS-InterviewQues/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prashuk","download_url":"https://codeload.github.com/prashuk/iOS-InterviewQues/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243909446,"owners_count":20367534,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-16T17:39:41.157Z","updated_at":"2025-03-16T17:39:41.821Z","avatar_url":"https://github.com/prashuk.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iOS-InterviewQues\n\n## iOS \u0026 Swift questions for interviews\n\n1. What is the difference between **Synchronous** \u0026 **Asynchronous** task? \n\n```\nSynchronous: waits until the task have completed\nAsynchronous: completes a task in the background and can notify you when complete.\n```\n\n2. What’s **Completion Handler**? \n\n```\nCompletion handlers are super convenient when our app is making an API call, and we need to do something when that task is done, like updating the UI to show the data from the API call. We’ll see completion handlers in Apple’s APIs like dataTaskWithRequest and they can be pretty handy in your own code.\nThe completion handler takes a chunk of code with 3 arguments:(NSData?, NSURLResponse?, NSError?) that returns nothing: Void. It’s a closure.\nThe completion handlers have to marked @escaping since they are executed some point after the enclosing function has been executed.\n```\n\n3. What’s the difference between the **frame** and the **bounds**? \n\n```\nThe bounds of a UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0). \nThe frame of a UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.\n```\n\n4. What is **Responder Chain** ? \n\n```\nA ResponderChain is a hierarchy of objects that have the opportunity to respond to events received.\n```\n\n5. What is Singleton Pattern ? \n\n```\nThe 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.\nThe singleton pattern guarantees that only one instance of a class is instantiated\n```\n\n6. MVVM:\n\n```\nUIKit independent representation of your View and its state. The View Model invokes changes in the Model and updates itself with the updated Model, and since we have a binding between the View and the View Model, the first is updated accordingly. \n```\n\n7. MVP:\n\n```\nIn MVP the presenter assumes the functionality of the \"middle-man\". In MVP, all presentation logic is pushed to the presenter.\nhttps://www.captechconsulting.com/blogs/ios-design-patterns-mvc-and-mvvm\n```\n\n8. What is the Swift main **advantage** ? \n\n```\nOptional Types, which make applications crash-resistant\nBuilt-in error handling\nClosures\nMuch faster compared to other languages\nType-safe language\nSupports pattern matching\n```\n\n9. Explain what is **defer** ? \n\n```\ndefer keyword which provides a block of code that will be executed in the case when execution is leaving the current scope.\nAnd it will execute that code whether the scope is exiting cleanly, from a guard, or while an error is being thrown.\nWhen more than one are included, they will be called in reverse order. Think of them being included on a stack and popping them off one at a time.\n```\n\n10. How to pass a variable as a **reference** ? \n\n```\nWe need to mention that there are two types of variables: reference and value types. The difference between these two types is that by passing value type, the variable will create a copy of its data, and the reference type variable will just point to the original data in the memory.\n```\n\n11. How to **pass data** between view controllers?\n\n```\nSegue, in prepareForSegue method (Forward)\nDelegate (Backward)\n```\n\n12. KVC — KVO\n\n```\nKVC adds stands for Key-Value Coding. It’s a mechanism by which an object’s properties can be accessed using string’s at runtime rather than having to statically know the property names at development time.\n\nKVO stands for Key-Value Observing and allows a controller or class to observe changes to a property value. In KVO, an object can ask to be notified of any changes to a specific property, whenever that property changes value, the observer is automatically notified.\n```\n\n13. Core Data\n\n```\nWhat is NSFetchRequest?\nNSFetchRequest is the class responsible for fetching from Core Data. Fetch requests are both powerful and flexible. You can use fetch requests to fetch a set of objects meeting the provided criteria, individual values and more.\n\nExplain **NSPersistentContainer**\nThe persistent container creates and returns a container, having loaded the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.\n\nExplain **NSFetchedResultsController**\nNSFetchedResultsController is a controller, but it’s not a view controller. It has no user interface. Its purpose is to make developers’ lives easier by abstracting away much of the code needed to synchronize a table view with a data source backed by Core Data.\nSet up an NSFetchedResultsController correctly, and your table will mimic its data source without you have to write more than a few lines of code.\n```\n\n14. Please explain **final** keyword into the class?\n\n```\nBy adding the keyword final in front of the method name, we prevent the method from being overridden. If we can replace the final class keyword with a single word static and get the same behavior.\nThe difference is that subclasses can override class methods; they cannot override static methods.\n```\n\n15. What is the difference **fileprivate**, **private** and **public private**(set) access level ?\n\n```\nfileprivate is accessible within the current file, private is accessible within the current declaration.\npublic private(set) means getter is public, but the setter is private.\n```\n\n16. REST, HTTP, JSON — What’s that?\n\n```\nHTTP is the application protocol or set of rules, websites use to transfer data from the web server to client. The client (your web browser or app) use to indicate the desired action:\nGET: Used to retrieve data, such as a web page, but doesn’t alter any data on the server.\nHEAD: Identical to GET but only sends back the headers and none of the actual data.\nPOST: Used to send data to the server, commonly used when filling a form and clicking submit.\nPUT: Used to send data to the specific location provided.\nDELETE: Deletes data from the specific location provided.\nREST, or REpresentational State Transfer, is a set of rules for designing consistent, easy-to-use and maintainable web APIs.\nJSON stands for JavaScript Object Notation; it provides a straightforward, human-readable and portable mechanism for transporting data between two systems. Apple supplies the JSONSerialization class to help convert your objects in memory to JSON and vice-versa.\n```\n\n17. What is the difference between a **delegate** and an **NSNotification**?\n\n```\nDelegates and NSNotifications can be used to accomplish nearly the same functionality. However, delegates are one-to-one while NSNotifications are one-to-many.\nThere are many different ways such as Delegate, KVO, Segue, and NSNotification, Target-Action, Callbacks.\n```\n\n18. What are the **states** of an **iOS** App?\n\n```\nNon-running — The app is not running.\nInactive — The app is running in the foreground, but not receiving events. An iOS app can be placed into an inactive state, for example, when a call or SMS message is received.\nActive — The app is running in the foreground, and receiving events.\nBackground — The app is running in the background, and executing code.\nSuspended — The app is in the background, but no code is being executed.\n```\n\n19. What is **Downcasting**?\n\n```\nWhen we’re casting an object to another type in Objective-C, it’s pretty simple since there’s only one way to do it. In Swift, though, there are two ways to cast — one that’s safe and one that’s not.\nas used for upcasting and type casting to bridged type\nas? used for safe casting, return nil if failed\nas! used to force casting, crash if failed. should only be used when we know the downcast will succeed.\n```\n\n20. What is the difference ANY and ANYOBJECT ?\n\n```\nAny can represent an instance of any type at all, including function types and optional types.\nAnyObject can represent an instance of any class type.\n```\n\n\u003e **Optional chaining** is a process for querying and calling properties, methods, and subscripts on an optional that might currently be nil. If the optional contains a value, the property, method, or subscript call succeeds; if the optional is nil, the property, method, or subscript call returns nil. Multiple queries can be chained together, and the entire chain fails gracefully if any link in the chain is nil. We use optional chaining when we do not really care if the operation fails; otherwise, we use if let or guard. Optional chaining lets us run code only if our optional has a value.\n\n21. Explain the difference between atomic and nonatomic synthesized properties\n\n```\natomic : It is the default behaviour. If an object is declared as atomic then it becomes thread-safe. Thread-safe means, at a time only one thread of a particular instance of that class can have the control over that object.\n\nnonatomic: It is not thread-safe. We can use the nonatomic property attribute to specify that synthesized accessors simply set or return a value directly, with no guarantees about what happens if that same value is accessed simultaneously from different threads. For this reason, it’s faster to access a nonatomic property than an atomic one.\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprashuk%2Fios-interviewques","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprashuk%2Fios-interviewques","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprashuk%2Fios-interviewques/lists"}