bigmountainstudio / VOODOFileTemplate2

A simple SwiftUI architecture template for Xcode.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

VOODO File Template

An Xcode file template that will create your view, observable object, and data object all in one file with sample data.

You can then edit, delete or separate out parts if you want.

⚠️ Note: This template uses @Observable (iOS 17+).

👉For the ObservableObject template, go here.

How to Install

Add the VOODO.xctemplate to this directory: ~/Library/Developer/Xcode/Templates/File Templates/Custom/

(Click your home directory and then show hidden folders with COMMAND+SHIFT+. )

Note: That full directory might not even exist so you will have to create it.

In Xcode

  1. Start Xcode and add a new file.
  2. Scroll down until you see the Custom section and select VOODO: new file dialog

Example Output

// View
import SwiftUI

struct PersonView: View {
    @State private var oo = PersonOO()
    
    var body: some View {
        List(oo.data) { datum in
            Text(datum.name)
        }
        .onAppear {
            oo.fetch()
        }
    }
}

#Preview {
    PersonView()
}

// Observable Object
import Observation
import SwiftUI

@Observable
class PersonOO {
    var data: [PersonDO] = []
    
    func fetch() {
        data = [PersonDO(name: "Datum 1"),
                PersonDO(name: "Datum 2"),
                PersonDO(name: "Datum 3")]
    }
}

// Data Object
import Foundation

struct PersonDO: Identifiable {
    let id = UUID()
    var name: String
}

Preview

preview

You Are In Control

From here, you can:

  • Delete what you don't need
  • Keep all the parts in one file
  • Break out the parts into separate files
  • Change the template to use any naming convention you want

Resources

For more information on this architecture and how to work with data in SwiftUI, take a look at this book: SwiftUI Essentials: Architecting Scalable & Maintainable Apps.

swiftui essentials

Learn More

About

A simple SwiftUI architecture template for Xcode.