​Swift is really a powerful and user-friendly programming language for macOS, iOS, watchOS and...

Page 218

Swift

func next() -> members? }

var items = [10,20,30].generate() while let x = items.next() { println(x) }

for lists in map([1,2,3], {i in i*5}) { println(lists) }

println([100,200,300]) println(map([1,2,3], {i in i*10})) When we run the above program using playground, we get the following result: 10 20 30 5 10 15 [100, 200, 300] [10, 20, 30]

Adding Protocol Conformance with an Extension Existing type can be adopted and conformed to a new protocol by making use of extensions. New properties, methods and subscripts can be added to existing types with the help of extensions. protocol AgeClasificationProtocol { var age: Int { get } func agetype() -> String }

class Person { 206


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.