Skip to content

Instantly share code, notes, and snippets.

View jamesrochabrun's full-sized avatar
🇵🇪

James Rochabrun jamesrochabrun

🇵🇪
View GitHub Profile
//: Playground - noun: a place where people can play
import UIKit
//ENUMS
enum Day {
case monday
//DEFINING A PROTOCOL
import Foundation
protocol FullNameable {
var fullName: String { get }
}
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
//reference types
class someClass {
var name: String
init(name: String) {
self.name = name
}
}
var aClass = someClass(name: "James")
var bClass = aClass
//: 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.
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
//: 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
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
class Dog {
var name: String
init(name: String) {
self.name = name
}
}
class Chihuahua: Dog {
override init(name: String) {
//: 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 {