Top IOS Interview Questions and Answers (April 2019) Part III

Previous: Top IOS Interview Questions and Answers (April 2019) Part II

Q1. How to identify a pure UIView subview out of various Custom View subviews?

Parsing through the subviews of a parent view, It has various subviews, all custom classes, of 10 different UIView subclasses. There is just one class which is a normal UIView.

Now when I am looping through, I need to get hold of the UIView subview, isKindOfClass is failing to do so as it returns 1 for all the UIView subclasses as well.

[currentView isMemberOfClass:[UIView class]];

isKindOfClass:

Returns a Boolean value that indicates whether the receiver is an instance of given class or an instance of any class that inherits from that class.

isMemberOfClass:

Returns a Boolean value that indicates whether the receiver is an instance of a given class.

Q2. How to get list of common elements of 2 array in Swift?

I have two arrays:

let fruitsArray = ["apple", "mango", "blueberry", "orange"]
let vegArray = ["tomato", "potato", "mango", "blueberry"]

How can I get the list of common items in those two array which gives

ouptput = ["mango", "blueberry"]

Explanation of the results

Using the Array approach uses "Brute force"-search which has time complexity O(N^2) where N = array1.count = array2.count which is in contrast to the Set approach O(N). However the conversion from Array to Set and back is very expensive for large data which explains the increase of critical #elements for bigger data types.

Q3. Is it Correct ?

Using filter with .filter(array1.contains) is performance wise faster than .filter{ array1.contains($0) }

Answer: A conversion from Array to Set is kind of expensive while the conversion from Set to Array is in contrast very inexpensive.

Using filter with .filter(array1.contains) is performance wise faster than .filter{ array1.contains($0) } since:

  • the last one creates a new closure (only once) whereas the first one passes only a function pointer
  • for the last one the call of the closure creates an additional stack frame which costs space and time (multiple times: O(N))

Q4. How do I check in Swift if two arrays contain the same elements regardless of the order in which those elements appear in?

Q5. What is A/B testing? Does Apple Test flight supports A/B testing?

AB testing is a great practice from the marketing world. One subset of users is presented with one type of UI or feature, and another subset with another. These two different types of UI and/or features are called variations A and B (hence the name A/B testing).

Later on, the user’s behavior is observed to see which group performed better in regards to KPIs (key performance indicators) such as revenue, conversion, etc. The winning variation becomes the mainstream feature/UI of the app and is set as the default behavior for all users.

Mobile A/B testing implementations often turn out to be quite messy. We’ve observed some practices that help implement more sane A/B testing.

Yes, Apple supports it. Simply create a group of testers and add the builds you’d like them to test. You can also create multiple groups and add different builds to each one, depending on which features you want them to focus on.

References:

  1. https://stackoverflow.com/questions/32439289/how-to-get-list-of-common-elements-of-2-array-in-swift