【问题标题】:Ensembles in iOS swiftiOS Swift 中的合奏
【发布时间】:2015-06-05 20:45:34
【问题描述】:

我想使用来自 github 的 Drew McCormack 的 Ensembles 来缓解我当前的 iOS/swift/coredata/iCloud 引起的头痛。所有的 Ensembles 示例都在 Objective-C 中。我将它作为我的项目中的一个框架,但作为一个周末编码员,我无法从 ObjC 示例代码中推断如何使用它。

有人看过使用 swift 的 Ensembles 方法指南吗?

补充:我有它作为一个框架,但是我如何设置它并让它开始 Leeching? Obj-C的方式是

//SetupEnsemble
cloudFileSystem=[[CDEICloudFileSystemalloc] initWithUbiquityContainerIdentifier:@"container"];
ensemble=[[CDEPersistentStoreEnsemblealloc]initWithEnsembleIdentifier:@"MainStore" persistentStoreURL:storeURL
        managedObjectModelURL:modelURL
cloudFileSystem:cloudFileSystem]; ensemble.delegate=self;

然后是水蛭

if(!ensemble.isLeeched){
[ensemble leechPersistentStoreWithCompletion:^(NSError *error) {
if (error) NSLog(@"Could not leech to ensemble: %@", error); }];}

【问题讨论】:

    标签: ios swift core-data ensembles


    【解决方案1】:

    以下步骤描述了如何使用 iCloud + Dropbox 文件系统将集成添加到项目中:

    使用以下内容将“Podfile”添加到您的项目中:

    target :YOUR_TARGET_NAME do
    platform :ios, '7.0'
    pod "Ensembles", :git => 'https://github.com/drewmccormack/ensembles.git'
    pod "Ensembles/Dropbox", :git => 'https://github.com/drewmccormack/ensembles.git'
    link_with 'YOUR_TARGET_NAME'
    end
    

    从终端运行“pod install”

    创建一个ObjC bridging header

    添加 Ensembles(和其他框架到桥接头):

    #import <Foundation/Foundation.h>
    #import <Ensembles/Ensembles.h>
    #import "DropboxSDK.h"
    #import "CDEDropboxCloudFileSystem.h"
    

    快乐编码:

    var ensemble:CDEPersistentStoreEnsemble?
    var ensembleFileSystem:CDECloudFileSystem?
    
    ensembleFileSystem = CDEICloudFileSystem(
      ubiquityContainerIdentifier: "SOME_CONTAINER",
      relativePathToRootInContainer: "STORE_ROOT_PATH"
    )
    
    ensemble = CDEPersistentStoreEnsemble(
      ensembleIdentifier: "IDENTIFIER",
      persistentStoreURL: "STORE_URL",
      persistentStoreOptions:nil,
      managedObjectModelURL:"MOM_URL",
      cloudFileSystem:ensembleFileSystem,
      localDataRootDirectoryURL:"DATA_ROOT_URL"
    )
    
    e.leechPersistentStoreWithCompletion({ (error:NSError?) -> Void in
      // check for error, etc...
    })
    

    【讨论】:

    • 我遇到了构建错误,可能是因为我对 STORE_ROOT_PATH、DATA_ROOT_URL 以及其他内容感到困惑。我正在使用的核心数据信息是let store_url = self.applicationDocumentsDirectory.URLByAppendingPathComponent("myapp.sqlite") let modelURL = NSBundle.mainBundle().URLForResource("myapp", withExtension: "momd")!
    • 与其在这里问越来越多的问题,我将开始一个关于我的编译错误的新问题。
    【解决方案2】:

    如果您是周末程序员,我建议您使用 Apple 的 CloudKit。当然,这一切都很快。有一些不错的教程在:https://videos.raywenderlich.com/courses/45-introduction-to-cloudkit/lessons/1

    【讨论】:

    • 嗨,约翰,我也在评估合奏!我只是对您的评论感到好奇“如果您是周末编码员,我会考虑使用 CloudKit”。我的理解是 CloudKit 需要我自己编写所有同步代码,而 Ensembles 会为我处理。我误解了其中的区别吗?
    猜你喜欢
    • 2016-09-03
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 2019-11-26
    • 2015-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多