​Quick is just a powerful and intuitive development language for macOS, iOS, watchOS and tvOS....

Page 228

Swift

var tos = TOS<String>() tos.push("Swift") println(tos.items)

tos.push("Generics") println(tos.items)

tos.push("Type Parameters") println(tos.items)

tos.push("Naming Type Parameters") println(tos.items)

let deletetos = tos.pop() When we run the above program using playground, we get the following result: [Swift] [Swift, Generics] [Swift, Generics, Type Parameters] [Swift, Generics, Type Parameters, Naming Type Parameters]

Extending a Generic Type Extending the stack property to know the top of the item is included with 'extension' keyword. struct TOS<T> { var items = [T]() mutating func push(item: T) { items.append(item) }

mutating func pop() -> T { return items.removeLast() } 216


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