├── .gitignore ├── LICENSE ├── Package.resolved ├── Package.swift ├── README.md ├── Sources ├── Prototype │ ├── Field.swift │ ├── Format.swift │ ├── Prototype.swift │ └── Section.swift ├── PrototypeAPI │ ├── FieldAttribute.swift │ ├── PrototypeKind.swift │ └── PrototypeStyle.swift ├── PrototypeClient │ └── main.swift ├── PrototypeMacros │ ├── FieldAttributeParser.swift │ ├── FieldMacro.swift │ ├── FieldMacroArguments.swift │ ├── FormatMacro.swift │ ├── FormatMacroArguments.swift │ ├── PrototypeKindParser.swift │ ├── PrototypeMacro.swift │ ├── PrototypeMacroArguments.swift │ ├── PrototypeMacrosError.swift │ ├── PrototypeMemberSpec.swift │ ├── PrototypePlugin.swift │ ├── PrototypeSpec.swift │ ├── PrototypeTypeSpec.swift │ └── SectionMacro.swift ├── PrototypeUI │ ├── MeasurementForm.swift │ └── MeasurementView.swift └── SwiftSyntaxExtensions │ ├── AccessLevelModifiers.swift │ ├── AttributeHasArgument.swift │ └── DeclarationHasAttribute.swift └── Tests └── PrototypeTests └── PrototypeTests.swift /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | xcuserdata/ 5 | DerivedData/ 6 | .swiftpm/configuration/registries.json 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | .swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist 9 | .netrc 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2023 Murat Yilmaz 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "pins" : [ 3 | { 4 | "identity" : "swift-syntax", 5 | "kind" : "remoteSourceControl", 6 | "location" : "https://github.com/apple/swift-syntax.git", 7 | "state" : { 8 | "revision" : "0687f71944021d616d34d922343dcef086855920", 9 | "version" : "600.0.1" 10 | } 11 | } 12 | ], 13 | "version" : 2 14 | } 15 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.9 2 | 3 | import PackageDescription 4 | import CompilerPluginSupport 5 | 6 | let package = Package( 7 | name: "Prototype", 8 | platforms: [.macOS(.v14), .iOS(.v16), .tvOS(.v16), .watchOS(.v6), .macCatalyst(.v16)], 9 | products: [ 10 | .library(name: "Prototype", targets: ["Prototype", "PrototypeAPI"]), 11 | .library(name: "PrototypeUI", targets: ["PrototypeUI"]) 12 | ], 13 | dependencies: [ 14 | .package( 15 | url: "https://github.com/apple/swift-syntax.git", 16 | from: "600.0.0" 17 | ), 18 | ], 19 | targets: [ 20 | .macro( 21 | name: "PrototypeMacros", 22 | dependencies: [ 23 | .target(name: "PrototypeAPI"), 24 | .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), 25 | .product(name: "SwiftCompilerPlugin", package: "swift-syntax"), 26 | .target(name: "SwiftSyntaxExtensions") 27 | ] 28 | ), 29 | .target( 30 | name: "Prototype", 31 | dependencies: [ 32 | .target(name: "PrototypeMacros"), 33 | .target(name: "PrototypeAPI"), 34 | ] 35 | ), 36 | .target( 37 | name: "PrototypeAPI" 38 | ), 39 | .executableTarget( 40 | name: "PrototypeClient", 41 | dependencies: [ 42 | .target(name: "Prototype"), 43 | .target(name: "PrototypeUI") 44 | ] 45 | ), 46 | .target( 47 | name: "PrototypeUI" 48 | ), 49 | .target( 50 | name: "SwiftSyntaxExtensions", 51 | dependencies: [ 52 | .product(name: "SwiftSyntax", package: "swift-syntax"), 53 | ] 54 | ), 55 | .testTarget( 56 | name: "PrototypeTests", 57 | dependencies: [ 58 | .target(name: "PrototypeAPI"), 59 | .target(name: "PrototypeMacros"), 60 | .target(name: "SwiftSyntaxExtensions"), 61 | .product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax"), 62 | ] 63 | ), 64 | ] 65 | ) 66 | 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Prototype (WIP) 2 | 3 | Prototype is a **work-in-progress** project that generates SwiftUI Forms and Views for data structures and classes. It's designed to complement SwiftData Models seamlessly. 4 | 5 | ## Overview 6 | 7 | SwiftUI has transformed UI development in Swift, but rapid prototyping by creating views for data models still involves some boilerplate work to be coded. Prototype aims to eliminate this boilerplate by providing a convenient macro to auto-generate SwiftUI code for your data. 8 | 9 | ## Key Features 10 | 11 | - **Rapid prototyping**: Prototype offers a simple macro for effortlessly generating SwiftUI views from your data structures and classes. 12 | 13 | - **SwiftData Models Integration**: Prototype works seamlessly with SwiftData Models, making it easy to create SwiftUI representations for your data. 14 | 15 | - **Customization**: While Prototype streamlines the process, you can still customize the generated SwiftUI code to match your design needs. 16 | 17 | ## Example 18 | 19 | Here's a quick example of Prototype in action: 20 | 21 | Source: 22 | ```swift 23 | @Prototype(style: .labeled, kinds: .form, .view) 24 | struct Author { 25 | let name: String 26 | } 27 | ``` 28 | Macro Expansion: 29 | ```swift 30 | struct AuthorView: View { 31 | public let model: Author 32 | 33 | public init(model: Author) { 34 | self.model = model 35 | } 36 | 37 | public var body: some View { 38 | LabeledContent("AuthorView.name.label") { 39 | LabeledContent("AuthorView.name", value: model.name) 40 | } 41 | } 42 | } 43 | 44 | struct AuthorForm: View { 45 | @Binding public var model: Author 46 | private let footer: AnyView? 47 | private let numberFormatter: NumberFormatter 48 | 49 | public init(model: Binding, numberFormatter: NumberFormatter = .init()) { 50 | self._model = model 51 | self.footer = nil 52 | self.numberFormatter = numberFormatter 53 | } 54 | 55 | public init