Embed Objective c protocol in Swift

I have this protocol in the c object class:

@protocol YTManagerDelegate <NSObject> @required - (void)uploadProgressPercentage:(int)percentage; @end ... 

and its associated quick class:

 class YTShare: UIViewController, YTManagerDelegate{ func uploadProgressPercentage(percentage:Int?){ println(percentage) } ... 

I get an error: the YTShare type does not conform to the YTShareDelegate protocol , I probably wrote the fast function incorrectly, so the obj class does not find it. How can I write this correctly?

+5
source share
1 answer

There are two errors in the delegate method.

 func uploadProgressPercentage(percentage:Int?){ println(percentage) } 

The parameter should not be optional, and the type C int displayed in Swift as CInt (an alias for Int32 ):

 func uploadProgressPercentage(percentage:CInt){ println(percentage) } 

Alternatively, you can use NSInteger in the Objective-C protocol, which maps to int in Swift. It will be a 32-bit or 64-bit integer, depending on the architecture, while int / CInt always 32-bit.

+5
source

Source: https://habr.com/ru/post/1206230/


All Articles