Posts

Showing posts from August, 2016

NSOperation和NSOperationQueue

NSOperation和NSOperationQueue NSOperation和NSOperationQueue NSOperation 是 GCD 的封裝,是完全的物件導向類別,所以使用起來更簡單。 大家可以看到 NSOperation 和 NSOperationQueue 分别對照 GCD 的 Task 和 Queue 。 將要執行的任務封装到一個 NSOperation 物件中。 將此task添加到 NSOperationQueue 物件中。 然後系統就會自動執行任務。至於是同步還是異步、串行還是並行繼續往下看: 加入Task NSOperation 只是一個抽象類別。 抽象類別是不能產生實體的類別,所以不能封裝task。 但有 2 個子類別是可以用封裝任務。 分别是:NSInvocationOperation 和 NSBlockOperation 。 建立一個 Operation 後,需要使用 start 方法啟用task,他會在當前的序列進行同步執行。而且也可以取消任務,只需要使用 cancel 方法即可。 NSInvocationOperation : 需要傳入一個方法。 OBJECTIVE-C //1.建立NSInvocationOperation物件 NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget: self selector :@ selector (run) object: nil ]; //2.開始執行 [operation start]; //SWIFT 在 Swift ,蘋果認為 NSInvocationOperation 這種不是安全的類別。 As of Xcode 6.1, NSInvocation is disabled in Swift, therefore, NSInvocationOperation is disabled too. See this thread in Developer Forum Because it’s not type-safe or ARC-safe. Even

IOS GCD多執行緒

IOS GCD多執行緒 GCD 簡稱 Grand Central Dispatch ,利用在CPU(雙核,多核心的平行運算), 自動管理Thread的Liftcycle ,(創造執行緒,調度Task,消除執行緒),不用自己管理Thread。 GCD Objectivc-C 使用Block Swift 使用Closure Task & Queue Task: Operation ,一個程式區段,在GCD裡面就是Block或者Closure 有兩種操作模式: sync & async 差別在於是否創造 “新的Thread” 同步執行 同步操作會阻礙當前執行緒執行並等待,等當前執行緒完成才繼續執行 異步執行 異步操作,當前執行緒會繼續往下執行,不會阻礙執行緒 Queue Serial Queues(串行序列) 會進行FIFO(First in First out) Concurrent Queues(並行序列) 也是FIFO取出,但取出後會開啟多條執行緒直接取出又放到另外一個執行緒,由於取出動作很快,看起來所有任務同時執行,但是自根據系統資源控制並行數量,所以如果任務很多,不會同時讓任務一起執行。 Item sync async Serial Queues 執行緒,一個一個執行 其他執行緒,一個一個執行 Concurrent Queues 執行緒,一個一個執行 很多執行緒,同時執行 創造Queue Main Queue Create Queue Global Queue Main Queue mainqueue為自定義變數 /*OBJECTIVE-C*/ dispatch_queue_t mainqueue = dispatch_get_main_queue(); /*SWIFT*/ let mainqueue = dispatch_get_main_queue() Create Your Own Queue 自己可以創建串

HTML複習

HTML複習 Html hyper text markup language 標準定義單位 http://www.w3.org 基本網頁運行環境介紹 http://feevocode.blogspot.com/2016/04/ap102-2016413.html html4 與html5 標準範本下載 https://github.com/DarisCode/HTML/tree/master/html Tag A pair Tag <h1>This is h1<h1/> single Tag - <br> <br/> free-formate : Html不會受大小寫影響 Attribute 屬性 < a href= "" > //href 是 a 標籤的屬性 "" 內的值是屬性 html 4.01版的重點 text & pr 3 -