wnagrodzki / iOSProgrammingGuidelines

2 stars 0 forks source link

Featureʼs code is separated #10

Open wnagrodzki opened 6 years ago

wnagrodzki commented 6 years ago

All the methods related to one functionality are placed in class extension.

class ExampleClass {
    init() {
        registerForUIContentSizeCategoryDidChangeNotification()
    }

    deinit {
        unregisterFromUIContentSizeCategoryDidChangeNotification()
    }
}

private extension ExampleClass {
    func registerForUIContentSizeCategoryDidChangeNotification() {...}
    func unregisterFromUIContentSizeCategoryDidChangeNotification() {...}
    @objc func contentSizeCategoryDidChangeNotification(notification: NSNotification) {...}
}
pwetrifork commented 6 years ago

Note that this is sometimes difficult to implement, e.g. when stored properties or protocols specifying init methods are involved. Common sense needs to be applied as well, we probably don’t want to split 20-line types.