Programare swift Swift tutorial from tutorials point | Page 11

Swift 4 30. SWIFT 4 – OPTIONAL CHAINING ...................................................................................... 158 Optional Chaining as an Alternative to Forced Unwrapping ................................................................ 158 Defining Model Classes for Optional Chaining & Accessing Properties ................................................ 160 Calling Methods Through Optional Chaining ....................................................................................... 162 Accessing Subscripts through Optional Chaining ................................................................................. 163 Accessing Subscripts of Optional Type ................................................................................................ 167 Linking Multiple Levels of Chaining ..................................................................................................... 169 Chaining on Methods with Optional Return Values ............................................................................. 173 31. SWIFT 4 – TYPE CASTING ................................................................................................. 175 Defining a Class Hierarchy ................................................................................................................... 175 Type Checking ..................................................................................................................................... 176 Downcasting ....................................................................................................................................... 178 Typecasting:Any and Any Object ......................................................................................................... 180 AnyObject ........................................................................................................................................... 182 32. SWIFT 4 – EXTENSIONS .................................................................................................... 185 Computed Properties .......................................................................................................................... 185 Initializers ........................................................................................................................................... 186 Methods .............................................................................................................................................. 188 Mutating Instance Methods ................................................................................................................ 188 Subscripts ............................................................................................................................................ 189 Nested Types ....................................................................................................................................... 190 33. SWIFT 4 – PROTOCOLS .................................................................................................... 192 Property and Method Requirements ................................................................................................... 192 Mutating Method Requirements ......................................................................................................... 194 Initializer Requirements ...................................................................................................................... 195 x