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

fix: use of @optional directive in protocols and interfaces #47

Merged
merged 3 commits into from
Apr 15, 2024

Conversation

t0rr3sp3dr0
Copy link
Contributor

The @optional directive of Objective-C defines that all property and method definitions bellow it are optional. This only changes if a @required directive is placed bellow it. go-macho doesn't implement this properly and mistakenly declares required methods as optional.

Additionally, @required and @optional should only ever be used inside @protocol blocks. But go-macho also uses them in @interface blocks.

This patch fixes both issues.

As I have tweaked the formatting of generated code slightly, I also changed the formatting of categories to keep consistency.

Before:

@protocol UIActivityItemsConfigurationReading <NSObject>

@property (readonly, copy, nonatomic) NSArray *itemProvidersForActivityItemsConfiguration;
@optional
@property (readonly, copy, nonatomic) NSArray *applicationActivitiesForActivityItemsConfiguration;

/* instance methods */
- (id)itemProvidersForActivityItemsConfiguration;
@optional
/* instance methods */
- (id)activityItemsConfigurationMetadataForItemAtIndex:(long long)index key:(id)key;
- (id)activityItemsConfigurationMetadataForKey:(id)key;
- (id)activityItemsConfigurationPreviewForItemAtIndex:(long long)index intent:(id)intent suggestedSize:(struct CGSize { double x0; double x1; })size;
- (id)applicationActivitiesForActivityItemsConfiguration;
- (char)activityItemsConfigurationSupportsInteraction:(id)interaction;
@end

After:

@protocol UIActivityItemsConfigurationReading <NSObject>

@required

@property (readonly, copy, nonatomic) NSArray *itemProvidersForActivityItemsConfiguration;

/* required instance methods */
- (id)itemProvidersForActivityItemsConfiguration;

@optional

@property (readonly, copy, nonatomic) NSArray *applicationActivitiesForActivityItemsConfiguration;

/* optional instance methods */
- (id)activityItemsConfigurationMetadataForItemAtIndex:(long long)index key:(id)key;
- (id)activityItemsConfigurationMetadataForKey:(id)key;
- (id)activityItemsConfigurationPreviewForItemAtIndex:(long long)index intent:(id)intent suggestedSize:(struct CGSize { double x0; double x1; })size;
- (id)applicationActivitiesForActivityItemsConfiguration;
- (char)activityItemsConfigurationSupportsInteraction:(id)interaction;

@end

@blacktop
Copy link
Owner

LGTM

@blacktop blacktop merged commit a154bd1 into blacktop:master Apr 15, 2024
@t0rr3sp3dr0 t0rr3sp3dr0 deleted the t0rr3sp3dr0-patch-4 branch April 16, 2024 04:50
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