Top IOS Interview Questions and Answers (Jan 2019) Part 1
Top IOS Interview Questions and Answers (Jan 2019) Part 1
For more questions, Please check previous articles — Top IOS Interview Questions and Answers for 2018/2019
Q1. Write down the custom method which works similar to
reduce() api?
Ans: sum = array.reduce(0, +)
//reduce() here is an ((Int, ((Int, Int) -> Bool)) ->
Int)
//and the + operator is func +(lhs: Int, rhs: Int) ->
Bool,
//... or ((Int, Int) -> Bool), so there's no need to
define reduce's closure.
Q2. How will you make property’s getter available, but the property is settable only from within code in swift?
Ans: The example below shows a version of the
TrackedString
structure in which the structure is defined with an explicit
access level of public. The structure’s members (including the
numberOfEdits
property) therefore have an internal access level by default.
You can make the structure’s
numberOfEdits
property getter public, and its property setter private, by
combining the
public
and
private(set)
access-level modifiers:
Q3. In swift 4.2, User-defined “Dynamic Member Lookup” Types introduced, What is the purpose for it?
Ans: The driving motivation for this feature is to improve interoperability with inherently dynamic languages like Python, Javascript, Ruby and others. That said, this feature is designed such that it can be applied to other inherently dynamic domains in a modular way.
Swift 4.2 introduces a new
@dynamicMemberLookup
attribute. Types that use it provide "dot" syntax for
arbitrary names which are resolved at runtime - in a completely
type safe way. This provides syntactic sugar that allows the
user to write:
a = someValue.someMember
someValue.someMember = a
mutateParameter(&someValue.someMember)
and have it be interpreted by the compiler as:
a = someValue[dynamicMember: "someMember"]
someValue[dynamicMember: "someMember"] = a
mutateParameter(&someValue[dynamicMember: "someMember"])
This allows the static type of
someValue
to
decide how to implement these dynamic member references.
Q4. What is the difference in functional programming and OOPS?
Ans:
Q5. How will you Protect a keychain item with biometric authentication?
Ans:When you store a secure item like a password or a private key in the keychain, you dictate the conditions under which that item can be accessed later. Among other things, you can tell keychain services that every time it tries to read the item, it should first seek the user’s permission — for example, by authenticating the user biometrically with Face ID or Touch ID. You rely on both the Security and LocalAuthentication frameworks to enable this behavior.
Hope this article is useful for people looking to gain knowledge on iOS interviews, Please ❤️ to recommend this post to others 😊. Let me know your feedback. :)
References:
- https://github.com/apple/swift-evolution/blob/master/proposals/0195-dynamic-member-lookup.md
- https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html
- https://www.educba.com/functional-programming-vs-oop/
- https://developer.apple.com/documentation/localauthentication/accessing_keychain_items_with_face_id_or_touch_id