1

Anybody using iRareMedia's iCloudDocumentSync with Swift? I used this framework successfully with Objective-C, but can't get started with Swift. In Objective C, the app initializes iCloud with the following:

[[iCloud sharedCloud] setDelegate:self]; // Set this if you plan to use the delegate
[[iCloud sharedCloud] setVerboseLogging:YES]; // We want detailed feedback about what's going on with iCloud, this is OFF by default
[[iCloud sharedCloud] setupiCloudDocumentSyncWithUbiquityContainer:nil];   

I cannot figure out how to convert two of these to Swift. The class is subscribed to the iCloudDelegate protocol:

class AppDelegate: UIResponder, UIApplicationDelegate, iCloudDelegate {

For the first

[[iCloud sharedCloud] setDelegate:self];

I tried iCloud.sharedCloud().setDelegate(self) but I get a compiler error: Cannot invoke 'setDelegate' with an argument list of type '(AppDelegate)'

I've also tried iCloud.sharedCloud().delegate = self (since delegate is a property of iCloud), but I get the compiler message: Ambiguous use of 'delegate'

The second [[iCloud sharedCloud] setVerboseLogging:YES]; converts just fine with iCloud.sharedCloud().setVerboseLogging = true

The third [[iCloud sharedCloud] setupiCloudDocumentSyncWithUbiquityContainer:nil]; I've tried

iCloud.sharedCloud().setupiCloudDocumentSyncWithUbiquityContainer(nil) 

which gets me: Value of type 'AnyObject' has no member 'setupiCloudDocumentSyncWithUbiquityContainer' with the error caret under the 's' of sharedCloud.

I'm baffled. I've done lots of Objective-c to Swift method conversions, so I'm not exactly new to this game, but I can't figure this out. If anyone is using iRareMedia's iCloudDocumentSync framwork with Swift, I'd appreciate any help and insights.

Thanks.

johnz
  • 489
  • 2
  • 17

1 Answers1

1

I don't know why, but setting up the iCloud delegate and initializing statements in a UIViewController allows them to all work in Swift. In the first viewcontroller in my app, I have this:

    cloud = iCloud.sharedCloud() as! iCloud
    cloud.delegate = self
    cloud.verboseLogging = true
    cloud.updateFiles()

and everything works as it's supposed to.

johnz
  • 489
  • 2
  • 17
  • Hi, I am stuck at the same point. I would like to sync files from and to the cloud using this pod. Should I add this part in the view controller where I sync with the icloud or just in the first view controller. – Mina Gerges Nov 20 '20 at 11:20
  • Wow, it's been a long time since I thought about this. I put that code into the first view controller opened, but I think you could put them in the view controller that syncs with iCloud and it work work as well. I suspect better ways to do an iClouds sync have come with more recent versions of Swift, but I don't know them. As it turned out, I decided to pull iCloud syncs out of the app I was writing at the time, so I don't even know if the above code still works! – johnz Nov 21 '20 at 23:54
  • Thanks for your response. I already find another tutorial that works for me. – Mina Gerges Nov 22 '20 at 15:03