Post

Replies

Boosts

Views

Activity

Do #freestanding macros generate code before @attached?
I wrote an @attached macro for generating an init. However, I also use this same class for previews. I get an error that it's impossible to create an instance of the class because the init that was supposed to be generated by the macro is missing. It seems that the #freestanding macro executes first, and at that moment, the code generated by @attached is not yet present. Is there a way to fix this?
0
0
638
Sep ’23
Which of the options in BuildSettings allows you to close the import scope?
I am preparing my own library that will allow me to work with UIKit in the SwiftUI style. And I'll be using my UIViewRepresentable subclass to display the preview while writing the UIKit code. Due to the fact that the names of my classes are the same as the names from SwiftUI (for example, the Text component is named exactly the same), I have name conflicts. On my working, configured project, everything works great. I just close the import scope like this: #if DEBUG import SwiftUI struct MyViewController_Previews: PreviewProvider { static var previews: some View { UIViewControllerPreview { MyViewController() } } } #endif But this same way doesn't work in my own project which I just created from scratch in Xcode. I just see classes from SwiftUI throughout the file. I guess that in the project from my work some flag is set in the Build Settings, which allows the compiler to understand scopes #if DEBUG Could you suggest which flag can I achieve this result? This screenshot from my own project. Here i can use SwiftUI class everywhere in file. But this is my work project. Here i can't use SwiftUI classes everywhere. Here is import SwiftUI limited to scope of #if DEBUG
0
0
782
Jan ’23
What exactly should I import so as not to import whole SwiftUI to use XCode Canvas?
I need to use canvas to display PreviewProvider. But I do not need classes like Text Button, VStack and others to be visible in my entire file. What exactly i need to import to use Canvas? I look for something like import protocol SwiftUI.CanvasPresentable and this protocol makes XCode to use Canvas without import whole SwiftUI
2
0
787
Dec ’22
Strikethrough Text on Incorrect Date Selection in DatePicker
How can I achieve the same text behavior in DatePicker as in the system Calendar application? There the text becomes crossed out when you select the wrong date. How can I do the same?
Replies
0
Boosts
0
Views
482
Activity
Oct ’23
Do #freestanding macros generate code before @attached?
I wrote an @attached macro for generating an init. However, I also use this same class for previews. I get an error that it's impossible to create an instance of the class because the init that was supposed to be generated by the macro is missing. It seems that the #freestanding macro executes first, and at that moment, the code generated by @attached is not yet present. Is there a way to fix this?
Replies
0
Boosts
0
Views
638
Activity
Sep ’23
Which of the options in BuildSettings allows you to close the import scope?
I am preparing my own library that will allow me to work with UIKit in the SwiftUI style. And I'll be using my UIViewRepresentable subclass to display the preview while writing the UIKit code. Due to the fact that the names of my classes are the same as the names from SwiftUI (for example, the Text component is named exactly the same), I have name conflicts. On my working, configured project, everything works great. I just close the import scope like this: #if DEBUG import SwiftUI struct MyViewController_Previews: PreviewProvider { static var previews: some View { UIViewControllerPreview { MyViewController() } } } #endif But this same way doesn't work in my own project which I just created from scratch in Xcode. I just see classes from SwiftUI throughout the file. I guess that in the project from my work some flag is set in the Build Settings, which allows the compiler to understand scopes #if DEBUG Could you suggest which flag can I achieve this result? This screenshot from my own project. Here i can use SwiftUI class everywhere in file. But this is my work project. Here i can't use SwiftUI classes everywhere. Here is import SwiftUI limited to scope of #if DEBUG
Replies
0
Boosts
0
Views
782
Activity
Jan ’23
What exactly should I import so as not to import whole SwiftUI to use XCode Canvas?
I need to use canvas to display PreviewProvider. But I do not need classes like Text Button, VStack and others to be visible in my entire file. What exactly i need to import to use Canvas? I look for something like import protocol SwiftUI.CanvasPresentable and this protocol makes XCode to use Canvas without import whole SwiftUI
Replies
2
Boosts
0
Views
787
Activity
Dec ’22