156.Write a String reverse program

157.When would you use Swift’s Result type?

The Swift Result Type

Apple added the Result type to the Swift Standard Library in Swift 5. It’s an enum with a success and failure case both of which have an associated value. You can use any type for Success but Failure is constrained to Error:

enum Result<Success, Failure> where Failure : Error {

case success(Success)

case failure(Failure)

}

158.What is a UUID, and when might you use it?

Suggested approach: UUID stands for “universally unique identifier”, which is a long string of hexadecimal numbers stored in a single type.

UUIDs are helpful for ensuring some value is guaranteed to be unique, for example you might need a unique filename when saving something.

For bonus points, perhaps explain why we call them universally unique — if you created 100 trillion UUIDs there’s a one in a billion chance of generating a duplicate.

159.What is the difference between the Float, Double, and CGFloat data types?

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.

160.Types of ranges?

There are multiple types of ranges in Swift you can use. The easiest way of working with them is by making use of the range operator. Let’s go over the different types available in Swift.

Closed range operator going from a…b

A closed range operator going from a…b defines a range that includes both a and b in which a must not be greater than b.

The closed operator is useful if you’d like to use all the values.

Half-open range operator going from a..<b

A half-open range defines a range going from a to b but does not include b. It’s named half-open as it’s containing its first value but not its final value. Just like with the closed range, the value of a must not be greater than b.

The half-open operator can be used to iterate over zero-based lists such as arrays and collections in Swift in which you want to iterate up to but not including the length of the list.

One-sided operator going from a…

A one-sided range operator only defines one side of the bounds, for example, a… or …b. A one-sided range goes as far as possible in one direction

A one-sided range can be used for iteration but only if used with a starting value a…. Otherwise, it’s unclear where the iteration should start. Iterating over a one-sided range requires you to manually check where the loop should end as it would otherwise continue indefinitely.

161.How would you explain Dynamic Type to a new iOS developer?

Suggested approach: This is a sneaky question, because if you say “I don’t use it” or (worse) “I don’t know what it is”, it sort of means you don’t pay attention to accessibility or user preferences. Dynamic Type is a way of allowing the user to adjust their preferred size for all fonts in all apps, and it’s surprisingly easy to use from both a developer and user perspective. SwiftUI even defaults to using it across the board!

162.What is apple developer/enterprise account??

We can Create two types of Apple account

1.Developer $99

2.Enterprise $299

Developer account We can create Two types of certificate

A.Development

B.Production

A. Development

— It’s use to test app internally

B.Production

— It’s use to upload app on app store

Profiles

There are two types of Profile

1.Development

2.Distribution

1.Development Use this profile for team (internal development purpose)

2.Distribution It’s use to upload app on app store

163.Difference between network location and gps location?

Network location usually refers to cellular location, or wifi location. They are less accurate then GPS (Global Positioning System — satellite based) location. When the app cannot obtain GPS location (probably because the target device is inside a building), the less accurate network location is obtained and uploaded to the map page.

164.I have written for loop from 1 to 10. But when i=7 then then it comes out from loop. I have not written any specific keyword nor exception generated. How it is possible?

for(int i=0, i<10:i++)

{

if(i==6)

{

i=10;

}

}

Here I am trying to iterate from 0 to 9. This loop is iterating till Condition i<10 matches.

Now in iterating, when loop comes i=6 I will make i=10.

So in next iteration, i<10 condition is mismatched. So it comes out from loop.

There is no any keyword used or any exception generated.

165.Difference between FCM and APNS?

  • FCM is sent as JSON payloads and APNS sends either string or dictionary.
  • FCM has a payload of 2KB while APNS has a payload of 4KB.
  • VOIP notification — 5KB
  • APNS saves 1 notification per App while FCM saves 100 notifications per device.
  • FCM supports multiple platforms while APNS requires their proprietary platform.
  • Acknowledgment can be sent in FCM if using XMPP, but it’s not possible on APNS.

Advantage of FCM:

  • Even if the user disallows notification, you can notify your app if the app is running in the foreground (using shouldEstablishDirectChannel).
  • Don’t need to create dashboard to send notification on the device.
  • Notification analytics on FCM Dashboard.
  • Easy to create notification payload structure.
  • App Server side handling is easy, Only one key is required for multiple apps and platform (iOS, Android, Web)

167.Write a program to find missing number of array of 1 to n?

let arr = [1,2,4,5,8,6,9,7]

let n = arr.count

let total = ((n + 1)*(n + 2))/2

var missingNum = total

for item in arr {

missingNum = missingNum — item

}

print(missingNum)

168.Write a program to distinguish lowercase and uppercase character from String in swift?

let string = “iOSiQA is Very Helpful WebSite to Prepare for iOS Interview.”

var output = “”

for chr in string {

var str = String(chr)

if str.lowercaseString != str {

output += str

}

}

print(output)

169.Can we make a class-specific protocol?

You can limit protocol adoption to class types (and not structures or enumerations) by adding the AnyObject or class protocol to a protocol’s inheritance list.

protocol someprotocol : AnyObject, Someanotherprotocol {

}

170.Can we declare an optional protocol method in swift?

Yes. In that protocol name and optional methods should be followed by @objc due to it consider as objective c code.

@objc protocol someprotocol {

@objc optional func somemethod()

@objc optional var someName : String { get set }

}

or

We can make protocol extension and provide default body to protocol method. So any class or struct confirms that protocol doesn’t require implementing that method.

--

--

Sandeep Reddy Challa
Sandeep Reddy Challa

Written by Sandeep Reddy Challa

I have around 14 years of experience in iOS development and lead/senior developer