The Future of iOS Development
Nico van der Linden

The Future of iOS Development

Last week it was WWDC time (Apple's annual Worldwide Developers Conference) a lot of great stuff was announced but what I loved most was the introduction of #swiftui.

It is unbelievable how easy #swiftui makes it to build an iOS user interface with its new declarative syntax. With this syntax you can simply state what your user interface should do. So you can for example simply mention that your list should contain an image and text placed next to each other (HStack) and how each object should look like (e.g. show the image as a circle (clipShape) with a white stroke overlay and a shadow). 

struct FruitRow: View {
    var name: String
    var info: String
    var image: String
    
    var body: some View {
        HStack {
            Image(image)
                .resizable()
                .frame(width: 50, height: 50)
                .clipShape(Circle())
                .overlay(Circle().stroke(Color.white, lineWidth: 2))
                .shadow(radius: 5)
            VStack(alignment: .leading){
                Text(name).font(.largeTitle)
                Text(info).font(.footnote).lineLimit(nil)
            }
        }
    }
}

This declarative syntax is not only easier to read/write but it also extremely reduces the lines of code necessary to achieve your goal. When building -for example- Lists, you no longer have to create prototype cells in storyboards or register them in code, no more manually creating IBOutlets/IBActions, dequeuing and configuring tableview cells or telling how many rows to use. 

List {

      FruitRow(name: "Apple", info: "Apple trees are large if grown from seed", image: "apples")
                
      FruitRow(name: "Banana", info: "The largest herbaceous flowering plant", image: "bananas")
      
      FruitRow(name: "Strawberry", info: "The garden strawberry was first bred in Brittany", image: "strawberries")

}
 
  

You simply create a list in which you provide a layout created in the Struct before (FruitRow) which will then be shown as a table list.

Also the new State options on controls are lovely, #swiftui will automatically watch for changes and then updates any parts of your views which use that state. 

@State var showApple = true
 
  
Toggle(isOn: $showApple) {

   Text("Show Apple")

}
 
  

You simply define a variable as "@State" and then iOS will keep track of this value on all components to which you attach this value ($showApple). This is called "binding" - asking swiftUI to synchronise the changes between a UI control and an underlying property.

I only looked at the surface of what #swiftui has to offer and it will take some time before we can fully rewrite our apps using swiftUI but I already love the direction Apple is taking for the future of iOS development.

Swift is evolving , which is always great

These bindings make sense. I remember being mostly confused when bindings were added to Cocoa/ObjC. And StackViews made SO much sense when they were added, I should have seen that they were just the groundwork for something bigger.

To view or add a comment, sign in

Others also viewed

Explore content categories