我试图在swift中将数据保存到plist文件,但是数据没有显示,因为它在读取plist时保存了.这是我正在使用的代码.
var documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as NSString
var path : NSString = documentsDirectory.stringByAppendingPathComponent("data.plist")
var data : NSMutableDictionary = NSMutableDictionary(contentsOfFile: path)
data.setObject(self.object, forKey: "key")
data.writeToFile(path, atomically: true)
Run Code Online (Sandbox Code Playgroud)
编辑:我听说最好的方法是写入文档目录,所以我的问题是如何写入该目录中的文件?
我一直试图在Xcode 6中为swift应用程序添加一个unwind segue,并且在前三个beta版的发行说明中,它被声明为不受支持.但是,在Beta 4中,该错误说明不再存在.我听说人们能够让它上班,但我没有运气.所以,我的问题是:我应该如何尝试查看unwind segue是否可以在我的应用中运行?我该怎么办?我正在使用UIBarButtonItem来触发segue.
到目前为止,我已将此代码放在目标控制器的.swift文件中:
@IBAction func unwindToSegue(segue:UIStoryboardSegue) {}
Run Code Online (Sandbox Code Playgroud)
使用此代码,我可以通过控制从条形按钮拖动到退出图标,然后单击unwindToSegue方法将条形按钮连接到该功能.那个部分已经工作了,但代码没有运行,即使我在函数内部放置一个断点而没有调用它.
我试图以编程方式创建UIPickerView并将其显示为文本字段的firstResponder,但是,选择器视图未显示.textField连接到接口构建器中的对象,但是正在以编程方式创建pickerView.
class View: UIViewController {
@IBOutlet var picker : UIPickerView = UIPickerView.alloc()
@IBOutlet var textField : UITextField = nil
override func viewDidLoad() {
super.viewDidLoad()
picker = UIPickerView()
picker.delegate = self
picker.dataSource = self
picker.backgroundColor = UIColor.blackColor()
textField.inputView = picker
}
}
extension View: UIPickerViewDataSource {
func numberOfComponentsInPickerView(colorPicker: UIPickerView!) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -> Int {
return 5
}
}
extension View: UIPickerViewDelegate {
func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) …Run Code Online (Sandbox Code Playgroud)