Swift Immutable Model
Few rules to make code CLEAN:
1. Declare constant properties var
2. Put only fields deceleration and constructors to model declaration
3. Put model logic to Extensions
Code Example.
class Person {
let firstname: String
let lastname: String
let age: Int
init(firstname: String, lastname: String, age: Int) {
self.firstname = firstname
self.lastname = lastname
self.age = age
}
}
Move all login into extensions
extension Person {
func age(age: Int) -> Person {
return Person(firstname: firstname, lastname: lastname, age: age)
}
}
Written by Kostiantyn
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mode
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#