mac應用開發入門筆記


第一天

今天是我學習mac應用開發的第一天,我的目標是開發一個可以打印Hello World的mac應用程序。
學習網址:https://www.raywenderlich.com/731-macos-development-for-beginners-part-1
參考:https://blog.csdn.net/lovechris00/article/details/72779076
環境准備:
1.一台運行着mac os的電腦
2.Xcode作為IDE


打開xcode,新建一個xcode項目,選擇mac os,選擇Cocoa App,點擊Next
在這里插入圖片描述
設置名稱,選擇語言,點擊Next
在這里插入圖片描述
此時xcode已經為開發者創建了基礎模版
在這里插入圖片描述

運行APP

可以直接通過command + R 運行這個項目,會彈出一個空白窗口
在這里插入圖片描述

xcode界面簡介

主要分了三個區域,導航區,編輯區,功能區
在這里插入圖片描述

添加UI元素

通過Storyboard進行界面的設置,點擊 Main.storyboard 在編輯區查看
在這里插入圖片描述

第二天

這里有三個區域

  • Application Scene: The menu bar and items.
  • Window Controller Scene: Configures how the window will behave.
  • View Controller Scene: Where your UI elements will go.
    在這里插入圖片描述
    從ui庫里取出你想要使用的ui元素
    在這里插入圖片描述
    配置ui元素,在Utilities panel里面可以去配置ui元素顏色,字體等格式
    在這里插入圖片描述
    把ui元素和代碼關聯起來Connecting the UI to the code
    在打開storyboard的時候,Option + 點擊代碼,可以把代碼放到storyboard的旁邊

按住control,拖動ui元素,讓ui元素和代碼建立聯系
在這里插入圖片描述
再把點擊動作和函數進行關聯
在這里插入圖片描述
獲取幫助
在這里插入圖片描述
Option-clicking is often a really good way to learn, and you can even add documentation to your own functions so that it shows up in the same way.
在這里插入圖片描述
開發出的mac應用如下,丑雖然丑了點,不過確實出來了
在這里插入圖片描述

第三天

第三題已經不是物理上的第三天了,而是邏輯上的第三天

效果圖在這里插入圖片描述
Connecting the UI to the code【怎么才能把ui和代碼連接起來呢】
@IBOutlets and @IBActions to connect your UI to your code.
在這里插入圖片描述
在這里插入圖片描述

添加菜單
在這里插入圖片描述

第四天

這里插入swift函數的概念,比其他我熟悉的語言多了個label的概念
Function Argument Labels and Parameter Names
func someFunction(argumentLabel parameterName: Int) {
    // In the function body, parameterName refers to the argument value
    // for that parameter.
}
參數標簽在調用函 數的時候使用;

今天我打算把菜單和菜單的快捷鍵給搞定
在這里插入圖片描述
菜單和函數進行關聯的方法
在這里插入圖片描述
First Responder是什么?

添加偏好窗口Preferences Window
添加代碼

在打開storyboard的時候,Option + 點擊代碼,可以把代碼放到storyboard的旁邊

我卡住了,在把新加的偏好窗口和偏好代碼關聯的時候遇到了問題,重新試了幾下又好了。。。
@IBOutlet
@IBAction

第五天

我打算今天把這部分教程也完成
https://www.raywenderlich.com/729-macos-development-for-beginners-part-3
Sandboxing
A sandboxed app has its own space to work in with separate file storage areas, no access to the files created by other apps and limited access and permissions. For iOS apps, this is the only way to operate. For macOS apps, this is optional; however, if you want to distribute your apps through the Mac App Store, they must be sandboxed. As a general rule, you should sandbox your apps, as this gives your apps less potential to cause problems.
在繼續往下學習之前,我想看看swift怎么發送http網路請求?
又卡住了,發送個http請求竟然這么難?需要配置網絡請求權限

開啟沙盒app的方法,project->target->capabilities->app sandbox 在這里面可以申請想要的權限。如果我先學沙盒再去嘗試網絡,可能就不需要被卡住那么久了。
網絡
硬件:相機,麥克風,USB, 打印機,藍牙
應用數據:聯系人,位置,日歷
文件訪問
在這里插入圖片描述

Organizing Your Files
看看你的項目結構,目前並沒有任何特別的組織規划,因為這個app很簡單,想象一下在大型工程中,一定要組織好你的代碼

MVC
mvc模式不僅在服務端使用,在前端同樣使用


寫到這里我有些困了,睡覺2019年 7月11日 星期四 00時08分27秒 CST


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM