Skip to content

Commit

Permalink
Updated ObjC bridging layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkenso committed Oct 17, 2021
1 parent 0924bb5 commit fff53f6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 22 deletions.
8 changes: 3 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit fff53f6

Please sign in to comment.