如果一開始在 Xcode 建立專案時忘了勾選 Create Git repository on my Mac,專案將沒有 git 版本管理的功能。如上圖所示,左邊的 Source Control Navigator 分頁將顯示 no Git Repositories,無法將專案上傳到 GitHub。
當我們從 Xcode 建立新的專案時,它預設的格式是最新版本,換句話說,當我們用 Xcode 14 建立專案時,使用 Xcode 13 的朋友就算使盡吃奶的力氣也打不開,他會看到以下的錯誤訊息。
The project at xxx.xcodeproj cannot be opened because it is in a future Xcode project file format. Adjust the project format using a compatible…
大部分的時候,我們打開 Xcode 後,可從最近開啟過的專案打開專案,因此並不需要知道專案在 Mac 擺放的路徑。不過某些時候我們還是需要知道專案的路徑,如果忘了路徑位置,可參考以下方法:
1 點選 Project navigator 裡的專案檔。
最近在看 iOS App 開發教學影片時,發現範例裡有個初學者容易看不懂的寫法,程式如下:
let isInputValid = textField.text?.count ?? 0 > 0
它使用了 ??,Nil-Coalescing 的技巧。利用它,程式將判斷 optional 是否有值,如果有的話將讀取 optional 的內容,無值的話將使用 ?? 後的值。
當我們在 Xcode 寫程式時,長方形的提示輸入框提醒我們要填入東西,不過如果你仔細看,將發現它有兩種不同的呈現呢。
第一種: 長方形的提示文字只有參數型別。
我們呼叫 function 時,需要保留參數名字和冒號。
func eat(name: String) {}eat(name: "牛排")
iOS SDK 裡有許多 protocol 的 function 都是 optional,代表我們在遵從 protocol 時不一定要定義它,比方 protocol UITableViewDelegate 的 tableView(_:didSelectRowAt:)。
optional func tableView(_ tableView: UITableView, didSelectRowAt indexPath…
GitHub 上有許多精彩的 Swift iOS App…
Xcode 很貼心,它在我們撰寫 App 程式時會自動 build,生成 App,一旦發現問題,馬上在相關的程式顯示紅色錯誤或黃色警告。
但是,它偶爾也會失靈,明明我們已經修正錯誤,它卻還念念不忘我們從前犯下的錯誤,例如以下例子:
原本我們輸入以下程式,造成錯誤。
These were the top 10 stories published by 彼得潘的 Swift iOS App 開發問題解答集 in May of 2018. You can also dive into daily archives for May of 2018 by using the calendar at the top of this page.