Skip to content

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.

Notifications You must be signed in to change notification settings

bigmountainstudio/VOODOFileTemplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

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 ObservableObject.

👉For the @Observable 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: image

Example Output

// View
import SwiftUI

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

struct Person_Previews: PreviewProvider {
    static var previews: some View {
        PersonView()
    }
}

// Observable Object
import SwiftUI

class PersonOO: ObservableObject {
    @Published 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: Working with Data in SwiftUI.

working with data in swiftui

Learn More

About

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.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published