Skip to content

Instantly share code, notes, and snippets.

View JunyiXie's full-sized avatar
:octocat:
Focusing

xiejunyi JunyiXie

:octocat:
Focusing
View GitHub Profile
+ (instancetype)imageWithLightImageBlock:(UIImage *(^)(void))lightImageBlock
darkImageBlock:(UIImage *(^)(void))darkImageBlock
{
__block UIImage *image = nil;
if (@available(iOS 13.0, *)) {
UITraitCollection *const scaleTraitCollection = [UITraitCollection currentTraitCollection];
UITraitCollection *const lightUnscaledTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
@JunyiXie
JunyiXie / gist:08f3fd1d19d638e16c440d51f9c424a7
Created May 6, 2018 14:05 — forked from snikch/gist:3661188
Find the current top view controller for your iOS application
- (UIViewController *)topViewController{
return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController];
}
- (UIViewController *)topViewController:(UIViewController *)rootViewController
{
if (rootViewController.presentedViewController == nil) {
return rootViewController;
}
@JunyiXie
JunyiXie / gist:43619fcd3d31cc9e235211f5cc0c7736
Created May 6, 2018 06:43 — forked from chrisballinger/gist:3352890
Fuzzy string match objective-c (Levenshtein Distance Algorithm)
-(float)compareString:(NSString *)originalString withString:(NSString *)comparisonString
{
// Normalize strings
[originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[comparisonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
originalString = [originalString lowercaseString];
comparisonString = [comparisonString lowercaseString];
// Step 1 (Steps follow description at http://www.merriampark.com/ld.htm)

进程和线程的概念:

线程(英语:thread)是操作系统能够进行运算调度的最小单位。

进程(英语:process),是计算机中已运行程序的实体/进程是具有独立功能的程序在一个数据集合运行的过程,它是系统进行资源分配和调度的一个独立单位。

为什么引入进程和线程的概念

进程:更好的描述和控制程序的并发执行,实现操作系统的并发性和共享性。 线程:减少程序在并发执行是所付出的时空开销,提高操作系统的并发性能。

进程的特征