2014-03-07 61 views
1

我作出了可可的AppleScript OSX的应用程序在Xcode 5ArrayController的保存内容到文件

我有一个表视图,其使用阵列控制器与每个按钮按QuickTime文件的当前播放时间更新。所有工作正常,但我坚持如何将表视图的结果保存到文件,最好是.csv

我一直在试图研究如何做到这一点,但我发现大多数教程与iOS相关。 我已经使用NSStrings和writeToFile进行了研究,但在填充空白时遇到了问题。

如果有人可以给我一些指示或知道与此有关的教程,我将不胜感激。

由于

编辑:我曾尝试表视图的表内容,以在IB阵列控制器与FinalResults的键路径,然后在保存按钮发件人结合

FinalResult's writeToFile:FilePath 

文件路径是使用位置集合

set FilePath to choose folder 

这是成功建立,但是当我点击保存按钮它给我下面的错误

014-03-11 22:37:07.462 SMPTE抓取[4043:303] * - [AppDelegate的备份:]:无法识别的函数writeToFile_。 (错误-10000)

我是否需要以某种方式将表内容绑定到其他东西?

我已经在这,现在天..

感谢

+0

下一步:检出NSArray和它的writeToFile方法。 – 2014-03-07 04:30:02

+0

我是否需要让NSArray引用NSArrayController或表视图,是否会在IB的Bindings Inspector中完成? – benWin

回答

0

由于在Macscripter StefanK过来,他解决了我原来的问题,而我试图解决它在很回合的方式。 (他必须是一个心灵读者)

无论如何,我想我会与任何发现自己陷入类似困境的人分享它。

set filePath to POSIX path of (path to desktop) & "test.csv" -- sample path, change it something appropriate 
set theArray to arrayController's arrangedObjects() -- arrayController is a property connected to an NSArrayController instance 
set csvList to current application's NSMutableArray's array() 
csvList's addObject:((theArray's objectAtIndex:0)'s allKeys()'s componentsJoinedByString:",") 
repeat with anItem in theArray 
    (csvList's addObject:((anItem's allValues())'s componentsJoinedByString:",")) 
end repeat 
set csvText to (csvList's componentsJoinedByString:return) 
csvText's writeToFile:filePath atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)