Re: [swift-users] Flatmap initializer inconsistency

2017-05-01 Thread Zhao Xin via swift-users
That is because for `Optional` the `flatMap` is `func flatMap(_ transform: (Wrapped) throws -> U?) rethrows -> U?` and for `Int`, only `init?(exactly value: Double)` fits the situation. `init(_ value: Double)` doesn't return nil. So there is no ambiguity. Zhaoxin On Tue, May 2, 2017 at 4:20 AM,

Re: [swift-users] Any way to declare a method that suppresses the string interpolation warning?

2017-05-01 Thread Rick Mann via swift-users
> On Apr 30, 2017, at 11:30 , Saagar Jha wrote: > > Apologize for the late response, this message got buried in my inbox. > > Saagar Jha > >> On Apr 23, 2017, at 23:23, Rick Mann wrote: >> >>> >>> On Apr 22, 2017, at 12:23 , Saagar Jha

Re: [swift-users] Flatmap initializer inconsistency

2017-05-01 Thread Zhao Xin via swift-users
In my test, compiler thought you use `init?(exactly value: Double)`, which returns nil. So this is not a bug. Zhaoxin On Tue, May 2, 2017 at 1:39 AM, Halen Wooten via swift-users < swift-users@swift.org> wrote: > Hi, > > I'm seeing a weird issue with using an initializer in flatMap. Here's > an

[swift-users] Flatmap initializer inconsistency

2017-05-01 Thread Halen Wooten via swift-users
Hi, I'm seeing a weird issue with using an initializer in flatMap. Here's an example: ``` let time: TimeInterval? = 662.8258259864 let intTimeFlatmap = time.flatMap(Int.init) // nil let intTime = Int(time!) // 662 ``` I would expect for the flatMap call to return an optional Int with the

Re: [swift-users] Atomics and Memory Fences in Swift

2017-05-01 Thread Joe Groff via swift-users
> On Apr 25, 2017, at 1:08 PM, Shawn Erickson wrote: > > > On Mon, Dec 5, 2016 at 9:28 AM Joe Groff via swift-users > wrote: > >> On Dec 4, 2016, at 4:53 PM, Andrew Trick via swift-users >> wrote: >> >> >>> On Nov 30,

Re: [swift-users] weak self

2017-05-01 Thread Zhao Xin via swift-users
[weak self] and [unowned self] are used to solve the problem of Strong Reference Cycles Between Class Instances . If you can grantee self won't be nil during

Re: [swift-users] weak self

2017-05-01 Thread Rien via swift-users
> On 01 May 2017, at 17:42, Dennis Weissmann wrote: > >> >> On May 1, 2017, at 5:32 PM, Rien wrote: >> >>> >>> On 01 May 2017, at 16:59, Dennis Weissmann >>> wrote: >>> On May 1, 2017, at 4:46 PM,

Re: [swift-users] weak self

2017-05-01 Thread Dennis Weissmann via swift-users
> On May 1, 2017, at 5:32 PM, Rien wrote: > >> >> On 01 May 2017, at 16:59, Dennis Weissmann wrote: >> >>> >>> On May 1, 2017, at 4:46 PM, Rien via swift-users >>> wrote: >>> >>> In my code I use a lot of queues.

Re: [swift-users] weak self

2017-05-01 Thread Rien via swift-users
> On 01 May 2017, at 16:59, Dennis Weissmann wrote: > >> >> On May 1, 2017, at 4:46 PM, Rien via swift-users >> wrote: >> >> In my code I use a lot of queues. And (very often) I will use [weak self] to >> prevent doing things when ‘self’ is

Re: [swift-users] weak self

2017-05-01 Thread Dennis Weissmann via swift-users
> On May 1, 2017, at 4:46 PM, Rien via swift-users > wrote: > > In my code I use a lot of queues. And (very often) I will use [weak self] to > prevent doing things when ‘self’ is no longer available. > > Now I am wondering: how does the compiler know that [weak self]

Re: [swift-users] weak self

2017-05-01 Thread Adrian Zubarev via swift-users
Not answering the questions, but sharing a neat trick. [weak self] in guard let `self` = self else { return } self.foo() // strong self :) --  Adrian Zubarev Sent with Airmail Am 1. Mai 2017 um 16:46:33, Rien via swift-users (swift-users@swift.org) schrieb: In my code I use a lot of

[swift-users] weak self

2017-05-01 Thread Rien via swift-users
In my code I use a lot of queues. And (very often) I will use [weak self] to prevent doing things when ‘self’ is no longer available. Now I am wondering: how does the compiler know that [weak self] is referenced? I am assuming it keeps a reverse reference from self to the [weak self] in order