Swift Tutorial - Tutorialspoint
} class Player { var stmark: result! init(stmark: result) { self.stmark = stmark } func print(target: classa) { stmark.print(tar ...
Class Only Protocols When protocols are defined and the user wants to define protocol with classes it should be added by definin ...
When we run the above program using playground, we get the following result: res is: 20 res is: 30 res is: 50 Protocol Compositi ...
let student = Person(name: "Roshan", age: 19 ) print(student) When we run the above program using playground, we get the followi ...
class sides { var rectsides: Int init(rectsides: Int) { self.rectsides = rectsides } } let objects: [AnyObject] = [Circle(radius ...
Swift language provides 'Generic' features to write flexible and reusable functions and types. Generics are used to avoid duplic ...
println("Before Swapping Int values are: \(numb1) and \(numb2)") exchange(&numb1, &numb2) println("After Swapping Int va ...
var tos = TOS<String>() tos.push("Swift") println(tos.items) tos.push("Generics") println(tos.items) tos.push("Type Parame ...
} var tos = TOS<String>() tos.push("Swift") println(tos.items) tos.push("Generics") println(tos.items) tos.push("Type Para ...
func exchange<T>(inout a: T, inout b: T) { let temp = a a = b b = temp } var numb1 = 100 var numb2 = 200 println("Before S ...
subscript(i: Int) - > ItemType { get } } struct TOS: Container { // original Stack implementation var items = [T]() mutating ...
tos.push("Type Parameters") println(tos.items) tos.push("Naming Type Parameters") println(tos.items) When we run the above progr ...
// conformance to the Container protocol mutating func append(item: T) { self.push(item) } var count: Int { return items.count } ...
println(tos.items) tos.push("Generics") println(tos.items) tos.push("Where Clause") println(tos.items) var eos = ["Swift", "Gene ...
To restrict access to code blocks, modules and abstraction is done through access control. Classes, structures and enumerations ...
call sum() and its values are printed thereby eliminating return values. To make the function's return type as private, declare ...
Enumeration in Swift language automatically receive the same access level for individual cases of an enumeration. Consider for e ...
When a constant, variable, property, or subscript makes use of a private type, the constant, variable, property, or subscript mu ...
To declare each and every subclass of the initialize 'required' keyword needs to be defined before the init() function. class cl ...
public class mainClass { var no1: Int // local storage init(no1: Int) { self.no1 = no1 // initialization } } class subClass: mai ...
«
4
5
6
7
8
9
10
11
12
13
»
Free download pdf