Intermediate Swift 3 - Part 5: Classes | Ray Wenderlich

In this Intermediate Swift 3 video tutorial you'll learn about classes and the differences between reference types and value types.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/3536-intermediate-swift-3/lessons/5

Hey, the solution is in the challenge file, thanx for the quick conversion to swift3/Xcode8 though.

Hello Brian,

Should all classes and or structs that you create be in their own separate file?
I can see were subclasses of your class could and probably should be in the same
file as your class.

Thanks,

Gary

Itโ€™s really up to you, your team, or your style guide. A good rule of thumb is to group classes together that are all interrelated and have dependencies on each other. Otherwise, keep them apart. I hope that helps!

Thatโ€™s good to know, Brian. I guess I had some pre-conceived idea that each
class needed to be in its own separate file.

Thanks,

Gary

Can I use struct but I still want to use the reference? Like what we did in C/C++?

let a = &b // something like that to tell swift I want to use a reference

Can I use class but I donโ€™t want to use the reference?

let x = copy(y) // something like that to tell swift a explicit copy should be made