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

Comments

Projects
None yet
2 participants
@niklasberglund

niklasberglund commented Jul 26, 2017

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

This comment has been minimized.

Collaborator

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

This comment has been minimized.

Collaborator

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 from No apply method in Objective-C to Protocol extension methods not available from Objective-C Jul 26, 2017

@niklasberglund

This comment has been minimized.

niklasberglund commented Jul 27, 2017

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