Write Swift macros

RSS for tag

Discuss the WWDC23 Session Write Swift macros

Posts under wwdc2023-10166 tag

3 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

OSLog in Swift macro doesn't persist original file/line number
I need to log to OSLog and into a file in parallel (due to OSLogStore not being able to provide old logs (FB13191608)). In Objective-C I can accomplish this with a macro using __FILE__ and __LINE__ in the macro implementation which still reference the position in the original code. I tried to create a Swift macro to make this work from Swift. However, log() takes the file and line number of the macro definition file instead of the position in the calling code. So when I click on the metadata link, I'm taken to the macro instead of the calling location. Is there any solution to that? #file and #line are correctly set in the macro but there’s no way to specify file and line number to the log() function (FB13204310).
5
0
1.2k
Oct ’23
External macro implementation type could not be found for macro 'stringify'
Hi. I created a new swift macro package and wan't to start using the template which contains the #stringify macro out of the box without any changes. The package itself runs incl. tests But now I added the Package to a dummy iOS app project / workspace and I can't compile if im using this code let (_, _) = #stringify(a + b) + package import Compile error: External macro implementation type '***.StringifyMacro' could not be found for macro 'stringify' I am using Xcode 15 and macOS 13.5.2 Restart Xcode, Clean etc doesn't help. Can anyone help my ? Thanks :)
4
1
2.9k
Jun ’24
Swift Macro: Missing package product 'MyMacroApple'
In Xcode 15.0.0 I have created a package using a template Swift Macro. I have named it 'MyMacroApple'. The template comes with #stringify macro so I have created an new app and named it 'MyMacroApp' then copy pasted the code from 'MyMacroApple' main.swift file import MyMacroApple let a = 17 let b = 25 let (result, code) = #stringify(a + b) then I have added Local package dependency to the app project and selected package product 'MyMacroApple' of Library kind to my 'pocMyApp' target. When I run the project I get the error: "No such module 'MyMacroApple'"
6
0
3.5k
Dec ’23