Giter Club home page Giter Club logo

ios_interview_answers's Introduction

iOS Interview Questions and Answers

Classes vs. Structs

YouTube

IMAGE ALT TEXT HERE

Script

Q: What is the difference between a class and a struct in Swift?

A: The main difference is that classes are reference types and structs are value types.

When you pass a class through a function or assign it to a variable, it will increase its reference count.

When you pass a struct through a function or assign it to a variable, its value is copied instead of increasing its reference count.

A good analogy is comparing a google doc to a word doc. When you send someone a word doc they’re able to edit a copy of the document, this is like a struct. And when you send someone a google doc then you’re both able to edit the same document, just like a class.

Other differences are: classes have inheritance, type casting, & de-initializers .


ARC, Retain Cycles, & Memory Leaks

YouTube

IMAGE ALT TEXT HERE

Script

Q: How is memory management handled in iOS?

A: Swift uses Automatic Reference Counting to handle memory management.

Q: What is ARC and how does it work?

A: Automatic Reference Counting keeps track of strong references to instances of classes. It increases or decreases their reference count whenever you assign or unassign them to constants, properties, or variables. Memory only gets deallocated whenever the reference count reaches zero.

Q: What is a memory leak?

A: A memory leak is when an amount of allocated space in memory cannot be deallocated due to a retain cycle.

Q: What is a retain cycle?

A: A retain cycle occurs when two or more objects hold strong references to each other. As a result these objects retain each other in memory because their retain count never reaches zero.

Q: How do you prevent retain cycles?

A: You can prevent a retain cycle by using ‘weak’ or ‘unowned’ references. A good example of this would be using [weak self] in a closure.

Q: What’s the difference between ‘weak’ and ‘unowned’?

A: Weak references are allowed to be nil. Unowned references are never nil.

Q: How do you detect memory leaks?

A: The easiest way to detect a memory leak is by using the debug memory graph. If the memory usage keeps increasing and never decreases then that’s an indicator that you might have a retain cycle.


Observer & Delegation
Work in-progress

Script

Q: What is the Delegation Design Pattern?

A: The delegation design pattern enables an object to delegate some of its responsibilities to another object. The delegating object typically keeps a reference to the other object.

Q: How do you avoid memory leaks when using the delegation pattern?

A: The delegate variable has to be declared as ‘weak’ to avoid a retain cycle.

Q: What are some examples of when we use the delegation pattern in iOS development?

A: The most common place where we use the delegation pattern in iOS development would be with TableViews & CollectionViews.

Q: What is the Observer Design Pattern?

A: The Observer Design Pattern allows an object to notify other objects about changes in its state.

Q: What are some examples of when we use the Observer Design Pattern in iOS development?

A: TODO://

Q: What is the main difference between the Delegation and Observer pattern?

A: The delegation design pattern is a one-to-one relationship, meaning one object communicates with one other object & the observer pattern is a one-to-many relationship, meaning one object can communicate with multiple other objects.


MVC & MVVM
Work in-progress
Static & Singletons
Work in-progress
Access Controls
Work in-progress
3rd Party Libraries
Work in-progress
Data Persistence
Work in-progress
App & VC Lifecycle
Work in-progress
Frames vs. Bounds
Work in-progress
Networking
Work in-progress
Swift Fundamentals
Work in-progress
Testing
Work in-progress
Recruiter Phone Screen
Work in-progress

Other Resources

Videos

Reading


Contributing

Feel free to create issues for questions you want answered.
If you already have a good answer then you can submit a pull request.


Author

James Sedlacek created this to help minimize the amount of time it takes to study for iOS interviews.

ios_interview_answers's People

Contributors

jamessedlacek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.