Swift Tutorial - Tutorialspoint
AnyObject To represent the instance of any class type, 'AnyObject' keyword is used. class Subjects { var physics: String init(ph ...
println("Instance equation is: (samplechem.equations)") let samplemaths = Maths(physics: "Fluid Dynamics", formulae: "Giga Hertz ...
println("None") } } When we run the above program using playground, we get the following result: Instance physics is: solid phys ...
Functionality of an existing class, structure or enumeration type can be added with the help of extensions. Type functionality c ...
var div: Int { return self / 5 } } let addition = 3.add println("Addition is \(addition)") let subtraction = 120.sub println("Su ...
} struct mult { var a = sum() var b = diff() } let calc = mult() println ("Inside mult block \(calc.a.num1, calc.a.num2)") print ...
Inside Sum Block:(100, 200) Inside Diff Block: (200, 100) Methods New instance methods and type methods can be added further to ...
Mutating Instance Methods Instance methods can also be mutated when declared as extensions. Structure and enumeration methods th ...
var no1 = 1 while multtable > 0 { no1 *= 10 --multtable } return (self / no1) % 10 } } println( 12 [ 0 ]) println( 7869 [ 1 ] ...
return .add case 1 : return .sub case 2 : return .mult case 3 : return .div default: return .anything } } } func result(numb: [I ...
When we run the above program using playground, we get the following result: 10 20 30 40 50 50 ...
Protocols provide a blueprint for Methods, properties and other requirements functionality. It is just described as a methods or ...
protocol classa { var marks: Int { get set } var result: Bool { get } func attendance() - > String func markssecured() - > ...
studdet.marks = 98 studdet.markssecured() println(studdet.marks) println(studdet.result) println(studdet.present) println(studde ...
self = wed println("Wednesday") case mon: self = thurs println("Thursday") case tue: self = fri println("Friday") case sat: self ...
protocol tcpprotocol { init(aprot: Int) } Class Implementations of Protocol Initializer Requirements Designated or convenience i ...
class subClass: mainClass, tcpprotocol { var no2: Int init(no1: Int, no2 : Int) { self.no2 = no2 super.init(no1:no1) } // Requir ...
func next() - > members? } var items = [ 10 , 20 , 30 ].generate() while let x = items.next() { println(x) } for lists in map ...
let firstname: String let lastname: String var age: Int init(firstname: String, lastname: String) { self.firstname = firstname s ...
Protocol Inheritance Swift allows protocols to inherit properties from its defined properties. It is similar to that of class in ...
«
4
5
6
7
8
9
10
11
12
13
»
Free download pdf