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
#define MACRO_SINGLETON_H \ | |
+ (instancetype)sharedInstance;\ | |
- (instancetype)init NS_UNAVAILABLE;\ | |
+ (instancetype)new NS_UNAVAILABLE;\ | |
+ (instancetype)allocWithZone:(struct _NSZone *)zone NS_UNAVAILABLE;\ | |
- (id)copy NS_UNAVAILABLE;\ | |
- (id)mutableCopy NS_UNAVAILABLE;\ | |
+ (id)copyWithZone:(struct _NSZone *)zone NS_UNAVAILABLE;\ | |
+ (id)mutableCopyWithZone:(struct _NSZone *)zone NS_UNAVAILABLE;\ |
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
1. 静态库 | |
只编译不链接 | |
只要头文件在,无需设置依赖 | |
会打包进主工程二进制文件 | |
2. 动态库 | |
既编译又链接 | |
必须设置依赖 | |
不会打包进主工程二进制文件 | |
3. 当且仅当动态库依赖静态库时,才会copy静态库的代码到动态库二进制 |
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
#define UIImageWithName(IMAGE_NAME)\ | |
(^UIImage *(NSString *imageName){\ | |
NSAssert(imageName.length != 0, @"imageName is empty");\ | |
if (imageName.length == 0) {\ | |
return nil;\ | |
}\ | |
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle bundleForClass:NSClassFromString(@"SHPUIModule")] pathForResource:@"SHPUIKit" ofType:@"bundle"]];\ | |
NSAssert(bundle != nil, @"bundle is nil");\ | |
if (bundle == nil) {\ | |
return nil;\ |
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
# iOS 10 or above | |
1. **Cold start** | |
1. normal notification | |
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: | |
2. silent notification | |
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: | |
2. **Hot start** | |
1. normal notification | |
userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler: |
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
<html> | |
<head> | |
<title>Safari Memory Hole</title> | |
</head> | |
<body> | |
<textarea>This file takes 30MB in Chrome but 2GB in Safari</textarea> | |
<script> | |
var m = {}; |
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
- (id)weakObject { | |
id (^block)() = objc_getAssociatedObject(self, @selector(weakObject)); | |
return (block ? block() : nil); | |
} | |
- (void)setWeakObject:(id)object { | |
id __weak weakObject = object; | |
id (^block)() = ^{ return weakObject; }; | |
objc_setAssociatedObject(self, @selector(weakObject), | |
block, OBJC_ASSOCIATION_COPY); |
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
int i = 0; | |
while (YES) { | |
@autoreleasepool { | |
NSString *string = [[NSString alloc] initWithFormat:@"%d", i]; | |
// or | |
// NSString *string = [[NSString alloc] init]; | |
[[string rac_willDeallocSignal] subscribeCompleted:^{ | |
NSLog(@"obj dealloc"); | |
}]; |
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
@interface MyObject : NSObject | |
@property NSString *name; | |
@end | |
@implementation MyObject | |
-(void)dealloc | |
{ | |
NSLog(@"dealloc"); | |
} | |
@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 Foundation | |
// Double | |
func + (leftAddend: Double, rightAddend: Double) -> Double { | |
fatalError() | |
} | |
func - (leftAddend: Double, rightAddend: Double) -> Double { | |
fatalError() | |
} |
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 <XCTest/XCTest.h> | |
@interface ThreadNotSafetyTests : XCTestCase | |
// no crash | |
//@property (atomic) NSObject *obj; | |
// crash | |
@property (nonatomic) NSObject *obj; | |
@end |
OlderNewer