![]() ![]() 3. What’s the Issue and How Can You Fix It?Ĭonsider this piece of code that tries to retrieve a theme color from the local storage of an iOS device: var color = (forKey: "themeColor")!Ĭan you spot the mistake and fix it? Answer: For example, when passing a value type as an argument to a function, a copy of it is created, so whatever the function does is not reflected in the original value. In Swift, all the basic data types (booleans, integers, etc.), enums, and structs are value types by nature.Īrrays are value types too. When moving a value type around in Swift, you’re essentially working with the copy of it. ![]() This is because assigning arr1 to arr2 actually means that a copy of arr1 is assigned to arr2, so the arr1 is not affected. For example: var result = Double(n1) + Double(n2) + n3 2. What is the Value of Variable Len? Why? var arr1 = To fix this, you need to convert each value to the same data type. In the code above, you’re trying to add three elements together, each of which represents a different data type. In Swift, implicit type casting between two data types is not possible. 1. What Causes an Error in This Piece of Code? How Could You Fix It? let n1: Int = 1 These interview questions are in no particular order. You need to know the answers to these before you get a chance to show your skills in front of a job interviewer.Īlso, feel free to use these Swift interview questions to practice for an exam. ![]() These questions focus on Swift programming and iOS app development. Here’s a list of 50 Swift interview questions and answers. ![]()
0 Comments
Leave a Reply. |