I have this protocol in a objective c class:
@protocol YTManagerDelegate <NSObject>
@required
- (void)uploadProgressPercentage:(int)percentage;
@end
...
and a swift class connected to it:
class YTShare: UIViewController, YTManagerDelegate{
func uploadProgressPercentage(percentage:Int?){
println(percentage)
}
...
I receive the error: type YTShare does not conform to protocol YTShareDelegate, I have probably write incorrectly the swift function so the obj class don't find it. How I can write it correctly?
There are two errors in the delegate method
func uploadProgressPercentage(percentage:Int?){
println(percentage)
}
The parameter must not be an optional, and the C type int
is mapped to Swift
as CInt
(an alias for Int32
):
func uploadProgressPercentage(percentage:CInt){
println(percentage)
}
Alternatively, you could use NSInteger
in the Objective-C protocol, which is
mapped to Int
in Swift. This would be a 32-bit or 64-bit integer, depending
on the architecture, whereas int
/CInt
is always 32-bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With