This file contains 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
#import <Foundation/Foundation.h> | |
@protocol MyProtocol <NSObject> | |
@required | |
-(void) mustImplementMethod1; | |
-(void) mustImplementMethod2; | |
-(void) mustImplementMethod3; | |
-(void) mustImplementMethod4; |
This file contains 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
#import <UIKit/UIKit.h> | |
#import "MyProtocol.h" | |
@interface ViewController : UIViewController <MyProtocol> | |
@end |
This file contains 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
import UIKit | |
protocol WeatherServiceDelegate: class { | |
func didCompleteRequest(result: String) | |
} | |
class WeatherService: NSObject { | |
weak var delegate:WeatherServiceDelegate? |
This file contains 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
// There are two ways of doing this: | |
// Way 1: use swift's multi-inheritance | |
class ViewController: UIViewController, WeatherServiceDelegate { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. |
This file contains 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
class Foo(object): | |
variable = 1 | |
def method(self, param): | |
print "run instance method (%s,%s)" % (self, param) | |
@classmethod | |
def class_method1(cls, param): |
This file contains 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
//CalculateChain.h | |
#import <Foundation/Foundation.h> | |
@interface CalculateChain : NSObject | |
@property (nonatomic) float result; | |
@property (readonly, nonatomic, copy) CalculateChain* (^add)(float num); | |
@property (readonly, nonatomic, copy) CalculateChain* (^minus)(float num); |
This file contains 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
// NSNumber+CalculateChain2.h | |
#import <Foundation/Foundation.h> | |
@interface NSNumber (CalculateChain2) | |
-(NSNumber*(^)(float))add; | |
-(NSNumber*(^)(float))minus; | |
-(NSNumber*(^)(float))multiply; | |
-(NSNumber*(^)(float))divide; |
This file contains 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
// view controller.h | |
#import <UIKit/UIKit.h> | |
#import "Item.h" | |
@interface ViewController : UIViewController | |
@property (nonatomic, strong) NSString *myVal; | |
@end |
This file contains 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
// item.h | |
#import <Foundation/Foundation.h> | |
@interface Item : NSObject | |
+(instancetype)sharedInstance; | |
@end |
This file contains 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
#import "Item.h" | |
static id _instance; | |
@implementation Item | |
+ (id)allocWithZone:(struct _NSZone *)zone | |
{ | |
static dispatch_once_t onceToken; |