Last active
October 25, 2019 14:30
-
-
Save wendyliga/74b6e91100682676fe9c4f8b1d695235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
myProtocol.h | |
*/ | |
@protocol MyProtocol <NSObject> | |
@property (nonatomic) BOOL myVariable; | |
@end | |
/** | |
MyClass.h | |
*/ | |
@interface MyClass <MyProtocol> | |
@end | |
/** | |
MyClass.m | |
*/ | |
@implementation MyClass | |
@synthesize myVariable; | |
@end |
@zeinrezky
hmm, kalau gw mw implementasi property di dalam delegate nya gmna pak?
kalau di swift dia bakal jadi setter getter
extension MyClass: MyProtocol {
public var myVariable: Bool {
get {
// code here
}
set(myVariable) {
// code here
}
}
}
kalau di objc, setelah di @synthesize
, harus di init kah ?
@zeinrezky
hmm, kalau gw mw implementasi property di dalam delegate nya gmna pak?kalau di swift dia bakal jadi setter getter
extension MyClass: MyProtocol { public var myVariable: Bool { get { // code here } set(myVariable) { // code here } } }
kalau di objc, setelah di
@synthesize
, harus di init kah ?
ga perlu init lagi, akses dari delegate nya.
/**
@protocol MyProtocol <NSObject>
@property (nonatomic) BOOL myVariable;
@end
*/
/**
MyClass.m
*/
@implementation
@synthesis delegate
[delegate myVariable] = true;
@end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
context nya lo hanya mau instance dari myVariable ya?
/**
MyClass.h
*/
@protocol MyProtocol
@interface MyClass
@Property(nonatomic, weak) id delegate;
@EnD
/**
MyClass.m
*/
@implementation
@synthesize delegate;
// do stuff with myVariable through the delegate
@EnD