I'm trying to convert an Objective-C project to Swift, here is one of the .h file in Objective-C:
typedef void(^PrintBlock)(HLPrinter *printer);
@interface ShoppingViewController : UIViewController
@property (copy, nonatomic) PrintBlock printBlock;
@end
and in the .m file, there is a function:
HLPrinter *printer = [self getPrinter];
if (_printBlock) {
_printBlock(printer);
}
And this is how I converted it into Swift:
typealias PrintBlock = (_ printer: HLPrinter?) -> Void
But when I tried to convert the function above into Swift, I get a 'Non-nominal type 'PrintBlock' (aka '(Optional<HLPrinter>) -> ()') does not support explicit initialization'
error when I was trying to declare a variable with type PrintBlock
:
let pb = PrintBlock()
I'm not familiar with Objective-C, so how should I convert that function with _printerBlock
into Swift?