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

Protocol extension methods not available from Objective-C #5

Closed
niklasberglund opened this issue Jul 26, 2017 · 3 comments
Closed

Protocol extension methods not available from Objective-C #5

niklasberglund opened this issue Jul 26, 2017 · 3 comments
Assignees

Comments

@niklasberglund
Copy link

Had a go at trying ThemeKit out in an Objective-C project. Using it with Objective-C doesn't seem very trivial. I tried importing <macOSThemeKit/macOSThemeKit-Swift.h>, grabbing an instance of dark theme with:
TKDarkTheme *darkTheme = [TKThemeManager darkTheme]

Then I should invoke the apply method on the darkTheme object right? But TKDarkTheme don't have any apply method.

Did I misunderstand how to apply a theme?

@nfgrilo nfgrilo self-assigned this Jul 26, 2017
@nfgrilo
Copy link
Contributor

nfgrilo commented Jul 26, 2017

Hi @niklasberglund!

Thank you for your feedback! No, you didn't misunderstand. The thing is, the Theme class extension that provides some convenience methods (like this) is not available from Objective-C (swift protocol is defined with @objc, but by definition, functions and properties defined on protocol extensions are not available when accessing from Objective-C).

As a workaround, and because this protocol extension is very simple, you can do what that method does on the extension, which is, setting the .theme property on TKThemeManager:

@import macOSThemeKit;

@implementation AppDelegate

- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
    TKDarkTheme *darkTheme = [TKThemeManager darkTheme];
    [[TKThemeManager sharedManager] setTheme:darkTheme];
}

@end

I'm sorry for the trouble - I need to update the docs about this. I will later dig into this to check if I can come with a better alternate implementation.
Thank you for pointing this out.

@nfgrilo
Copy link
Contributor

nfgrilo commented Jul 26, 2017

@niklasberglund just a quick follow-up:

The README.md and documentation has been updated to include Objective-C examples for the simpler and advanced usage sections.

Thanks and sorry for the inconvenience.

@nfgrilo nfgrilo changed the title No apply method in Objective-C Protocol extension methods not available from Objective-C Jul 26, 2017
@niklasberglund
Copy link
Author

Perfect! Thank you. Look forward to trying it out more.

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

No branches or pull requests

2 participants