Swift 2
我正在尝试将一个小资产保存到CloudKit,但没有多少运气找到示例代码。记录是"Table1“,资产在应用程序包中。任何建议都会有帮助的。iOS9 Swift 2。
let audioPath = NSBundle.mainBundle().pathForResource("song-1", ofType: "mp3")!
let itemRecord:CKRecord = CKRecord(recordType: "Table1")
db.saveRecord(itemRecord) { (record:CKRecord?, error:NSError?) -> Void in发布于 2016-03-11 07:25:59
首先必须创建一个CKAsset对象。你可以这样做:
let audioPath = NSBundle.mainBundle().pathForResource("song-1", ofType: "mp3")!
var file: CKAsset? = CKAsset(fileURL: NSURL(fileURLWithPath: audioPath))之后,可以使用以下方法将其添加到您的CKRecord中:
itemRecord.setValue(file, forKey: "AudioFile")https://stackoverflow.com/questions/35926662
复制相似问题