[問題] 加入檔案的問題
Programming in Objective-C, 5th, page 405
書上說把TXT檔拉到Xcode的左邊來加入檔案
在跳出的畫面中選複製檔案到專案資料夾
然後用下面的程式碼顯示TXT內容
NSString *txtFilePath = [[NSBundle mainBundle]
pathForResource: @"instructions"
ofType: @"txt"];
NSString *instructions = [NSString
stringWithCotentsOfFile: txtFilePath
encoding: NSUTF8Encoding
error: NULL];
我發現檔案有被加到放.xcodeproj的那個資料夾
但是txtFilePath和instructions跑出來都是(null)
我把檔案加到mainBundle顯示的那個位置就可以
/Users/Jason/Library/Developer/Xcode/DerivedData/
xxxxxxxxx/Build/Products/Debug/instructions.txt
是因為我的專案是Command Line Tool的關係嗎?
我上網查好像是要複製到Resource資料夾
不過Command Line Tool好像沒這個東西
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 211.76.64.223
※ 編輯: ishuen 來自: 211.76.64.223 (01/29 16:05)
→
01/29 16:31, , 1F
01/29 16:31, 1F
→
01/29 16:32, , 2F
01/29 16:32, 2F
→
01/29 16:33, , 3F
01/29 16:33, 3F
→
01/29 16:33, , 4F
01/29 16:33, 4F
→
01/29 16:35, , 5F
01/29 16:35, 5F
→
01/29 16:35, , 6F
01/29 16:35, 6F
→
01/30 21:47, , 7F
01/30 21:47, 7F