天天看點

[第2章]多線程:NSThread簡介一、說明二、方法三、自定義線程

一、說明

操作的是線程,不是封裝好的隊列或隊列;适用于長時間一直使用的子線程。

二、方法

1、睡眠

// 1、睡到指定時間。
class func sleepUntilDate(date: NSDate)

// 2、跟sleep()一樣(PS:typealias NSTimeInterval = Double) 
class func sleepForTimeInterval(ti: NSTimeInterval)
           

2、線程運作Selector

NSThread.detachNewThreadSelector("run", toTarget: self, withObject: nil)

func run() {
    sleep()
    NSLog("thread")
}
           

3、獲得目前線程

NSThread.currentThread()
           
[第2章]多線程:NSThread簡介一、說明二、方法三、自定義線程

三、自定義線程

[第2章]多線程:NSThread簡介一、說明二、方法三、自定義線程