Last active
February 19, 2019 16:20
-
-
Save jamesrochabrun/a5e578bf5de4ce6f4aace462ee6eabf5 to your computer and use it in GitHub Desktop.
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 | |
//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