• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: URL.setResourceValues() in Swift 3
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: URL.setResourceValues() in Swift 3


  • Subject: Re: URL.setResourceValues() in Swift 3
  • From: Rick Mann <email@hidden>
  • Date: Thu, 29 Sep 2016 13:29:33 -0700

> On Sep 29, 2016, at 10:54 , Quincey Morris <email@hidden> wrote:
>
> 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.

Nope, it's URL.

> 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.

So, it turns out, destURL was a let, not a var. That made the difference. Sure seems like a bad diagnostic.

However, there's also a problem in that the documentation in Xcode 8 is:

	func setResourceValues(_ keyedValues: [URLResourceKey : Any]) throws

But the Xcode generated interface shows it as:

	public mutating func setResourceValues(_ values: URLResourceValues) throws

And incidentally, it seems Xcode's code completion still isn't reliable, in that I can command-click on URL, but not on setResourceValues (I just get a ? appearing).

I'll write a bug.

--
Rick Mann
email@hidden



_______________________________________________

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


  • Follow-Ups:
    • Re: URL.setResourceValues() in Swift 3
      • From: Quincey Morris <email@hidden>
References: 
 >URL.setResourceValues() in Swift 3 (From: Rick Mann <email@hidden>)
 >Re: URL.setResourceValues() in Swift 3 (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Normalising file names on macOS
  • Next by Date: Re: URL.setResourceValues() in Swift 3
  • Previous by thread: Re: URL.setResourceValues() in Swift 3
  • Next by thread: Re: URL.setResourceValues() in Swift 3
  • Index(es):
    • Date
    • Thread