[objc blocks] Specialize store instructions with current closure in methods specialized with blocks as arguments
Reviewed By: mbouaziz, jvillard Differential Revision: D7744403 fbshipit-source-id: 42ad5f8master
parent
496e5e8c0a
commit
28200b87d7
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2018 - present Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
#import <Foundation/NSObject.h>
|
||||
#import <Foundation/NSData.h>
|
||||
|
||||
typedef void (^MyHandler)(NSData* newData);
|
||||
|
||||
@interface Fetcher : NSObject
|
||||
|
||||
@property(nonatomic, strong) MyHandler completionBlock;
|
||||
|
||||
- (instancetype)initWithCompletionBlock:(MyHandler)block;
|
||||
|
||||
@end
|
||||
|
||||
@implementation Fetcher
|
||||
|
||||
- (instancetype)initWithCompletionBlock:(_Nonnull MyHandler)block {
|
||||
_completionBlock = block;
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface FBSomeDataManager : NSObject
|
||||
|
||||
- (void)setData:(NSData*)data;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FBSomeDataManager {
|
||||
Fetcher* _fetcher;
|
||||
NSData* _data;
|
||||
}
|
||||
|
||||
- (void)setData:(NSData*)data {
|
||||
_data = data;
|
||||
}
|
||||
|
||||
- (void)fetchNewData {
|
||||
// We retain fetcher
|
||||
_fetcher = [[Fetcher alloc] initWithCompletionBlock:^(NSData* newData) {
|
||||
// fetcher retains us
|
||||
[self setData:newData];
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in new issue