目录 | Table of Contents

CloudKit开发手记——队列管理

目录 | Table of Contents

网上现在大部分的教程(包括苹果官方的CloudKit Quick Start)讲述的都是一种简易的方法(convience methods),我这里将要讲述的是如何有效使用队列进行数据库操作,使得操作更加有效规范可控。

 

队列的控制

如果你想要使用自己定义的NSOperationQueue的话,只需要在CKOperation指定上数据库就可以了

let container = CKContainer(identifier: "iCloud.me.masterchan.test0006")
let database = container.publicCloudDatabase

//获取数据
let fetchOperation = CKFetchRecordsOperation(recordIDs: [CKRecordID(recordName: "High School Fleet")])
fetchOperation.database = database
//......
let queue = NSOperationQueue()
queue.addOperation(fetchOperation)

 

另外,在一般情况下,其实可以直接使用database这个队列

let container = CKContainer(identifier: "iCloud.me.masterchan.test0006")
let database = container.publicCloudDatabase
//......
database.addOperation(fetchOperation)

 

当然,还能够添加依赖,确保操作按顺序执行

fetchUserRecordOperation.addDependency(fetchOperation)//可以通过添加依赖来决定执行顺序

 

 

操作的类型

  • CKFetchRecordChangesOperation
    • 检查Private Database中Zone的变化
  • CKFetchRecordZonesOperation
  • CKFetchRecordsOperation
    • 取得记录,private 或 public
  • CKFetchSubscriptionsOperation
    • 取得订阅
  • CKFetchWebAuthTokenOperation
    • 获取网页认证的Token
  • CKModifyRecordZonesOperation
  • CKModifyRecordsOperation
  • CKModifySubscriptionsOperation
  • CKQueryOperation

 

 

 

 

 

这篇博文发表在 应用开发 | App Dev 目录下,标签为 , , , ,
如需引用,请使用链接:https://note.mc256.dev/?p=1144

This article published in 应用开发 | App Dev with tags , , , , .
Cite this page using this link:https://note.mc256.dev/?p=1144

您的邮箱地址不会被公开,评论使用Gravatar头像。
Your email address will not be published. This blog is using Gravatar.

正在提交评论... Submitting ...
正在为您准备评论控件 Loading Comment Plugin
Copyright © 2013-2024 mc256. All Rights Reserved.
Powered by WordPress on top of a dual-stack k3s Cluster using JuiceFS.
Wordpress Theme Designed By mc256.
Encrypted By Let's Encrypt.  Hosted On Linode + OVH + AWS.
DNS Provided By Hostker.
Status Page by CloudFlare Worker.