MVVM is a design pattern in software development that separates main application components into three interconnected categories: Model, View and ViewModel. Model represents the data, View represents the user interfaces and ViewModel represents the main link between View and Model.
When you name a new class, you want that name to be meaningful and describe why this particular class exists and what it does. This is much harder than it seems. The name of a class usually consists of two components. The first part of the name is usually related to a domain, e.g. a feature name or a screen name. That one is pretty much given. The other part of the class name is related to a type of the problem it is trying to solve and it may be much harder to come up with a meaningful name for this. I found that when you’re in a “naming paralysis”, going through the list of some common suffixes is generally enough for that bulb to light up when you come across a name that you see fit.
As I wrote in a blog post about Value vs Reference types, in Swift Enums and Structs are first class citizens. They contain properties, methods and extensions which are usually only found in Classes. Value types do not support inheritance in Swift, but they can conform to protocols which makes them convenient for use in Protocol Oriented Programming.
Swift properties associate values to a certain class, structure or enumeration. There are two kinds, stored and computed properties. Stored properties are constant or variable values that exist in an instance. Computed properties do not store a value, instead they represent a value that is calculated from other values. Another difference between the two is that stored properties cannot be contained in enumerations. Classes and structures can contain both stored and calculated properties.
There is an expression that states: “There are only two hard things in programming – cache invalidation and naming things”. More often than not, so little effort goes into naming things. We’re usually eager to start working on the “important” stuff as soon as possible so in a matter of seconds we make up a name that is going to be the first and most important point of contact for anyone looking into that particular part of the implementation. The name of a variable, function, class or any type should roughly tell you what it does, how it’s used and why it exists. That is why much more thought and effort should go into naming things.
When creating UITableViewCell or UICollectionViewCell subclasses you usually need to define a few things both in xib and in code. First when you create the layout in the interface builder, you also define the reuse identifier for that cell. Implicitly for UITableViewCell and UICollectionViewCell you define the height/size. Automatically generated xib has the same file name as the name of the class. These are all things that you have to define in two places – one is the xib itself, and the other is in code.
Loading a view from a xib requires you to instantiate a UINib object, providing a Nib name and bundle. On that UINib object you use the instantiate method, providing an owner and options. The general pattern is that the name of the Nib is the same as the name of the class, and the bundle used is the main bundle. I like to simplify this pattern to use a method called loadFromNib that has an optional parameter called name where you can provide the exact name of the nib to load the view from. If the name parameter is not provided, the name of the nib is assumed to be the same as the class name. Since that is usually the case, you don’t have to provide a name parameter, just use e.g. let myView: MyView = loadFromNib().
There are usually two common reasons when you have missing files in the project after a merge.
The first case is when the commit contains references of files only, but not the files themselves. That means a developer adds e.g. images to the project and commits the project file, but forgets to commit the actual image files. When you merge those changes, you get those familiar red file names that clearly state missing files. You need to get a hold of the actual files and add them to resolve the issue.
There is a railroad crossing near my house and my 2yr old likes to watch the gate arm go up and down to let the train/traffic cross. As much as I’d love to stay with him on that crossing all day long 🙂 I decided it would be much easier to build a smaller version of the gate arm at home for him to play with.
Swift is a programming language that strongly emphasizes value types. Structs and Enums are first class citizens in Swift. While value types do not support inheritance, they contain properties, methods and extensions, features usually related to classes.
Value types usually don’t manipulate the data they store. It is the owner of that value type that manipulates the data stored in the value. The value type itself can contain interface and convenience methods for computation and calculations using the stored data. This results in a clean and predictable control flow.