An extension for Xcode to generate builders from structs

Overview

Swift Struct Builder Generator Xcode Source Editor Extension

An Xcode extension (plugin) to generate struct builders automatically.

Install Swift Struct Builder Generator Xcode Source Editor Extension

  • Close Xcode if it is open
  • Download the latest release here
  • Copy the app to the Applications folder.
  • Open the app
  • Select OK for '"Swift Struct Builder Generator for Xcode" wants access to control "Xcode"'
  • Go to System Preferences -> Extensions -> Xcode Source Editor and make sure Builder Generator is enabled.
  • Open Xcode

How to create a new Swift builder

  • Open a file which contains one more structs you wish to generate a builder for.

Example:

class Foo {
    var name: String?
}
  • Click Editor -> SourceEditorExtension -> Generate Builder.

Recommended: assign a shortcut

  • Select preferences ⌘, in Xcode.
  • Choose 'Key Bindings'.
  • Search for 'Generate Builder'.
  • Choose your preferred shortcut.

Usage example

Open a struct called Foo that we wish to generator a builder for:

struct Foo: Equatable {
    var isActive: Bool
    var city: String?
    var countryIsoCode: String? = Locale.current.regionCode
    let aboutMe: String?
    let quote: String?
}

Generate the builder:

struct FooBuilder {
	var isActive: Bool = false
	var city: String?
	var countryIsoCode: String?
	var aboutMe: String?
	var quote: String?
	func build() -> Foo {
		return Foo(
			isActive: isActive,
			city: city,
			countryIsoCode: countryIsoCode,
			aboutMe: aboutMe,
			quote: quote
		)
	}
}

Extract the generated builder into its own file if you like, or leave it close the original file. Then use the builder like:

var foo: Foo = FooBuilder(isActive: true).build()

Disable or remove the plugin

To disable:

Go to System Preferences -> Extensions and deselect the extension under Xcode Source Editor.

To remove:

Delete the app.

Extension doesn’t appear in my editor or in System Extensions

When multiple copies of Xcode are on the same machine, extensions can stop working completely. In this case, Apple Developer Relations suggests re-registering your main copy of Xcode with Launch Services"

$ cd /System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support

$ ./lsregister -f /Applications/Your-Xcode.app
You might also like...
YMExtension - Swift extension

YMExtension Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation YMExte

Unboxing - An extension for KeyedDecodingContainer class to decode a collection of heterogeneous types.

Unboxing An extension for KeyedDecodingContainer class to decode a collection of heterogeneous types. Usage Start by creating an enum that has variant

SwiftExtensionKit - SwiftExtensionKit is to contain generic extension helpers for UIKit and Foundation

RichAppz PureSwiftExtensionKit SwiftExtensionKit is to contain generic extension

UIViewController extension to present view / view controller as bottom-half modal.
UIViewController extension to present view / view controller as bottom-half modal.

UIViewController extension to present view / view controller as bottom-half modal. Installation CocoaPods pod 'SemiModalViewController' Swift Package

A lightweight extension to Swift's CollectionDifference, supporting moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

DifferenceTracker is a lightweight extension to Swift's CollectionDifference. It defines moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

iOS ReplayKit Screen Share Broadcast Extension Frame Sharing

An iOS app that demonstrates how we can share CMSampleBuffer frames from SampleHandler of Broadcast Extension to the host app and how to pass callbacks to and fro from host app to SampleHandler and vice versa.

A CMIO Camera Extension of the creative camera type, with configuration app

ArtFilm A CMIO Camera Extension of the creative camera type, with configuration app ArtFilm is the sample code for the blog post Getting To Grips With

🏈 Cache CocoaPods for faster rebuild and indexing Xcode project.
🏈 Cache CocoaPods for faster rebuild and indexing Xcode project.

🏈 Cache CocoaPods for faster rebuild and indexing Xcode project.

Replace your Xcode icon with colorful variants
Replace your Xcode icon with colorful variants

XcoatOfPaint Have you ever wished the Xcode icon could get a fresh coat of paint to match the colorful Mac you just bought? Or you want to distinguish

Releases(v1.0.0)
Owner
Marius Wichtner
Marius Wichtner
A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

David Roman 3 Oct 14, 2022
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Fabrizio Brancati 992 Dec 2, 2022
Generate Markdown documentation from source code

SourceDocs SourceDocs is a command line tool that generates markdown documentation files from inline source code comments. Similar to Sphinx or Jazzy,

Eneko Alonso 349 Dec 10, 2022
Generate a privacy policy for your iOS app

PrivacyFlash Pro To easily run PrivacyFlash Pro get the latest packaged release. Learn more about PrivacyFlash Pro in our research paper. PrivacyFlash

privacy-tech-lab 141 Dec 22, 2022
A utility to generate PreviewDevice presets from the available devices

SwiftUIGen A utility to generate PreviewDevice presets from the available devices Installation Manual Go to the GitHub page for the latest release Dow

Timberlane Labs 29 Nov 14, 2022
An eject button for Interface Builder to generate swift code

Eject Eject is a utility to transition from Interface Builder to programatic view layout. This is done by using code generation to create a .swift fil

Rightpoint 524 Dec 29, 2022
Minecraft-silicon - Generate Apple Silicon-native versions of Minecraft

Minecraft Silicon A dead simple utility to generate Apple Silicon-native Minecra

Cole Feuer 4 Jun 21, 2022
Swift Xid - Xid uses MongoDB Object ID algorighm1 to generate globally unique ids with base32 serialzation to produce shorter strings

Swift Xid - Xid uses MongoDB Object ID algorighm1 to generate globally unique ids with base32 serialzation to produce shorter strings

Uditha Atukorala 0 Jun 13, 2022
Generate and Preview Passbook Passes

Note: This project is no longer being maintained. Passbook is an iOS 6 feature that manages boarding passes, movie tickets, retail coupons, & loyalty

Nomad CLI 324 Dec 21, 2022
An iOS app/Safari extension to automagically redirect AMP links to their normal counterpart. Comes with a trusty dog.

Amplosion ⚡️ Amplosion is an iOS 15 and greater app that automagically redirects AMP links to their normal counterpart. AMP links can be super annoyin

Christian Selig 46 Dec 11, 2022