Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


The following code snippet results in a compile time error:

struct IntStack {

var items = [Int]()

func add(x: Int) {

items.append(x) // Compile time error here.

}

}

Explain why a compile time error occurs. How can you fix it?



The following code snippet results in a compile time error: struct IntStack { var items = [I..

Answer / iosraj

Structures are value types. By default, the properties of a value type cannot be modified from within its instance methods.

However, you can optionally allow such modification to occur by declaring the instance methods as ‘mutating’; e.g.:

struct IntStack {

var items = [Int]()

mutating func add(x: Int) {

items.append(x) // All good!

}

}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Apple iOS Swift Interview Questions

How many types of closures are there in swift?

0 Answers  


What is retain in swift?

0 Answers  


Is swift written in c++?

0 Answers  


What is difference between single and double, in swift?

0 Answers  


What is de-initializer and how it is written in Swift?

1 Answers  


How would you define variables and constants in swift programming language?

0 Answers  


What is a swift class?

0 Answers  


How proficient are you in objective-c and swift? Can you briefly describe their differences?

0 Answers  


Is swift a functional language?

0 Answers  


What is use of enum in swift?

0 Answers  


What is tuple in swift?

0 Answers  


What is enum in swift?

0 Answers  


Categories