Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write new errorString() swift macro #1346

Open
tmolitor-stud-tu opened this issue Dec 23, 2024 · 0 comments
Open

Write new errorString() swift macro #1346

tmolitor-stud-tu opened this issue Dec 23, 2024 · 0 comments
Labels
🦸 Help wanted If you are motivated, this is a good start!

Comments

@tmolitor-stud-tu
Copy link
Member

Write a ObjcC macro and a Swift macro doing extracting the localized error message from an NSError object and taking an optional fallback string that automatically gets wrapped in NSLocalizedString().

The ObjC macro would be this:

#include "metamacros.h"
#define errorString(error, ...) metamacro_if_eq(0, metamacro_argcount(__VA_ARGS__))( emptyDefault(((NSError*)error).userInfo[NSLocalizedDescriptionKey], @"", NSLocalizedString(@"Unknown error!", @"")) )( emptyDefault(((NSError*)error).userInfo[NSLocalizedDescriptionKey], @"", NSLocalizedString(metamacro_head(__VA_ARGS__), @"")) )

Swift macro resources, that should be helpful:
https://www.avanderlee.com/swift/macros/

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/macros/

https://github.com/krzysztofzablocki/Swift-Macros?tab=readme-ov-file

This can be a follow up PR, but don't forget that (we'll need that NSError to string conversion a lot when we use promises)

See #1338 (comment)

@tmolitor-stud-tu tmolitor-stud-tu added the 🦸 Help wanted If you are motivated, this is a good start! label Dec 23, 2024
@matthewrfennell matthewrfennell moved this to In Progress in Monal Team Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦸 Help wanted If you are motivated, this is a good start!
Projects
Status: In Progress
Development

No branches or pull requests

1 participant