在 iOS 專案中,pathForResource 回傳 nil 通常代表檔案未被正確複製進 App Bundle。請依序檢查:
Show in Finder,確認檔案實際存在於專案目錄。若上述方法皆無效,建議建立新的空白專案,將程式碼、資源逐步遷移。這能確保 Build Settings、Bundle 結構皆為預設狀態,避免隱藏設定污染。
// 正確讀取 main bundle 中的 plist
if let path = Bundle.main.path(forResource: "Config", ofType: "plist"),
let dict = NSDictionary(contentsOfFile: path) as? [String: Any] {
// 使用 dict
}