- 使用ARC
- 延遲加載懶加載
- 重用在正確的地方使用reuseIndentifier
- 緩存NSCache 保存計算數據
- 處理內存警告移除對緩存,圖片object 和其他一些可以重創建的objects 的強引用
5.1 app delegate 中使用`applicationDidReceiveMemoryWarning:` 的方法
5.2 自定義UIViewController 的子類(subclass)中覆蓋`didReceiveMemoryWarning`
5.3在自定義類中註冊並接收UIApplicationDidReceiveMemoryWarningNotification 的通知 - 重用大開銷對象NSDateFormatter和NSCalendar 懶加載/單例_formatter.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy”; 設置和創建速度一樣慢
- 自動釋放池手動添加自動釋放池
- 是否緩存圖片imageNamed imageWithContentOfFile
- 混編
- 循環引用delegate block nstimer
- 移除kvo nsnotificationcenter 並未強引用,只記錄內存地址,野指針報
- UIViewController自動移除一般在dealloc中
- performselector 延遲操作[NSObject cancelPreviousPerformRequestsWithTarget:self]
📱 iOS開發 | 🔧 CI/CD | 💻 Xcode | 🐛 除錯筆記 🔴 問題描述 這兩天在跑 CI 時突然出現錯誤訊息: Package@swift-6.0.swift:PACKAGE-TARGET:CasePathsMacros: error: Target 'CasePathsMacros' must be enabled before it can be used 🤔 嘗試過的解法 💬 Claude 的建議 首先詢問了 Claude,得到以下步驟: 先更新 swift-case-paths 到最新版本 確保使用 "Up to Next Major Version" 執行 File → Packages → Reset Package Caches Clean Build Folder (Cmd + Shift + K) 重新 Build 結果: 一看就知道沒用 😅 🤖 ChatGPT 的建議 接著試了 ChatGPT 的解法,主要是降低引用到的 package 版本。繞了一圈,還是沒用。 ✅ 最終解決方案 最後還是回到 Google,找到了真正有效的解法。針對這個 macro fingerprint validation 問題,有三種解決方式: 📌 方法一:本機開發用(Terminal 指令) defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES 📌 方法二:xcodebuild 參數 在執行 xcodebuild 指令時,加上 -skipMacroValidation 參數 📚 參考連結: https://vocus.cc/article/690779ebfd89780001859b14 📌 方法三:CI 正統做法 ⭐️(推薦) 步驟 1: 在專案根目錄建立資料夾 ci_scripts 步驟 2: 在此資料夾中建立腳本 ci_post_clone.sh ,內容如下: #!/bin/zsh mkdir -p ~/Library/org.swift.swiftpm/security/ cp macros.js...
留言