diff --git a/RunloopAndThread/RunloopAndThread.xcodeproj/project.pbxproj b/RunloopAndThread/RunloopAndThread.xcodeproj/project.pbxproj deleted file mode 100644 index 2b68ea4..0000000 --- a/RunloopAndThread/RunloopAndThread.xcodeproj/project.pbxproj +++ /dev/null @@ -1,308 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 9BAA82A81D451A0E00E5B98A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BAA82A71D451A0E00E5B98A /* main.m */; }; - 9BAA82AB1D451A0E00E5B98A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BAA82AA1D451A0E00E5B98A /* AppDelegate.m */; }; - 9BAA82AE1D451A0E00E5B98A /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 9BAA82AD1D451A0E00E5B98A /* ViewController.m */; }; - 9BAA82B11D451A0E00E5B98A /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9BAA82AF1D451A0E00E5B98A /* Main.storyboard */; }; - 9BAA82B31D451A0E00E5B98A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9BAA82B21D451A0E00E5B98A /* Assets.xcassets */; }; - 9BAA82B61D451A0E00E5B98A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9BAA82B41D451A0E00E5B98A /* LaunchScreen.storyboard */; }; -/* End PBXBuildFile section */ - -/* Begin PBXFileReference section */ - 9BAA82A31D451A0E00E5B98A /* RunloopAndThread.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RunloopAndThread.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 9BAA82A71D451A0E00E5B98A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; - 9BAA82A91D451A0E00E5B98A /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; - 9BAA82AA1D451A0E00E5B98A /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 9BAA82AC1D451A0E00E5B98A /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 9BAA82AD1D451A0E00E5B98A /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; - 9BAA82B01D451A0E00E5B98A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; - 9BAA82B21D451A0E00E5B98A /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 9BAA82B51D451A0E00E5B98A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 9BAA82B71D451A0E00E5B98A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 9BAA82A01D451A0E00E5B98A /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 9BAA829A1D451A0E00E5B98A = { - isa = PBXGroup; - children = ( - 9BAA82A51D451A0E00E5B98A /* RunloopAndThread */, - 9BAA82A41D451A0E00E5B98A /* Products */, - ); - sourceTree = ""; - }; - 9BAA82A41D451A0E00E5B98A /* Products */ = { - isa = PBXGroup; - children = ( - 9BAA82A31D451A0E00E5B98A /* RunloopAndThread.app */, - ); - name = Products; - sourceTree = ""; - }; - 9BAA82A51D451A0E00E5B98A /* RunloopAndThread */ = { - isa = PBXGroup; - children = ( - 9BAA82A91D451A0E00E5B98A /* AppDelegate.h */, - 9BAA82AA1D451A0E00E5B98A /* AppDelegate.m */, - 9BAA82AC1D451A0E00E5B98A /* ViewController.h */, - 9BAA82AD1D451A0E00E5B98A /* ViewController.m */, - 9BAA82AF1D451A0E00E5B98A /* Main.storyboard */, - 9BAA82B21D451A0E00E5B98A /* Assets.xcassets */, - 9BAA82B41D451A0E00E5B98A /* LaunchScreen.storyboard */, - 9BAA82B71D451A0E00E5B98A /* Info.plist */, - 9BAA82A61D451A0E00E5B98A /* Supporting Files */, - ); - path = RunloopAndThread; - sourceTree = ""; - }; - 9BAA82A61D451A0E00E5B98A /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 9BAA82A71D451A0E00E5B98A /* main.m */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 9BAA82A21D451A0E00E5B98A /* RunloopAndThread */ = { - isa = PBXNativeTarget; - buildConfigurationList = 9BAA82BA1D451A0E00E5B98A /* Build configuration list for PBXNativeTarget "RunloopAndThread" */; - buildPhases = ( - 9BAA829F1D451A0E00E5B98A /* Sources */, - 9BAA82A01D451A0E00E5B98A /* Frameworks */, - 9BAA82A11D451A0E00E5B98A /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = RunloopAndThread; - productName = RunloopAndThread; - productReference = 9BAA82A31D451A0E00E5B98A /* RunloopAndThread.app */; - productType = "com.apple.product-type.application"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 9BAA829B1D451A0E00E5B98A /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0730; - ORGANIZATIONNAME = bestswifter; - TargetAttributes = { - 9BAA82A21D451A0E00E5B98A = { - CreatedOnToolsVersion = 7.3.1; - DevelopmentTeam = U2HX3RFD94; - }; - }; - }; - buildConfigurationList = 9BAA829E1D451A0E00E5B98A /* Build configuration list for PBXProject "RunloopAndThread" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - Base, - ); - mainGroup = 9BAA829A1D451A0E00E5B98A; - productRefGroup = 9BAA82A41D451A0E00E5B98A /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 9BAA82A21D451A0E00E5B98A /* RunloopAndThread */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXResourcesBuildPhase section */ - 9BAA82A11D451A0E00E5B98A /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 9BAA82B61D451A0E00E5B98A /* LaunchScreen.storyboard in Resources */, - 9BAA82B31D451A0E00E5B98A /* Assets.xcassets in Resources */, - 9BAA82B11D451A0E00E5B98A /* Main.storyboard in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXResourcesBuildPhase section */ - -/* Begin PBXSourcesBuildPhase section */ - 9BAA829F1D451A0E00E5B98A /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 9BAA82AE1D451A0E00E5B98A /* ViewController.m in Sources */, - 9BAA82AB1D451A0E00E5B98A /* AppDelegate.m in Sources */, - 9BAA82A81D451A0E00E5B98A /* main.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin PBXVariantGroup section */ - 9BAA82AF1D451A0E00E5B98A /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 9BAA82B01D451A0E00E5B98A /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; - 9BAA82B41D451A0E00E5B98A /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 9BAA82B51D451A0E00E5B98A /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - -/* Begin XCBuildConfiguration section */ - 9BAA82B81D451A0E00E5B98A /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 9BAA82B91D451A0E00E5B98A /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_ANALYZER_NONNULL = YES; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 9BAA82BB1D451A0E00E5B98A /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - INFOPLIST_FILE = RunloopAndThread/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = baidu.RunloopAndThread; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 9BAA82BC1D451A0E00E5B98A /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - INFOPLIST_FILE = RunloopAndThread/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = baidu.RunloopAndThread; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 9BAA829E1D451A0E00E5B98A /* Build configuration list for PBXProject "RunloopAndThread" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 9BAA82B81D451A0E00E5B98A /* Debug */, - 9BAA82B91D451A0E00E5B98A /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 9BAA82BA1D451A0E00E5B98A /* Build configuration list for PBXNativeTarget "RunloopAndThread" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 9BAA82BB1D451A0E00E5B98A /* Debug */, - 9BAA82BC1D451A0E00E5B98A /* Release */, - ); - defaultConfigurationIsVisible = 0; - }; -/* End XCConfigurationList section */ - }; - rootObject = 9BAA829B1D451A0E00E5B98A /* Project object */; -} diff --git a/RunloopAndThread/RunloopAndThread/AppDelegate.h b/RunloopAndThread/RunloopAndThread/AppDelegate.h deleted file mode 100644 index fe7f9b2..0000000 --- a/RunloopAndThread/RunloopAndThread/AppDelegate.h +++ /dev/null @@ -1,17 +0,0 @@ -// -// AppDelegate.h -// RunloopAndThread -// -// Created by 张星宇 on 16/7/24. -// Copyright © 2016年 bestswifter. All rights reserved. -// - -#import - -@interface AppDelegate : UIResponder - -@property (strong, nonatomic) UIWindow *window; - - -@end - diff --git a/RunloopAndThread/RunloopAndThread/AppDelegate.m b/RunloopAndThread/RunloopAndThread/AppDelegate.m deleted file mode 100644 index abb96e3..0000000 --- a/RunloopAndThread/RunloopAndThread/AppDelegate.m +++ /dev/null @@ -1,45 +0,0 @@ -// -// AppDelegate.m -// RunloopAndThread -// -// Created by 张星宇 on 16/7/24. -// Copyright © 2016年 bestswifter. All rights reserved. -// - -#import "AppDelegate.h" - -@interface AppDelegate () - -@end - -@implementation AppDelegate - - -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - // Override point for customization after application launch. - return YES; -} - -- (void)applicationWillResignActive:(UIApplication *)application { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. -} - -- (void)applicationDidEnterBackground:(UIApplication *)application { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. -} - -- (void)applicationWillEnterForeground:(UIApplication *)application { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. -} - -- (void)applicationDidBecomeActive:(UIApplication *)application { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. -} - -- (void)applicationWillTerminate:(UIApplication *)application { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. -} - -@end diff --git a/RunloopAndThread/RunloopAndThread/Assets.xcassets/AppIcon.appiconset/Contents.json b/RunloopAndThread/RunloopAndThread/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 118c98f..0000000 --- a/RunloopAndThread/RunloopAndThread/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/RunloopAndThread/RunloopAndThread/Base.lproj/LaunchScreen.storyboard b/RunloopAndThread/RunloopAndThread/Base.lproj/LaunchScreen.storyboard deleted file mode 100644 index 2e721e1..0000000 --- a/RunloopAndThread/RunloopAndThread/Base.lproj/LaunchScreen.storyboard +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RunloopAndThread/RunloopAndThread/Base.lproj/Main.storyboard b/RunloopAndThread/RunloopAndThread/Base.lproj/Main.storyboard deleted file mode 100644 index f56d2f3..0000000 --- a/RunloopAndThread/RunloopAndThread/Base.lproj/Main.storyboard +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/RunloopAndThread/RunloopAndThread/Info.plist b/RunloopAndThread/RunloopAndThread/Info.plist deleted file mode 100644 index 6905cc6..0000000 --- a/RunloopAndThread/RunloopAndThread/Info.plist +++ /dev/null @@ -1,40 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - - diff --git a/RunloopAndThread/RunloopAndThread/ViewController.h b/RunloopAndThread/RunloopAndThread/ViewController.h deleted file mode 100644 index 52f0228..0000000 --- a/RunloopAndThread/RunloopAndThread/ViewController.h +++ /dev/null @@ -1,15 +0,0 @@ -// -// ViewController.h -// RunloopAndThread -// -// Created by 张星宇 on 16/7/24. -// Copyright © 2016年 bestswifter. All rights reserved. -// - -#import - -@interface ViewController : UIViewController - - -@end - diff --git a/RunloopAndThread/RunloopAndThread/ViewController.m b/RunloopAndThread/RunloopAndThread/ViewController.m deleted file mode 100644 index c3d8721..0000000 --- a/RunloopAndThread/RunloopAndThread/ViewController.m +++ /dev/null @@ -1,105 +0,0 @@ -// -// ViewController.m -// RunloopAndThread -// -// Created by 张星宇 on 16/7/24. -// Copyright © 2016年 bestswifter. All rights reserved. -// - -#import "ViewController.h" - -@interface ViewController () - -@property (strong, nonatomic) NSPort *emptyPort; -@property (strong, nonatomic) NSThread *thread; -@property (assign, nonatomic) BOOL shouldKeepRunning; - -@end - -@implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; -// [self memoryTest]; -// [self runloopTest]; -} - -#pragma --mark 内存占用测试 -- (void)memoryTest { - for (int i = 0; i < 100000; ++i) { - NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(run) object:nil]; - [thread start]; - [self performSelector:@selector(stopThread) onThread:thread withObject:nil waitUntilDone:YES]; - } -} - -- (void)stopThread { - CFRunLoopStop(CFRunLoopGetCurrent()); - NSThread *thread = [NSThread currentThread]; - [thread cancel]; -} - -- (void)run { - @autoreleasepool { - NSLog(@"current thread = %@", [NSThread currentThread]); - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - if (!self.emptyPort) { - self.emptyPort = [NSMachPort port]; - } - [runLoop addPort:self.emptyPort forMode:NSDefaultRunLoopMode]; - // 下面这两种写法都不可取 -// [runLoop run]; -// [runLoop runMode:NSRunLoopCommonModes beforeDate:[NSDate distantFuture]]; - CFRunLoopRun(); - } -} - -# pragma --mark runloop 启动与退出测试 -- (void)runloopTest { - // 绘制按钮,点击按钮后关闭 runloop - UIButton *stopButton = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; - [stopButton setTitle:@"Stop Timer" forState:UIControlStateNormal]; - [stopButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; - [self.view addSubview:stopButton]; - [stopButton addTarget:self action:@selector(stopButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside]; - -// self.shouldKeepRunning = YES; - - self.thread = [[NSThread alloc] initWithTarget:self selector:@selector(singleThread) object:nil]; - [self.thread start]; - [self performSelector:@selector(printSomething) onThread:self.thread withObject:nil waitUntilDone:YES]; -} - -- (void)singleThread { - @autoreleasepool { - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - if (!self.emptyPort) { - self.emptyPort = [NSMachPort port]; - } - [runLoop addPort:self.emptyPort forMode:NSDefaultRunLoopMode]; - CFRunLoopRun(); -// while (_shouldKeepRunning && [runLoop runMode:NSRunLoopCommonModes beforeDate:[NSDate distantFuture]]); - } -} - -- (void)printSomething { - NSLog(@"current thread = %@", [NSThread currentThread]); - [self performSelector:@selector(printSomething) withObject:nil afterDelay:1]; -} - -#pragma --mark 点击按钮退出 -- (void)stopButtonDidClicked:(id)sender { - [self performSelector:@selector(stopRunloop) onThread:self.thread withObject:nil waitUntilDone:YES]; -} - -- (void)stopRunloop { - // self.shouldKeepRunning = NO; - CFRunLoopStop(CFRunLoopGetCurrent()); -} - -- (void)didReceiveMemoryWarning { - [super didReceiveMemoryWarning]; - // Dispose of any resources that can be recreated. -} - -@end diff --git a/RunloopAndThread/RunloopAndThread/main.m b/RunloopAndThread/RunloopAndThread/main.m deleted file mode 100644 index 69bcf1c..0000000 --- a/RunloopAndThread/RunloopAndThread/main.m +++ /dev/null @@ -1,16 +0,0 @@ -// -// main.m -// RunloopAndThread -// -// Created by 张星宇 on 16/7/24. -// Copyright © 2016年 bestswifter. All rights reserved. -// - -#import -#import "AppDelegate.h" - -int main(int argc, char * argv[]) { - @autoreleasepool { - return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); - } -}