Skip to content

Conversation

@simonomi
Copy link
Contributor

@simonomi simonomi commented Dec 28, 2025

the macro generates the game variable and eventHandler function, using the declaration it's attached to as the PlaydateGame. the name @PlaydateMain calls back to@main as it fills the same role.

providing a macro does add a dependency on Swift Syntax, but as of Swift 6.2, SwiftPM distributes Swift Syntax pre-built, so it shouldn't impact compile times too much.

finally, i have a question about PlaydateGame. in the examples, the Game type is always defined as a class, but i'm not sure i see any reason it needs to be? given that the protocol doesn't inherit from AnyObject, the macro supports being used on structs, classes, and even enums. since Swift generally recommends using structs over classes unless necessary, can we switch the examples to use a struct instead?

P.S. see also finnvoor/PlaydateKitTemplate#5

@finnvoor
Copy link
Owner

finnvoor commented Jan 7, 2026

apologies for the delay, this looks great. I think the main reason I used classes instead of structs was just because it seemed likely to store game state in the Game class, and a struct would require marking a bunch of methods as mutating. I think it's nice to give people the option to use a struct though. We could put the macro in a separate target if anyone complains about compile time, but yeah I think it's probably not going to make much of a difference. Mind updating the examples to use this macro?

thanks!

@simonomi
Copy link
Contributor Author

simonomi commented Jan 8, 2026

alright! the examples have been updated and i went back and added some documentation to the macro. while i personally would prefer a struct with mutating methods over a class, i think you're right that a final class is the correct default!

@finnvoor finnvoor merged commit 068030c into finnvoor:main Jan 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants