From fff53f68c9926590f055469b0ee52cc856c22b99 Mon Sep 17 00:00:00 2001 From: "Alkenso (Vladimir Vashurkin)" Date: Sun, 17 Oct 2021 12:08:26 +0300 Subject: [PATCH] Updated ObjC bridging layout --- Package.swift | 8 ++--- .../ObjC Bridging/ObjC.swift} | 25 ++++++-------- .../SwiftConvenienceObjC.h} | 4 +-- .../SwiftConvenienceObjC.m} | 34 ++++++++++++++++++- 4 files changed, 49 insertions(+), 22 deletions(-) rename Sources/{SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.m => SwiftConvenience/ObjC Bridging/ObjC.swift} (80%) rename Sources/{SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.h => SwiftConvenienceObjC/SwiftConvenienceObjC.h} (90%) rename Sources/{SwiftConvenience/_Support Files/Exported.swift => SwiftConvenienceObjC/SwiftConvenienceObjC.m} (68%) diff --git a/Package.swift b/Package.swift index bb4b478..5146d95 100644 --- a/Package.swift +++ b/Package.swift @@ -7,10 +7,9 @@ let package = Package( name: "SwiftConvenience", platforms: [.macOS(.v10_10), .iOS(.v9), .tvOS(.v9), .watchOS(.v2)], products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. .library( name: "SwiftConvenience", - targets: ["SwiftConvenience", "SwiftConvenienceObjcBridge"] + targets: ["SwiftConvenience"] ), .library( name: "SwiftConvenienceTestUtils", @@ -22,12 +21,11 @@ let package = Package( targets: [ .target( name: "SwiftConvenience", - dependencies: ["SwiftConvenienceObjcBridge"], + dependencies: ["SwiftConvenienceObjC"], linkerSettings: [LinkerSetting.linkedLibrary("bsm", .when(platforms: [.macOS]))] ), .target( - name: "SwiftConvenienceObjcBridge", - dependencies: [], + name: "SwiftConvenienceObjC", publicHeadersPath: "." ), .target( diff --git a/Sources/SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.m b/Sources/SwiftConvenience/ObjC Bridging/ObjC.swift similarity index 80% rename from Sources/SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.m rename to Sources/SwiftConvenience/ObjC Bridging/ObjC.swift index 7e9f9bc..2e97147 100644 --- a/Sources/SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.m +++ b/Sources/SwiftConvenience/ObjC Bridging/ObjC.swift @@ -20,22 +20,19 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -#import "SwiftConvenienceObjcBridge.h" +import Foundation +@_implementationOnly import SwiftConvenienceObjC -@implementation NSException (SwiftConvenience) - -+ (nullable instancetype)catching:(void(NS_NOESCAPE ^)(void))block -{ - @try - { - block(); - return nil; - } - @catch (NSException *exception) - { - return exception; +extension NSException { + public static func catching(_ body: () -> Void) -> NSException? { + scbridge_catching(body) } } -@end + +extension NSXPCConnection { + public var auditToken: audit_token_t { + scbridge_auditToken + } +} diff --git a/Sources/SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.h b/Sources/SwiftConvenienceObjC/SwiftConvenienceObjC.h similarity index 90% rename from Sources/SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.h rename to Sources/SwiftConvenienceObjC/SwiftConvenienceObjC.h index 2445f66..7769ca4 100644 --- a/Sources/SwiftConvenienceObjcBridge/SwiftConvenienceObjcBridge.h +++ b/Sources/SwiftConvenienceObjC/SwiftConvenienceObjC.h @@ -27,14 +27,14 @@ NS_ASSUME_NONNULL_BEGIN @interface NSException (SwiftConvenience) -+ (nullable instancetype)catching:(void(NS_NOESCAPE ^)(void))block; ++ (nullable instancetype)scbridge_catching:(void(NS_NOESCAPE ^)(void))block; @end @interface NSXPCConnection (SwiftConvenience) -@property (nonatomic, readonly) audit_token_t auditToken; +@property (nonatomic, readonly) audit_token_t scbridge_auditToken; @end diff --git a/Sources/SwiftConvenience/_Support Files/Exported.swift b/Sources/SwiftConvenienceObjC/SwiftConvenienceObjC.m similarity index 68% rename from Sources/SwiftConvenience/_Support Files/Exported.swift rename to Sources/SwiftConvenienceObjC/SwiftConvenienceObjC.m index b8bfb79..736f989 100644 --- a/Sources/SwiftConvenience/_Support Files/Exported.swift +++ b/Sources/SwiftConvenienceObjC/SwiftConvenienceObjC.m @@ -20,4 +20,36 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. -@_exported import SwiftConvenienceObjcBridge +#import "SwiftConvenienceObjC.h" + + +@implementation NSException (SwiftConvenience) + ++ (nullable instancetype)sc_catching:(void(NS_NOESCAPE ^)(void))block +{ + @try + { + block(); + return nil; + } + @catch (NSException *exception) + { + return exception; + } +} + +@end + + +@interface NSXPCConnection (SwiftConveniencePrivate) +@property (nonatomic, readonly) audit_token_t auditToken; +@end + +@implementation NSXPCConnection (SwiftConvenience) + +- (audit_token_t)scbridge_auditToken +{ + self.auditToken; +} + +@end