移動開發在路上 IOS移動開發系列 多執行緒一

2022-07-02 23:27:09 字數 2483 閱讀 4852

類似於什麼是程序什麼是執行緒在這裡我就不多浪費時間了(google一下什麼都有)!

廢話不多說先上圖,我相信大家都是喜歡看圖的人,俗話說得好,求圖求真相嗎?雖然這裡只有屌絲乙個但是真相還是會有的。。。

碼農的eq有限,所以既沒有太多煽情的部分了

在obj-c中線程的建立與啟動

首先說一下oc中有幾種多執行緒的方式

//建立多執行緒物件一

nsthread *thread=[[nsthread

alloc] initwithtarget:self

selector:@selector(childthread:) object:@"

子執行緒"];

//開始執行多執行緒

[thread start];

//建立多執行緒物件二

[nsthreaddetachnewthreadselector:

@selector

(childthread:) totarget:

selfwithobject:

@"子執行緒"];

//建立多執行緒物件三

[selfperformselectorinbackground:

@selector

(childthread:) withobject:

@"子執行緒"];

//建立多執行緒物件四

nsoperationqueue *threadqueue = [[nsoperationqueue alloc] init];

[threadqueue addoperationwithblock:^(void)

}}];//建立多執行緒物件五

//建立乙個執行緒佇列

nsoperationqueue *operationqueue = [[nsoperationqueue alloc] init];

//同時執行的併發數

operationqueue.maxconcurrentoperationcount = 1;

//建立乙個執行緒物件

nsinvocationoperation *operation1 = [[nsinvocationoperation alloc] initwithtarget:self selector:@selector(childthread:) object:@"子執行緒"];

//建立乙個執行緒物件

nsinvocationoperation *operation2 = [[nsinvocationoperation alloc] initwithtarget:self selector:@selector(childthread2:) object:@"子執行緒2"];

//設定優先順序

operation2.queuepriority = nsoperationqueuepriorityhigh;

[operationqueue addoperation:operation1];

[operationqueue addoperation:operation2];

//建立多執行緒物件六

dispatch_queue_t

queueq=dispatch_queue_create(

"test"

, null

);dispatch_async(queueq, ^

dispatch_sync

(dispatch_get_main_queue(), ^

});});

先建立乙個專案

我這裡xcode版本是5.0.2

建立乙個新專案

下一步

點選 建立

到這裡我們這個專案就算建立好了。

開始 coding 

選擇這個.m檔案

又補充了一下子

到這裡先告一段落

持續更新中...

那裡有不對的請多提意見,互相學習!

出處:

移動開發在路上 IOS移動開發系列 多執行緒三

這一次說一點概念性的東西,也是為後邊做一些基礎 http協議的基本概念 http協議的基本概念 全稱 超文字傳輸協議 瀏覽器和伺服器之間的通訊規則 http協議永遠都是客戶端發起的請求,伺服器回送響應 請求 客戶端 伺服器 server 響應 客戶端 需要什麼資料的時間 根據使用者的操作,作出相應的...

移動開發必備

工具 1.alcatraz 是xcode的plugin管理器,想要什麼自己來吧。如inject plugin,cocoapods 2.xctool 3.nomad 5.sourcetree git 6.cornerstone svn 7.diffmerge 8.charles 來著的 9.cocoa...

移動前端開發

去掉輸入url控制項條 window.onload function script html,body body a,img mdn 手機網頁開發 mdn 在移動瀏覽器中使用viewport元標籤控制布局 移動前端開發和 web 前端開發的區別是什麼 移動前端端開發的入門理論 alloyteam移動...