Skip to content

Instantly share code, notes, and snippets.

@jamesrochabrun
Last active February 19, 2019 16:20
Show Gist options
  • Save jamesrochabrun/a5e578bf5de4ce6f4aace462ee6eabf5 to your computer and use it in GitHub Desktop.
Save jamesrochabrun/a5e578bf5de4ce6f4aace462ee6eabf5 to your computer and use it in GitHub Desktop.
//: Playground - noun: a place where people can play
import UIKit
//Diffeerence between structs and classes
struct User {
var name: String
var email: String
}
var user = User(name: "marc", email: "j@j.com")
var otherUser = user
user.email
otherUser.email
otherUser.email = "ama@gmali.com"
user.email
//nothing changes in structs, this is a value type and its just a copy
///////
//classes is a reference type
class Person {
var name: String
var email: String
init(name:String, email:String) {
self.name = name
self.email = email
}
}
var somePerson = Person(name: "stece", email: "setev@gmail.com")
var otherPerson = somePerson
somePerson.email
otherUser.email
otherPerson.email = "otheremailchanged@gmail.com"
somePerson.email
//here it does change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment