Member-only story
SwiftCodingInterviewQuestions
6 min readJan 30, 2025
-
- we have 3 api call: a,b, and c. b is dependent on a and c is not, how to do with swift programming.
- Create a generic function that performs addition.
- Suppose we have array of string and multiple apis are getting called how you will handle race condition.
- Call API(passing via closure, combine framework, async-await) and show result in table view and Gridview using swift and swiftUI.
- explain the delegation pattern and provide an example.
Array questions
- Find the Largest Element in an Array, Example Input:
[3, 5, 7, 2, 8]
Example Output:8
- Merge Two Sorted Arrays, Example Input:
[1, 3, 5]
and[2, 4, 6]
Example Output:[1, 2, 3, 4, 5, 6]
- Find All Prime Numbers up to a Given Number, Example Input:
10
Example Output:[2, 3, 5, 7]
- Implement a binary search function to find the position of an element in a sorted array, Example Input:
[1, 3, 5, 7, 9], 5
Example Output:2
Create a generic function that performs addition.
protocol Addable {
static func + (lhs: Self, rhs: Self) -> Self
}
extension Int: Addable {}
extension Double: Addable {}
extension String: Addable {}
func add<T: Addable>(_ a: T, _ b: T) -> T {
return a + b
}
// Usage:
let intResult = add(10, 20) // 30
let doubleResult = add(5.5, 2.3) // 7.8
let stringResult =…