How to reuse Swift typealias in Objective-C code
Asked Answered
S

1

9

I'm creating a custom react-native module and I have this custom type in a swift file

VideoTrimmer.swift

typealias TrimCompletion = (Error?) -> ()

how do I import or reuse it in a file with objective code? Or what's the syntax to redeclare it? I'm not so familiar with Objective-C syntax.

VideoTrimmer.m

#import "React/RCTBridgeModule.h"
@interface RCT_EXTERN_MODULE(VideoTrimmer, NSObject)
  RCT_EXTERN_METHOD(trimVideo:(NSURL *)sourceURL destinationURL:(NSURL 
  *)destinationURL startTime:(int *)startTime endTime:(int *)endTime 
  completion:(TrimCompletion *)completion)
@end
Sowers answered 10/12, 2017 at 18:26 Comment(0)
C
19

Typealiases defined in Swift are not supported in Objective-C. However, you should be able redeclare the block type in Objective-C with typedef:

typedef void (^TrimCompletion)(NSError *);
Clathrate answered 3/1, 2018 at 1:7 Comment(2)
Can you post the Swift equivalent of the Objective-C code you posted.Tautology
@Tautology it's in the question: typealias TrimCompletion = (Error?) -> VoidClathrate

© 2022 - 2024 — McMap. All rights reserved.