Why would this be "ambiguous"?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Why would this be "ambiguous"?

Alex Hall
Hello all,Calendar, NSDate, etc. This line:
let differenceComponents:NSDateComponents = calendar.components(.Year | .month | .Week | .Day | .Hour | .Minute, fromDate:date, toDate:nowDate, options:0)
gives the error:
type of statement is ambiguous without more context

I'm wondering why it would be, and what I can do to fix it? The function being called returns NSDateComponents, which I assign to my variable. I'm not seeing the ambiguity, and Google has nothing to say on the topic that relates to this. I just found a couple instances where the person either had to change a function or do something different with the options. Thanks.

Sorry if this isn't the list for this. I have an iOS app and I'm just starting to explore NS

--
Have a great day,
Alex Hall
[hidden email]

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/F0FEF52E-A258-44CD-AF07-021C3928E134%40icloud.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why would this be "ambiguous"?

Brent Royal-Gordon
> let differenceComponents:NSDateComponents = calendar.components(.Year | .month | .Week | .Day | .Hour | .Minute, fromDate:date, toDate:nowDate, options:0)

If you’re using Swift 2, you now need to write that set of calendar units as [.Year, .Month, .Week, .Day, .Hour, .Minute] instead of trying to or them together. Not sure that will completely fix your problem, but it’s a start.

--
Brent Royal-Gordon
Architechies

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/FB82632B-2340-41E6-881D-DDFA9CC62567%40architechies.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why would this be "ambiguous"?

Daniel T.
In reply to this post by Alex Hall
This works:

let differenceComponents = calendar.components([.Year, .Month, .Day, .Hour, .Minute],
fromDate: date,
toDate: nowDate,
options: NSCalendarOptions())


On Oct 20, 2015, at 4:32 PM, Alex Hall <[hidden email]> wrote:

Hello all,Calendar, NSDate, etc. This line:
let differenceComponents:NSDateComponents = calendar.components(.Year | .month | .Week | .Day | .Hour | .Minute, fromDate:date, toDate:nowDate, options:0)
gives the error:
type of statement is ambiguous without more context

I'm wondering why it would be, and what I can do to fix it? The function being called returns NSDateComponents, which I assign to my variable. I'm not seeing the ambiguity, and Google has nothing to say on the topic that relates to this. I just found a couple instances where the person either had to change a function or do something different with the options. Thanks.

Sorry if this isn't the list for this. I have an iOS app and I'm just starting to explore NS

--
Have a great day,
Alex Hall
[hidden email]


--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/F0FEF52E-A258-44CD-AF07-021C3928E134%40icloud.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/0879A257-3DDF-4021-82BF-F021FDAECEB2%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why would this be "ambiguous"?

Kevin Ballard
In reply to this post by Brent Royal-Gordon


On Tue, Oct 20, 2015, at 01:37 PM, Brent Royal-Gordon wrote:
> > let differenceComponents:NSDateComponents = calendar.components(.Year | .month | .Week | .Day | .Hour | .Minute, fromDate:date, toDate:nowDate, options:0)
>
> If you’re using Swift 2, you now need to write that set of calendar units
> as [.Year, .Month, .Week, .Day, .Hour, .Minute] instead of trying to or
> them together. Not sure that will completely fix your problem, but it’s a
> start.

You also need to specify the options as `[]` instead of as `0`. If
you're still on Swift 1.2, then you still need to specify options as
`nil` instead of `0`.

You also typed `.month` instead of `.Month`.

-Kevin Ballard

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/1445373651.3970367.415677801.5A56A940%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why would this be "ambiguous"?

Kevin Ballard
In reply to this post by Daniel T.
The `NSCalendarOptions()` is unnecessarily verbose. Yeah that works, but `[]` is much shorter and more idiomatic.
 
-Kevin
 
On Tue, Oct 20, 2015, at 01:47 PM, Daniel Tartaglia wrote:
This works:
 
let differenceComponents = calendar.components([.Year, .Month, .Day, .Hour, .Minute],
fromDate: date,
toDate: nowDate,
options: NSCalendarOptions())
 
 
On Oct 20, 2015, at 4:32 PM, Alex Hall <[hidden email]> wrote:
 
Hello all,Calendar, NSDate, etc. This line:
let differenceComponents:NSDateComponents = calendar.components(.Year | .month | .Week | .Day | .Hour | .Minute, fromDate:date, toDate:nowDate, options:0)
gives the error:
type of statement is ambiguous without more context
 
I'm wondering why it would be, and what I can do to fix it? The function being called returns NSDateComponents, which I assign to my variable. I'm not seeing the ambiguity, and Google has nothing to say on the topic that relates to this. I just found a couple instances where the person either had to change a function or do something different with the options. Thanks.
 
Sorry if this isn't the list for this. I have an iOS app and I'm just starting to explore NS
 
--
Have a great day,
Alex Hall
 
 
--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
 


--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/1445374206.3973827.415688089.537A1939%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why would this be "ambiguous"?

Alex Hall
Thank you, everyone. I apparently missed the memo regarding or-ing things together in Swift 2; everything now works as expected. Is this specific to certain Cocoa classes, or is it safe to assume that anytime an API in Cocoa wants or-ed items, I should pass them in as an array?
On Oct 20, 2015, at 16:50, Kevin Ballard <[hidden email]> wrote:

The `NSCalendarOptions()` is unnecessarily verbose. Yeah that works, but `[]` is much shorter and more idiomatic.
 
-Kevin
 
On Tue, Oct 20, 2015, at 01:47 PM, Daniel Tartaglia wrote:
This works:
 
let differenceComponents = calendar.components([.Year, .Month, .Day, .Hour, .Minute],
fromDate: date,
toDate: nowDate,
options: NSCalendarOptions())
 
 
On Oct 20, 2015, at 4:32 PM, Alex Hall <[hidden email]> wrote:
 
Hello all,Calendar, NSDate, etc. This line:
let differenceComponents:NSDateComponents = calendar.components(.Year | .month | .Week | .Day | .Hour | .Minute, fromDate:date, toDate:nowDate, options:0)
gives the error:
type of statement is ambiguous without more context
 
I'm wondering why it would be, and what I can do to fix it? The function being called returns NSDateComponents, which I assign to my variable. I'm not seeing the ambiguity, and Google has nothing to say on the topic that relates to this. I just found a couple instances where the person either had to change a function or do something different with the options. Thanks.
 
Sorry if this isn't the list for this. I have an iOS app and I'm just starting to explore NS
 
--
Have a great day,
Alex Hall
 
 
--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
 


--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/1445374206.3973827.415688089.537A1939%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.


--
Have a great day,
Alex Hall
[hidden email]

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/ED976CF9-0F6A-4F5C-92B6-71A79F999A77%40icloud.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Why would this be "ambiguous"?

Jim Dovey
> On Oct 20, 2015, at 2:11 PM, Alex Hall <[hidden email]> wrote:
>
> Thank you, everyone. I apparently missed the memo regarding or-ing things together in Swift 2; everything now works as expected. Is this specific to certain Cocoa classes, or is it safe to assume that anytime an API in Cocoa wants or-ed items, I should pass them in as an array?

This is the new syntax for OptionSet types, which is a part of the standard library in Swift 2.0. When converting from ObjC, any type declared using the NS_OPTIONS or CF_OPTIONS macros are imported as OptionSets, so they all get this syntax.

Cheers,
-Jim

--
You received this message because you are subscribed to the Google Groups "Swift Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/swift-language/3075DDBE-5FD2-44C7-B927-A0CE96DA2D12%40gmail.com.
For more options, visit https://groups.google.com/d/optout.