trifork / TriforkSwiftExtensions

Generic Trifork Swift Extensions
MIT License
8 stars 6 forks source link

Extensions for showing /hiding view, and whenever a collection is not empty. #47

Closed ktvtrifork closed 3 years ago

ktvtrifork commented 5 years ago

the hide and show helps code that contains

let someView = UIView()
//some lines later
if something {
    //do some more stuff
    someView.isHidden = false 
} else {
   //do some more other stuff
  someView.isHidden = true

where the natural thinking is that you either hide or show a view, which is the inverse of the "isHidden" property; and leads sometimes to bugs regarding the mixing of showing (a positive action) vs setting the isHidden to false (a negative action) so to simplify it without and potential confusion you are to express the intention via a name , rather than an assignment.

The "isNotEmpty" for a colleciton is to make code such as

let someCollection: [String] = ....
if !someCollection.isEmpty { 
     //do stuff
}

more readable and easier to understand, as more complex expressions can easily "hide" the exclamation mark, and or might become complex because of the inversion going on in such expressions, eg:

if (!someCollection.isEmpty || someotherBool)  {

}

The "Not" part makes that very apparent and also potentially simplifies boolean expressions as well.

ghost commented 5 years ago

@ktvtrifork update docs and merge :)

trifork-bot commented 4 years ago
1 Warning
:warning: Big PR

Generated by :no_entry_sign: Danger

ghost commented 3 years ago

This is not the "Swift way" of doing things, eventhough it might be a nicer way to do things. We decided that we won't go down this path to keep the coding style more Apple-like.

Closing PR đŸ§¹