---
# System prepended metadata

title: iOS Interview Questions
tags: [ios, swift, interview, swiftUI]

---

# iOS Interview Questions

###### tags: `interview` `ios` `swift`  `swiftUI`

# Swift Questions

### Accessibility
1. Why to use and how to set Accessibility Identitifier?

### Data
1. How is a dictionary different from an array?
    <details>
      <summary>Possible Answer</summary>
  
    **Suggested approach:** It’s all down to how you access data: arrays must be accessed using the index of each element, whereas dictionaries can be accessed using something you define – strings are very common. Make sure and give practical examples of where each would be used.
    </details>
    
2. What are the main differences between classes and structs in Swift?
	* Why would you choose one over the other
	* How does swift solve some problems that other languages have with structs (performance)
	<details>
      <summary>Possible Answers</summary>
      
    **Suggested approach:** Your answer ought to include a discussion of value types (like structs) and reference types (like classes), but also the fact that classes allow inheritance.

    For bonus points you could mention that classes have `deinit()` methods and structs do not.
    </details>
    
3. How are CodingKeys useful
    <details>
      <summary>Possible Answers</summary>
      
    **Suggested approach:** enum over the keys for encoding / decoding. The association betweent the case name and its raw value lets you name your data structures to standards rather than having to match the names and capitalization fo the serialization format you're modeling.
    </details>
    
4. What’s the difference between Float, Double, and CGFloat
    <details>
      <summary>Possible Answers</summary>
      
    **Suggested approach:** It’s a question of how many bits are used to store data: `Float` is always 32-bit, `Double` is always 64-bit, and `CGFloat` is either 32-bit or 64-bit depending on the device it runs on, but realistically it’s just 64-bit all the time.
    
    For bonus points, talk about how Swift 5.5 and onwards allows us to use `CGFloat` and `Double` interchangeably.
    </details>
    
5. What the difference between map() and compactMap()
    <details>
      <summary>Possible Answers</summary>
      
    **Suggested approach:** Remember to give practical examples as well as outlining the core differences. So, you might start by saying the `map()` transforms a sequence using a function we specify, whereas `compactMap()` does that same step but then unwraps its optionals and discards any nil values. For example, converting an array of strings into integers works better with `compactMap()`, because creating an `Int` from a `String` is failable.
    </details>
    
6. Why is immutability important
     <details>
      <summary>Possible Answers</summary>
      
      **Suggested approach:** Immutability is baked deep into Swift, and Xcode even warns if `var` was used when `let` was possible. It’s important because it’s like a programming contract: we’re saying This Thing Should Not Change, so if we try to change it the compiler will refuse.
     </details>
     
7. What are one side ranges
     <details>
      <summary>Possible Answers</summary>
      
      **Suggested approach:** As always, start with a simple definition that clarifies the difference between regular ranges, then provide a practical example.

    So, you might say that one-sided ranges are ranges where you don’t specify the start or end of the range, meaning that Swift will automatically make the range start from the start of the collection or the end of the collection. They are useful when you want to read from a certain position to the end of a collection, such as if you want to skip the first 10 users in an array.
    </details>

8. When would you use the Result type
     <details>
      <summary>Possible Answers</summary>
      
      **Suggested approach:** Start with a brief introduction to what `Result` does, saying that it’s an enum encapsulating success and failure, both with associated values so you can attach extra information. I would then dive into the “when would you use it” part of the question – talking about asynchronous code is your best bet, particularly in comparison to how things like `URLSession` would often pass both a value and an error even when only one should exist at a time.

    If you’d like to go into more detail, more benefits of `Result` include being able to send the result of a function around as value to be handled at a later date, and also the ability to handle typed errors.
    </details>
    
9. What is type erasure, why would you use it.`Combine - advanced`
     <details>
      <summary>Possible Answers</summary>
      
      **Suggested approach:** Type erasure allows us to throw away some type information, for example to say that an array of strings is actually just `AnySequence` – it’s a sequence containing strings, but we don’t know exactly what kind of sequence.

    This is particularly useful when types are long and complex, which is often the case with Combine. So, rather than having a return type that is 500 characters long, we can just say `AnyPublisher<SomeType, Never> `– it’s a publisher that will provide `SomeType` and never throw an error, but we don’t care exactly what publisher it is.
    </details>
    
---
# Below have not worked through...
---

### General
What are you most excited about from WWDC iOS 15 this year?
How do you keep up to date
What do you look for in a PR

### Store Data
How are some ways to store data in iOS
Which is better for
	Security
	Large amount of data
	Small amounts of data

### Memory - Performance
How does Swift handle memory management?
How would I know I have a memory leak
How would I track down a memory leak
How might I test for poor network performance






---
# Swift Questions

https://www.hackingwithswift.com/interview-questions

1. How might you remove all duplicates from an Array?
2. Why is immutability important?
3. How might you iterate through all of the elements in an enum?
4. How is a dictionary different from an array?
5. What is the difference between an array and a set?

- Why don't structs have a deinit() method
- What is type erasure and when would you use it?
- Difference between map and compactMap
- Why is immutability important?  
- Can you talk about KVO
- When would you use the defer keyword in Swift?
- What is the difference between an extension and a protocol extension?
- What is the difference between an escaping closure and a non-escaping closure?
- Can you give useful examples of enum associated values?
- What problem does optional chaining solve?
- What does the CaseIterable protocol do?
- What is the difference between weak and unowned?
- What are opaque return types?

## iOS
- What's the purpose of size classes
- What are some of the advantages of SwiftUI over UIKit
- How would you add a shadow to a view, rounded rectangles

## UIKit
- What is the difference between @IBOutlet and @IBAction?
- What is the purpose of reuse identifiers for table view cells?
- What is the difference between a UIImage and a UIImageView?
- When would you choose to use a collection view rather than a table view?
- How does a view's intrinsic content size aid in Auto Layout?

## Miscellaneous
- Favorite iOS / Swift sites


## Performance
- How would you identify resolve retain cycles
- How might you track down performance problems
- How would you explain ARC to a new developer
- What does final do? Why would you use it
- When would you use autoclosure, 

## Company
- What excited you most about iOS 15 and WWDC this year.
- What do you think of the DSW App?
- What improvemnts would you make
- What is your least favorite iOS SDK?



