[linters] Remove the linters UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK and REGISTERED_OBSERVER_BEING_DEALLOCATED
Summary: There is now a compilation check for UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK so this check is less useful. Also the check REGISTERED_OBSERVER_BEING_DEALLOCATED is useful only in an old version of iOS. Reviewed By: ngorogiannis Differential Revision: D22231851 fbshipit-source-id: 72151fef5master
parent
fc6cd0cb28
commit
622f0fb6f2
@ -1,5 +0,0 @@
|
||||
Objects register with a notification center to receive notifications. This check
|
||||
warns you when an object is registered as observer of a NSNotificationCenter but
|
||||
it is never unregistered. This is problematic as if the object is not
|
||||
unregistered the notification center can still send notification even after the
|
||||
object has been deallocated. In that case we would get a crash.
|
@ -1,20 +0,0 @@
|
||||
This checks warns you when you are using an API (constant, method call, etc.)
|
||||
that is only defined in a version higher than the version that you support. To
|
||||
enable this check, pass to Infer the option
|
||||
`--iphoneos-target-sdk-version version`. Calling an undefined API will lead to a
|
||||
crash in the app. To fix this, you can choose a different API or use it inside
|
||||
an if, as in:
|
||||
|
||||
```objectivec
|
||||
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
|
||||
font = [UIFont systemFontOfSize:size weight:0];
|
||||
}
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```objectivec
|
||||
if (kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_9_0) {
|
||||
font = [UIFont systemFontOfSize:size weight:0];
|
||||
}
|
||||
```
|
@ -1,22 +0,0 @@
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
TESTS_DIR = ../../..
|
||||
|
||||
CLANG_OPTIONS = -c $(OBJC_CLANG_OPTIONS) -fobjc-arc
|
||||
|
||||
INFER_OPTIONS = --no-capture --linters-only --no-filtering --debug-exceptions --project-root $(TESTS_DIR) \
|
||||
--iphoneos-target-sdk-version 8.0 \
|
||||
--iphoneos-target-sdk-version-path-regex "codetoanalyze/objc/ioslints/filter_out_unavailable_api\.m:10.0" \
|
||||
--iphoneos-target-sdk-version-path-regex "codetoanalyze/objc/ioslints/RemoveObserverInGivenSDKTest\.m:9.0" \
|
||||
|
||||
INFERPRINT_OPTIONS = --issues-tests
|
||||
|
||||
SOURCES = \
|
||||
$(wildcard *.m) \
|
||||
$(wildcard */*.m) \
|
||||
|
||||
include $(TESTS_DIR)/clang.make
|
||||
include $(TESTS_DIR)/objc.make
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface RemoveObserverInGivenSDKTest2 : NSObject
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation RemoveObserverInGivenSDKTest2
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
@ -1,25 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface Filter_out_unavailable_api : NSObject
|
||||
|
||||
- (void)n NS_AVAILABLE(10_12, 10_0);
|
||||
|
||||
@end
|
||||
|
||||
@implementation Filter_out_unavailable_api
|
||||
|
||||
- (void)n {
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)with_responds_to_selector:(Filter_out_unavailable_api*)a {
|
||||
[a n];
|
||||
}
|
||||
|
||||
@end
|
@ -1,10 +0,0 @@
|
||||
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases.m2, 144, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases.m3, 152, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases.uifont_without_respondstoselector, 127, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases.with_responds_to_selector_in_else, 80, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases.without_instances_responds_to_selector, 104, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_allowed_cases.m, Unavailable_api_allowed_cases.without_responds_to_selector, 65, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, OpenURLOptionsFromSourceApplication, 69, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk.unsupported_class, 35, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_api_in_supported_ios_sdk.m, Unavailable_api_in_supported_ios_sdk.unsupported_class_with_attributes, 54, UNAVAILABLE_CLASS_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
||||
codetoanalyze/objc/ioslints/unavailable_property_ios.m, FNFPlayerLayer.initWithConfigs, 20, UNAVAILABLE_API_IN_SUPPORTED_IOS_SDK, no_bucket, ERROR, []
|
@ -1,223 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#import <AVFoundation/AVPlayer.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Photos/PHAssetResource.h>
|
||||
#import <UIKit/UIImagePickerController.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface Unavailable_api_allowed_cases : NSObject
|
||||
|
||||
- (void)m NS_AVAILABLE(10_12, 10_0);
|
||||
|
||||
- (void)n NS_AVAILABLE(10_12, 10_0);
|
||||
|
||||
@property(nonatomic, strong) AVPlayer* player;
|
||||
|
||||
@end
|
||||
|
||||
#define CK_AT_LEAST_IOS9 (kCFCoreFoundationVersionNumber >= 1223.1)
|
||||
|
||||
#define AT_LEAST_IOS9 \
|
||||
(kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_9_0)
|
||||
|
||||
#ifndef kCFCoreFoundationVersionNumber_iOS_10_0
|
||||
#define kCFCoreFoundationVersionNumber_iOS_10_0 1348
|
||||
#endif
|
||||
|
||||
#ifndef kCFCoreFoundationVersionNumber_iOS_10_2
|
||||
#define kCFCoreFoundationVersionNumber_iOS_10_2 1348.22
|
||||
#endif
|
||||
|
||||
#define AT_LEAST_IOS10 \
|
||||
(kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_10_0)
|
||||
|
||||
@implementation Unavailable_api_allowed_cases
|
||||
|
||||
- (void)m {
|
||||
}
|
||||
|
||||
- (void)n {
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)with_responds_to_selector:(Unavailable_api_allowed_cases*)a {
|
||||
if ([a respondsToSelector:@selector(m)]) {
|
||||
int x = 1;
|
||||
[a m];
|
||||
x = 3;
|
||||
}
|
||||
}
|
||||
// no bug
|
||||
- (void)with_responds_to_selector:(Unavailable_api_allowed_cases*)a
|
||||
and:(BOOL)ok {
|
||||
if ([a respondsToSelector:@selector(m)] && ok) {
|
||||
[a m];
|
||||
}
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)without_responds_to_selector:(Unavailable_api_allowed_cases*)a {
|
||||
[a m];
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)call_m:(Unavailable_api_allowed_cases*)a
|
||||
API_AVAILABLE(ios(10), macosx(10.13)) {
|
||||
int x = 1;
|
||||
[a m];
|
||||
x = 3;
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)with_responds_to_selector_in_else:(Unavailable_api_allowed_cases*)a {
|
||||
if ([a respondsToSelector:@selector(m)]) {
|
||||
} else {
|
||||
[a m];
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)with_responds_to_selector_nested_if:(Unavailable_api_allowed_cases*)a {
|
||||
if ([a respondsToSelector:@selector(m)]) {
|
||||
if ([a respondsToSelector:@selector(n)]) {
|
||||
[a m];
|
||||
[a n];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)with_instances_responds_to_selector {
|
||||
if ([[UICollectionView class]
|
||||
instancesRespondToSelector:@selector(setPrefetchingEnabled:)]) {
|
||||
[[UICollectionView appearance] setPrefetchingEnabled:NO];
|
||||
}
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)without_instances_responds_to_selector {
|
||||
[[UICollectionView appearance] setPrefetchingEnabled:NO];
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)with_responds_to_selector_two_selectors:
|
||||
(Unavailable_api_allowed_cases*)a {
|
||||
if ([a respondsToSelector:@selector(m)] &&
|
||||
[a respondsToSelector:@selector(n)]) {
|
||||
[a m];
|
||||
[a n];
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)uifont_with_respondstoselector:(CGFloat)size {
|
||||
UIFont* font;
|
||||
if ([UIFont respondsToSelector:@selector(systemFontOfSize:weight:)]) {
|
||||
font = [UIFont systemFontOfSize:size weight:0];
|
||||
}
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)uifont_without_respondstoselector:(CGFloat)size {
|
||||
UIFont* font = [UIFont systemFontOfSize:size weight:0];
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)m1 {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (kCFCoreFoundationVersionNumber >=
|
||||
kCFCoreFoundationVersionNumber_iOS_9_0) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)m2 {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)m3:(BOOL)ok {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (ok) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)m4:(BOOL)ok {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (kCFCoreFoundationVersionNumber >=
|
||||
kCFCoreFoundationVersionNumber_iOS_9_0 &&
|
||||
ok) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)m5 {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (kCFCoreFoundationVersionNumber >=
|
||||
kCFCoreFoundationVersionNumber_iOS_9_0 &&
|
||||
kCFCoreFoundationVersionNumber >=
|
||||
kCFCoreFoundationVersionNumber_iOS_7_0) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)m6 {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (AT_LEAST_IOS9) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)m7 {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (CK_AT_LEAST_IOS9) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)m8 {
|
||||
NSDictionary* destinationPixelBufferAttributes;
|
||||
if (AT_LEAST_IOS10) {
|
||||
destinationPixelBufferAttributes =
|
||||
@{(NSString*)kCVPixelBufferOpenGLESTextureCacheCompatibilityKey : @YES};
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)playInReverse {
|
||||
if ([self.player respondsToSelector:@selector(playImmediatelyAtRate:)]) {
|
||||
[self.player playImmediatelyAtRate:-1.0];
|
||||
}
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (PHAsset*)improper_ios_version_good:(NSDictionary*)info {
|
||||
PHAsset* videoAsset = NULL;
|
||||
if (@available(iOS 11, *)) { // not strictly correct version number, should be
|
||||
// "11.0" We should handle this case anyway.
|
||||
videoAsset = [info objectForKey:UIImagePickerControllerPHAsset];
|
||||
}
|
||||
return videoAsset;
|
||||
}
|
||||
|
||||
@end
|
@ -1,71 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
NS_CLASS_AVAILABLE(10_12, 10_0)
|
||||
|
||||
@interface Unav_class : NSObject
|
||||
|
||||
- (void)m;
|
||||
|
||||
@end
|
||||
|
||||
@interface Unavailable_api_in_supported_ios_sdk : NSObject
|
||||
|
||||
@end
|
||||
|
||||
@implementation Unavailable_api_in_supported_ios_sdk
|
||||
|
||||
// no bug
|
||||
- (void)test_no_bug:(int)n and:(NSData*)data {
|
||||
if (@available(macOS 10.13, iOS 11.0, *)) {
|
||||
NSDictionary* cacheData =
|
||||
[NSKeyedUnarchiver unarchiveTopLevelObjectWithData:data error:nil];
|
||||
}
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)unsupported_class {
|
||||
AVPlayerLooper* looper =
|
||||
[[AVPlayerLooper alloc] initWithPlayer:nil
|
||||
templateItem:nil
|
||||
timeRange:kCMTimeRangeInvalid];
|
||||
if (!looper) {
|
||||
NSLog(@"");
|
||||
}
|
||||
}
|
||||
// no bug
|
||||
- (void)unsupported_class_with_check {
|
||||
if ([AVPlayerLooper class]) {
|
||||
AVPlayerLooper* looper =
|
||||
[[AVPlayerLooper alloc] initWithPlayer:nil
|
||||
templateItem:nil
|
||||
timeRange:kCMTimeRangeInvalid];
|
||||
}
|
||||
}
|
||||
|
||||
// bug
|
||||
- (void)unsupported_class_with_attributes:(nonnull Unav_class*)c {
|
||||
[Unav_class new];
|
||||
}
|
||||
|
||||
// no bug
|
||||
- (void)unsupported_class_with_attributes_with_check:(nonnull Unav_class*)c {
|
||||
if ([Unav_class class]) {
|
||||
[[Unav_class alloc] init];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static NSDictionary* OpenURLOptionsFromSourceApplication(
|
||||
NSString* sourceApplication) {
|
||||
NSDictionary* options =
|
||||
@{UIApplicationOpenURLOptionsSourceApplicationKey : sourceApplication};
|
||||
return options;
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
#import <AVFoundation/AVFoundation.h>
|
||||
|
||||
@interface FNFPlayerLayer : CAEAGLLayer
|
||||
|
||||
- (instancetype)initWithConfigs:(FNFPlayerLayer*)configs;
|
||||
|
||||
@end
|
||||
|
||||
@implementation FNFPlayerLayer {
|
||||
BOOL my_field;
|
||||
}
|
||||
|
||||
- (instancetype)initWithConfigs:(FNFPlayerLayer*)configs {
|
||||
my_field = configs.presentsWithTransaction;
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// OkPerson is the only class in the whole hierarchy that invokes removeObserver
|
||||
|
||||
@interface OkPerson : NSObject
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation OkPerson
|
||||
|
||||
- (void)boo {
|
||||
[self.nc removeObserver:self];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface OkPerson2 : OkPerson
|
||||
|
||||
@end
|
||||
|
||||
@implementation OkPerson2
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface OkPerson3 : OkPerson2
|
||||
|
||||
@end
|
||||
|
||||
@implementation OkPerson3
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
// No one in the whole hierarchy of BadPerson invokes removeObserver
|
||||
|
||||
@interface BadPerson : NSObject
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadPerson
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface BadPerson2 : BadPerson
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadPerson2
|
||||
|
||||
- (void)foo:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// ---
|
||||
|
||||
@interface BadPerson3 : BadPerson2
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
@end
|
||||
|
||||
@implementation BadPerson3
|
||||
|
||||
- (void)fooRegister:(NSMutableDictionary*)dict {
|
||||
self.nc = [NSNotificationCenter defaultCenter];
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
@end
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ViewController : NSObject
|
||||
@end
|
||||
|
||||
@implementation ViewController
|
||||
|
||||
- (instancetype)init {
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(fired)
|
||||
name:@"some_notification"
|
||||
object:nil];
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)fired {
|
||||
NSLog(@"This codepath fired");
|
||||
}
|
||||
|
||||
- (void)invalidate1 {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (void)invalidate2 {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:@"some_notification"
|
||||
object:nil];
|
||||
}
|
||||
@end
|
||||
|
||||
int fooError() {
|
||||
ViewController* vc = [[ViewController alloc] init];
|
||||
ViewController* vc2;
|
||||
vc2 = vc;
|
||||
[vc fired];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fooOK1() {
|
||||
ViewController* vc = [[ViewController alloc] init];
|
||||
ViewController* vc2;
|
||||
vc2 = vc;
|
||||
[vc fired];
|
||||
[vc invalidate1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int fooOK2() {
|
||||
ViewController* vc = [[ViewController alloc] init];
|
||||
ViewController* vc2;
|
||||
vc2 = vc;
|
||||
[vc fired];
|
||||
[vc invalidate2];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int barError() {
|
||||
// ViewController* vc = [[ViewController alloc] init];
|
||||
//[vc fired];
|
||||
|
||||
// vc = [[ViewController alloc] init];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int barOK1() {
|
||||
ViewController* vc = [[ViewController alloc] init];
|
||||
[vc invalidate1];
|
||||
vc = [[ViewController alloc] init];
|
||||
[vc invalidate1];
|
||||
return 0;
|
||||
}
|
||||
|
||||
int barOK2() {
|
||||
ViewController* vc = [[ViewController alloc] init];
|
||||
[vc invalidate2];
|
||||
vc = [[ViewController alloc] init];
|
||||
[vc invalidate1];
|
||||
return 0;
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ViewController : NSObject
|
||||
@end
|
||||
@implementation ViewController
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(fired)
|
||||
name:@"some_notification"
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self
|
||||
name:@"some_notification"
|
||||
object:nil];
|
||||
}
|
||||
@end
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ViewControllerError : NSObject
|
||||
@end
|
||||
@implementation ViewControllerError
|
||||
|
||||
- (instancetype)init {
|
||||
if (self = [super init]) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(fired)
|
||||
name:@"some_notification"
|
||||
object:nil];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@end
|
@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface AA : NSObject
|
||||
|
||||
@property(strong) NSNotificationCenter* nc;
|
||||
|
||||
- (void)my_method:(double)d
|
||||
block_param:(double (^)(double time))myblock
|
||||
st:(int)numSteps;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AA
|
||||
|
||||
- (void)foo {
|
||||
[self.nc addObserver:self selector:@selector(foo:) name:nil object:nil];
|
||||
}
|
||||
|
||||
- (void)my_method:(double)d
|
||||
block_param:(double (^)(double time))myblock
|
||||
st:(int)num {
|
||||
for (int i = 1; i <= num; i++) {
|
||||
if (myblock)
|
||||
myblock(i * d * num);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)boo {
|
||||
|
||||
[self my_method:5.3
|
||||
block_param:^(double time) {
|
||||
[self.nc removeObserver:self];
|
||||
return time + 7.4;
|
||||
}
|
||||
st:30];
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in new issue