Re: URL.setResourceValues() in Swift 3
Re: URL.setResourceValues() in Swift 3
- Subject: Re: URL.setResourceValues() in Swift 3
- From: Quincey Morris <email@hidden>
- Date: Thu, 29 Sep 2016 10:54:20 -0700
- Feedback-id: 167118m:167118agrif8a:167118swmKCvuxvO:SMTPCORP
On Sep 29, 2016, at 04:18 , Rick Mann <email@hidden> wrote:
>
> var vals = URLResourceValues()
> vals.isExcludedFromBackup = true
> try destURL.setResourceValues(vals)
>
> But I get "Cannot convert value of type 'URLResourceValues' to expected argument type '[URLResourceKey : AnyObject]'" on the "vals" argument. The problem is that the docs say it's supposed to take [URLResourceKey : Any].
>
> The Swift interface file generated by Xcode looks like this:
>
> public mutating func setResourceValues(_ values: URLResourceValues) throws
>
> But that's clearly not what the compiler sees.
What is the type of ‘destURL’? URL or NSURL? It sounds like it’s NSURL.
The function signature in class NSURL is:
> func setResourceValues([URLResourceKey : Any])
whereas the function signature in class URL is:
> func setResourceValues(_ values: URLResourceValues)
So, you either need to change destURL to be a URL, or use the NSURL API that takes a dictionary. Note that URL is not just a cosmetic renaming of NSURL in Swift 3, but a whole new type that wraps a NSURL object. Both types are accessible, though you’re going to have the best Swift 3 experience if you switch to URL — and its altered API and semantics.
Regarding Any vs. AnyObject as the dictionary value, the error message I get (in Xcode 8.1 beta, with the above code) is:
> Cannot convert value of type 'URLResourceValues' to expected argument type '[URLResourceKey : Any]’
So, you’re either not compiling against the 10.12 SDK (which I think should be impossible), or you’re compiling as Swift 2.3, or Xcode at least thinks you are.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden