Convert Objective-C code to Swift: delegate -
Convert Objective-C code to Swift: delegate -
i'm learning function written in objective-c. don't know objective-c language. when i'm converting code swift, got stuck @ delegate functions.
the code in .h file is:
#import <uikit/uikit.h> @protocol scpopviewdelegate <nsobject> @optional - (void)viewheight:(cgfloat)height; - (void)itempressedwithindex:(nsinteger)index; @end @interface scpopview : uiview @property (nonatomic, weak) id <scpopviewdelegate>delegate; @property (nonatomic, strong) nsarray *itemnames; @end
and i'm trying convert code as:
protocol popviewdelegate: class { func itempressedwithindex(index: int) func viewheight(height: cgfloat) }
but 3 lastly sentences, don’t know how deal them, 1 id
, delegate
.
can help, please? more effort larn swift. give thanks much!
the definition of protocol ends first @end statement.
the @interface after definition of objective-c class, scpopview.
you don't need care latter part if you're trying define protocol in swift.
fyi:
@interface someclass: nsobject
is equivalent to
class someclass: nsobject
in swift.
objective-c swift delegates protocols
Comments
Post a Comment