Questions tagged [swift-macro]

Swift macros contribute to improved code readability and expressiveness by generating code, effectively eliminating repetitive code and enhancing the app development experience.

8 questions
3
votes
1 answer

How to use Swift Macros with @Observable and @Environment?

I'm trying to use the new Swift Macros using @Observable and @Environment with the following code: import SwiftUI import Observation @Observable class Note { var text = "" } struct ContentView: View { @State var note = Note() var…
ygee
  • 2,580
  • 3
  • 17
  • 21
2
votes
0 answers

The package product 'SwiftSyntaxMacros' requires minimum platform version 10.15 for the macOS platform, but this target supports 10.13

I created a new swift macro package in my Xcode project. My Package.swift looks like: import CompilerPluginSupport import PackageDescription let package = Package( name: "TestMockable", platforms: [.iOS(.v14)], products: [ .library( …
2
votes
1 answer

Declaration name is not covered by Swift macro

I'm fiddling around with the new Swift 5.9 Macros. I have the following macro: Given the following enum @associatedValues enum Fruit { case banana(Banana) case grape(Grape) } I want @associatedValues enum Fruit { case banana(Banana) …
Nuno Gonçalves
  • 6,202
  • 7
  • 46
  • 66
1
vote
0 answers

Cannot find #unwrap macro in Xcode Version 15.0 beta (15A5160n)

Apple demonstrated in more than one session the #unwrap macro which I thought I built into Xcode 15 and the frameworks it is shipped with directly. But if I try to unwrap an URL: let url = #unwrap(URL(string: "my-awsome-url.tld")) I get the…
Tobonaut
  • 2,245
  • 2
  • 26
  • 39
0
votes
1 answer

Swift Macros: ReturnClauseSyntax

I am doing some testing and figuring out with the new Swift Macros but I came across a hurdle I can't seem to figure out, also because there isn't a lot of helpful guides on them yet. So first of all, if the appliance of the macro is a good idea at…
Mar-k
  • 648
  • 6
  • 16
0
votes
0 answers

Is there a way to get the declared funcs of SimpleTypeIdentifierSyntax (representing a Protocol) in SwiftMacro?

I'm trying to create a Swift-Macro. Intention of the Macro is: take a protocol type as input generate a class declaration which conforms to this protocol type implement protocol defined funcs I've managed to get the class with its conformance…
Steve
  • 1
  • 1
0
votes
1 answer

@Observable initial value with classes

Converting from ObservableObject to @Observable macro, an initial value is required but initializing from init fails: @Observable final class ViewModel { var foo: Foo // ❌ @Observable requires property 'foo' to have an initial value (from macro…
amq
  • 160
  • 4
  • 17
-1
votes
1 answer

Swift Macro: Missing package product 'MyFirstMacro'

In Xcode 15.0.0, I have created a package using a Swift Macro template. I named it 'MyFirstMacro'. The template includes a #stringify macro. Next, I created a new application named 'MyApp' and copied the code from the 'MyFirstMacro' main.swift…
Blazej SLEBODA
  • 8,936
  • 7
  • 53
  • 93