iT邦幫忙

2025 iThome 鐵人賽

DAY 4
0

Day 4 - 調色盤實作(建立 MVC 架構與 MainViewController)

昨天介紹完 MVC 架構Code Style,今天我們要正式開始進行實作,先建立專案的檔案結構,並準備主畫面控制器。


建立 MVC 架構資料夾

首先,到左邊的專案資料夾,對專案名稱點擊右鍵,選擇 New Group
建立我們昨天提到的三層架構:M (Model)C (Controller)V (View)

https://ithelp.ithome.com.tw/upload/images/20250918/20178625cmSKcX7zv0.png


建立 Controller

建立完成後,對 C (Controller) 資料夾右鍵,選擇 New File

https://ithelp.ithome.com.tw/upload/images/20250918/201786254IWSXZDuYq.jpg

接著點選 Cocoa Touch Class
https://ithelp.ithome.com.tw/upload/images/20250918/20178625W6sx14foOy.png

由於這個 Class 是專案的主界面,所以命名為 MainViewController
同時記得勾選 Also create XIB file
如果沒有勾選的話,就只會產生程式碼檔案,而沒有可視化的 XIB 介面 可以搭配使用。

https://ithelp.ithome.com.tw/upload/images/20250918/201786257hAms4N6Ft.png


完成的檔案結構

到這裡,我們的檔案結構就會長得像這樣:

https://ithelp.ithome.com.tw/upload/images/20250918/20178625QT0KGd3boZ.png


結語

今天我們完成了 MVC 架構資料夾建立,以及 MainViewController 的初始化
明天的內容將會進一步教大家 如何在 XIB 上建立元件,並加上 Auto Layout 約束,讓畫面更有結構。


上一篇
Day3 介紹MVC 架構與 Code Style
下一篇
Day 5 - 調色盤實作(XIB 介面建立與元件擺放)
系列文
我將成為Swift之強者5
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言