Member-only story

SwiftCodingInterviewQuestions

--

-

  1. we have 3 api call: a,b, and c. b is dependent on a and c is not, how to do with swift programming.
  2. Create a generic function that performs addition.
  3. Suppose we have array of string and multiple apis are getting called how you will handle race condition.
  4. Call API(passing via closure, combine framework, async-await) and show result in table view and Gridview using swift and swiftUI.
  5. explain the delegation pattern and provide an example.

Array questions

  1. Find the Largest Element in an Array, Example Input: [3, 5, 7, 2, 8]Example Output: 8
  2. Merge Two Sorted Arrays, Example Input: [1, 3, 5] and [2, 4, 6]Example Output: [1, 2, 3, 4, 5, 6]
  3. Find All Prime Numbers up to a Given Number, Example Input:10 Example Output:[2, 3, 5, 7]
  4. Implement a binary search function to find the position of an element in a sorted array, Example Input: [1, 3, 5, 7, 9], 5Example 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 =…

--

--

No responses yet