Skip to content

Commit

Permalink
feat(ios): CAPPluginMethod selector-based initializer (#7412)
Browse files Browse the repository at this point in the history
Co-authored-by: jcesarmobile <[email protected]>
  • Loading branch information
Steven0351 and jcesarmobile authored Jun 11, 2024
1 parent 30c13a8 commit 44c5b55
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ios/Capacitor/Capacitor.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
A38C3D7B2848BE6F004B3680 /* CapacitorCookieManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A38C3D7A2848BE6F004B3680 /* CapacitorCookieManager.swift */; };
A71289E627F380A500DADDF3 /* Router.swift in Sources */ = {isa = PBXBuildFile; fileRef = A71289E527F380A500DADDF3 /* Router.swift */; };
A71289EB27F380FD00DADDF3 /* RouterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A71289EA27F380FD00DADDF3 /* RouterTests.swift */; };
A7187FD22BD1CB7D00093C45 /* CAPPluginMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7187FD12BD1CB7D00093C45 /* CAPPluginMethod.swift */; };
A76739792B98E09700795F7B /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = A76739782B98E09700795F7B /* PrivacyInfo.xcprivacy */; };
A7BE62CC2B486A5400165ACB /* KeyValueStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BE62CB2B486A5400165ACB /* KeyValueStore.swift */; };
A7D8B3522B238A840003FAD6 /* JSValueEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7D8B3512B238A840003FAD6 /* JSValueEncoder.swift */; };
Expand Down Expand Up @@ -241,6 +242,7 @@
A38C3D7A2848BE6F004B3680 /* CapacitorCookieManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapacitorCookieManager.swift; sourceTree = "<group>"; };
A71289E527F380A500DADDF3 /* Router.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Router.swift; sourceTree = "<group>"; };
A71289EA27F380FD00DADDF3 /* RouterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RouterTests.swift; sourceTree = "<group>"; };
A7187FD12BD1CB7D00093C45 /* CAPPluginMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CAPPluginMethod.swift; sourceTree = "<group>"; };
A76739782B98E09700795F7B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
A7BE62CB2B486A5400165ACB /* KeyValueStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyValueStore.swift; sourceTree = "<group>"; };
A7D8B3512B238A840003FAD6 /* JSValueEncoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSValueEncoder.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -356,6 +358,7 @@
A7DB03AB29B001E300888AE9 /* CAPBridgedPlugin+getMethod.swift */,
62959B092524DA7700A3D7F1 /* CAPPluginMethod.h */,
62959AE82524DA7700A3D7F1 /* CAPPluginMethod.m */,
A7187FD12BD1CB7D00093C45 /* CAPPluginMethod.swift */,
62959AE22524DA7700A3D7F1 /* CAPPluginCall.h */,
62959B062524DA7700A3D7F1 /* CAPPluginCall.m */,
62959AE62524DA7700A3D7F1 /* CAPPluginCall.swift */,
Expand Down Expand Up @@ -700,6 +703,7 @@
62D43AF02581817500673C24 /* WKWebView+Capacitor.swift in Sources */,
62959B432524DA7800A3D7F1 /* Data+Capacitor.swift in Sources */,
62E207AE2588234500A78983 /* WebViewDelegationHandler.swift in Sources */,
A7187FD22BD1CB7D00093C45 /* CAPPluginMethod.swift in Sources */,
621ECCBC2542046400D3D615 /* JSTypes.swift in Sources */,
621ECCDA254205C400D3D615 /* CapacitorBridge.swift in Sources */,
62959B382524DA7800A3D7F1 /* CAPPluginCall.m in Sources */,
Expand Down
2 changes: 1 addition & 1 deletion ios/Capacitor/Capacitor/CAPPluginMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ typedef NSString CAPPluginReturnType;
@property (nonatomic, strong) CAPPluginReturnType *returnType; // Return type of method (i.e. callback/promise/sync)

- (instancetype)initWithName:(NSString *)name returnType:(CAPPluginReturnType *)returnType;

- (instancetype)initWithSelector:(SEL)selector returnType:(CAPPluginReturnType *)returnType;

@end
8 changes: 8 additions & 0 deletions ios/Capacitor/Capacitor/CAPPluginMethod.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ -(instancetype)initWithName:(NSString *)name returnType:(CAPPluginReturnType *)r
return self;
}

-(instancetype)initWithSelector:(SEL) selector returnType:(CAPPluginReturnType *)returnType {
// need to drop the : from the selector string
NSString* rawSelString = NSStringFromSelector(selector);
self.name = [rawSelString substringToIndex:[rawSelString length] - 1];
self.selector = selector;
self.returnType = returnType;
return self;
}

@end

17 changes: 17 additions & 0 deletions ios/Capacitor/Capacitor/CAPPluginMethod.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CAPPluginMethod.swift
// Capacitor
//
// Created by Steven Sherry on 4/18/24.
// Copyright © 2024 Drifty Co. All rights reserved.
//

extension CAPPluginMethod {
public enum ReturnType: String {
case promise, callback, none
}

public convenience init(_ selector: Selector, returnType: ReturnType = .promise) {
self.init(selector: selector, returnType: returnType.rawValue)
}
}

0 comments on commit 44c5b55

Please sign in to comment.