[TOC]
NSThread
Api
参见api文档
/****多线程* ***** ***** ***** ***** ***** *****/
@interface NSThread : NSObject
# Creating
- (instancetype)init;
- (instancetype)initWithTarget:(id)target selector:(SEL)selector object:(nullable id)argument; //创建线程
- (instancetype)initWithBlock:(void (^)(void))block API_AVAILABLE(ios(10.0));
+ (void)detachNewThreadSelector:(SEL)selector toTarget:(id)target withObject:(nullable id)argument; //创建线程并启动
+ (void)detachNewThreadWithBlock:(void (^)(void))block API_AVAILABLE(ios(10.0));
//Setting
@property (readonly, retain) NSMutableDictionary *threadDictionary;
@property (nullable, copy) NSString *name ;
@property NSUInteger stackSize ; //in bytes.This value must be in bytes and a multiple of 4KB.
+ (double)threadPriority; //a floating point number from 0.0 to 1.0, where 1.0 is highest priority.
+ (BOOL)setThreadPriority:(double)p;
@property double threadPriority; // To be deprecated; use qualityOfService below
@property NSQualityOfService qualityOfService //(iOS8_0); // read-only after the thread is started
//Starting a thread
- (void)start;
- (void)main; // thread body method 线程的执行体方法 用于子类重写 If you subclass NSThread, you can override this method and use it to implement the main body of your thread instead. If you do so, you do not need to invoke super.
You should never invoke this method directly. You should always start your thread by invoking the start method.
//Stoping a thread
+ (void)sleepUntilDate:(NSDate *)date;
+ (void)sleepForTimeInterval:(NSTimeInterval)ti;
+ (void)exit;
- (void)cancel;
@property (readonly, getter=isExecuting) BOOL executing ;
@property (readonly, getter=isFinished) BOOL finished ;
@property (readonly, getter=isCancelled) BOOL cancelled ;
@property (class, readonly, strong) NSThread *currentThread;
@property (class, readonly, strong) NSThread *mainThread ;
@property (readonly) BOOL isMainThread ;
@property (class, readonly) BOOL isMainThread ;
@property (class, readonly, copy) NSArray<NSNumber *> *callStackReturnAddresses ;
@property (class, readonly, copy) NSArray<NSString *> *callStackSymbols;
+ (BOOL)isMultiThreaded;
@end
//通知
FOUNDATION_EXPORT NSNotificationName const NSWillBecomeMultiThreadedNotification;
FOUNDATION_EXPORT NSNotificationName const NSDidBecomeSingleThreadedNotification;
FOUNDATION_EXPORT NSNotificationName const NSThreadWillExitNotification;
////*****/////
@interface NSObject (NSThreadPerformAdditions)
// equivalent to the first method with kCFRunLoopCommonModes
- (void)performSelectorInBackground:(SEL)aSelector withObject:(nullable id)arg ;
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(nullable id)arg waitUntilDone:(BOOL)wait modes:(nullable NSArray<NSString *> *)array;
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(nullable id)arg waitUntilDone:(BOOL)wait;
// equivalent to the first method with kCFRunLoopCommonModes
- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(nullable id)arg waitUntilDone:(BOOL)wait modes:(nullable NSArray<NSString *> *)array ;
- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(nullable id)arg waitUntilDone:(BOOL)wait ;
@end