This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
//ENUMS | |
enum Day { | |
case monday |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//DEFINING A PROTOCOL | |
import Foundation | |
protocol FullNameable { | |
var fullName: String { get } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
//computed properties | |
//A computed property does not actually store a value, but computes it based on the values of other stored properties in our class. | |
//they can not stored values | |
//A computed property that does not specify a getter or setter is by default a read only computed property |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//reference types | |
class someClass { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
var aClass = someClass(name: "James") | |
var bClass = aClass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
//initialization | |
//value types get defautlt initializers , structs and enums | |
//1- failable and throwing initializers | |
//What happens if we can't initialize an object? This is a common occurrence if initialization depends on external data. Swift gives us two ways to deal with this - failable and throwing initializers. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//initializer delegation definition: When one initializer calls another this process is known as initialize | |
//Initializer delegation - VALUE TYPES | |
//note value types have a memberwise initializer so they dont need the init method | |
struct Point { | |
var x:Int = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
//Value types in Swift includes structs, enums, arrays and other native types | |
//Value semantics | |
struct Point { | |
var x: Double |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
//helper struct | |
struct Point { | |
var x: Double | |
var y: Double | |
} | |
//type methods - valueType section | |
//you cant override in value types because they don't have inheritance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Dog { | |
var name: String | |
init(name: String) { | |
self.name = name | |
} | |
} | |
class Chihuahua: Dog { | |
override init(name: String) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
//Extensions | |
//in Swift we can use extensions to add functionality to an existing class, structure, enumeration or even a protocol type. | |
//TYPE EXTENSIONS | |
extension Int { |