How do I access the value of the ubiquitousItemDownloadingStatus resource value?

I have code to retrieve the ubiquitousItemDownloadingStatus resource value of a url:


do {

  let resourceValues = try item.url.resourceValues(forKeys: [URLResourceKey.ubiquitousItemDownloadingStatusKey]

  } catch {

  print(error.localizedDescription)

  }


However, I don't know what to do with the value. I am able to access the resource value with the following code:


  do {

  let resourceValues = try item.url.resourceValues(forKeys: [URLResourceKey.ubiquitousItemDownloadingStatusKey])

  resourceValues.ubiquitousItemDownloadingStatus // ???

  } catch {

  print(error.localizedDescription)

  }


But I'm not sure what to do after that. The declaration of the resource value in the Foundation Library is a struct, as follows:


public struct URLUbiquitousItemDownloadingStatus : Hashable, Equatable, RawRepresentable {

  public init(rawValue: String)
}
extension URLUbiquitousItemDownloadingStatus {

  @available(iOS 7.0, *)
  public static let notDownloaded: URLUbiquitousItemDownloadingStatus

  @available(iOS 7.0, *)
  public static let downloaded: URLUbiquitousItemDownloadingStatus

  @available(iOS 7.0, *)
  public static let current: URLUbiquitousItemDownloadingStatus
}


I'm confused because I expect an enum.

Please if anyone can help clarify this for me I would appreciate it.

Accepted Reply

The

URLUbiquitousItemDownloadingStatus
tell you the status of the download. This is primarily for UI purposes. If you want to access a ubiquitous file, you’ll need to wrap that access to ensure that the file is actually present, and that any changes you make then get uploaded when you’re done.

Most folks don’t do this directly. Rather, they use one of the platform document wrappers (

NSDocument
or
UIDocument
), which takes care of this and many other gnarly details.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

The

URLUbiquitousItemDownloadingStatus
tell you the status of the download. This is primarily for UI purposes. If you want to access a ubiquitous file, you’ll need to wrap that access to ensure that the file is actually present, and that any changes you make then get uploaded when you’re done.

Most folks don’t do this directly. Rather, they use one of the platform document wrappers (

NSDocument
or
UIDocument
), which takes care of this and many other gnarly details.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"