0

I am looking at implementing a swift version of some objective C code. I have a Typedef with the declaration:

void (^)(Class1 * _Nonnull, Class2 * _Nonnull)

The class declarations are:

@class Class1 : NSObject;
@class Class2 : NSObject;

Class2 has a result property as such:

@property (readonly, atomic) Result * _Nullable result;

When trying to use this, I have the following:

Class Properties

var object1: Class1?
var object2: Class2?
var result: Result?
var objectTD: TypedefName?

and some code:

self.object1 = try! Class1()
self.object2 = Class2.init()
self.objectTD = (self.object1, self.object2)
self.Class1!.method(self.objectTD)

The errors I get for the last two lines are:

Cannot assign value of type '(Class1?, Class2?)' to type 'TypedefName' (aka '(Class1, Class2) -> ()')

Value of optional type 'TypedefName?' (aka 'Optional<(Class1, Class2) -> ()>') must be unwrapped to a value of type 'TypedefName' (aka '(Class1, Class2) -> ()')

FerasAS
  • 273
  • 2
  • 14
  • 2
    This is actually too simple to duplicate. (Never thought I'd say that here.) Any Chance you could provide something to duplicate? That also means Obj-C code too. Be glad to try to help. And maybe in developing something I could duplicate, you might find the issue. –  Dec 19 '21 at 03:13
  • 1
    Maybe this helps: [Can not use Objective-c block in swift](https://stackoverflow.com/questions/45030325/can-not-use-objective-c-block-in-swift) – Willeke Dec 19 '21 at 12:20
  • @Willeke I am not sure if the link helps, or at least I still do not understand what I need to do. – FerasAS Dec 19 '21 at 12:28
  • 1
    `self.object1` and `self.object2` are defined as optionals and should be unwrapped before assign to `TypeDef`. – sbooth Dec 19 '21 at 21:36
  • 1
    Are you familiar with Objective-C blocks? Maybe this helps: [Use Objective-C blocks in swift](https://stackoverflow.com/questions/40460650/use-objective-c-blocks-in-swift) or search the Internet to find out how to use Objective-C blocks in Swift. – Willeke Dec 20 '21 at 14:03

0 Answers0