ios - coredata和sqlite如何同步?
问题描述
我正在制作一个需要单击按钮(true or false alarm
)的应用程序,然后将单击哪个按钮、单击日期附加到UITableView
. 所有这些信息当前都存储在 coredata 中,我想将 table/coredata 中的数据上传到 sqlite。然后我想将此表上传到数据库,以便它可以用于其他事情。
我试过使用JSONSerialization
,但我不确定它是如何工作的。我想json
通过按钮视图将文件发送到数据库,但我无法提供UIButton
此功能。
对于按钮输入,
@IBAction func addAlarm(_ sender: UIButton){
let trueFalseAlarm = Alarm(context: moc)
trueFalseAlarm.added = Date()
if sender.tag == 0{
trueFalseAlarm.trueFalse = "0""
}else if sender.tag == 1{
trueFalseAlarm.trueFalse = "1"
}
}
表视图:
func tableView (_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(with Identifier: "Cell", for: indexPath)
let trueFalseAlarm = alarmItems[indexPath.row]
let trueFalse = trueFalseAlarm.trueFalse
cell.deatailTextLabel?.text = trueFalse
let alarmDate = trueFalseAlarm.added as! Date
let dateFormatter = DateFormatter()
date Formatter.dateFormat = "d MMMM yyyy, hh:mm"
cell.detailTextLabel?.text = dateFormatter.string(from: alarmDate)
该表可以工作,但现在问题是在某个时间点获取表的一个实例,并将在 UITableView 中使用的数组发送到数据库中。该数组当前如下所示:
警报项:[(实体:警报;ID:_____;数据:{添加 =“2019-05-24 02:17:51 +0000”;trueFalse = 0;}),...]
tableview 中的数据存储在 coredata 中。是否可以从 coredata 上传/同步数据并将其也包含在 sqlite 中?我需要的只是数据之后的一切。太感谢了。
解决方案
推荐阅读
- amazon-web-services - AWS Appsync 订阅 - “连接失败:连接握手错误”
- java - 无法设置程序流程以正确运行功能
- python - AttributeError:“SimpleImputer”对象在 PyCaret 中没有属性“_validate_data”
- python - Pandas Dataframe:如何创建另一列的增量唯一值计数列
- python - 删除行包含 Pandas 数据框中的非英语单词
- css - StoryBook React 钩子
- c# - C# - 桌面与服务器上的 Oracle 日期不同
- python - 如何从 jetson nano 获取 gps 数据?
- python - PyMacs 可以用来在 Emacs 窗口中显示图形吗?
- eclipse - Jaspersoft Studio 插件依赖问题