Skip to content

Instantly share code, notes, and snippets.

@wendyliga
Last active October 25, 2019 14:30
Show Gist options
  • Save wendyliga/74b6e91100682676fe9c4f8b1d695235 to your computer and use it in GitHub Desktop.
Save wendyliga/74b6e91100682676fe9c4f8b1d695235 to your computer and use it in GitHub Desktop.
/**
myProtocol.h
*/
@protocol MyProtocol <NSObject>
@property (nonatomic) BOOL myVariable;
@end
/**
MyClass.h
*/
@interface MyClass <MyProtocol>
@end
/**
MyClass.m
*/
@implementation MyClass
@synthesize myVariable;
@end
@zeinrezky
Copy link

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

@wendyliga
Copy link
Author

wendyliga commented Oct 25, 2019

@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
Copy link

@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