Re: [swift-users] @noReturn

2017-03-24 Thread Saagar Jha via swift-users
By the way, return Never used to be called @noreturn, so you weren't far off! On Fri, Mar 24, 2017 at 02:22 Rien via swift-users wrote: > Excellent! > > Love this list ;-) > > Regards, > Rien > > Site: http://balancingrock.nl > Blog: http://swiftrien.blogspot.com > Github: http://github.com/Balan

Re: [swift-users] Memory Leak of Dictionary used in singleton

2017-03-24 Thread Joe Groff via swift-users
> On Mar 11, 2017, at 4:04 PM, Ekaterina Belinskaya via swift-users > wrote: > > Hi everyone! > > I have singleton. It contains a 2 dictionaries. > > struct Stat { > var statHash:String > var displayDescription:String > var displayName:String > var displayIcon:String > va

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Toni Suter via swift-users
Ok, I submitted a bug report (https://bugs.swift.org/browse/SR-4347 ) and I'll try to fix it in the next few days. Thanks and best regards Toni > Am 24.03.2017 um 18:51 schrieb Mark Lacey : > >> >> On Mar 24, 2017, at 3:08 AM, Toni Suter via swift-users

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Mark Lacey via swift-users
> On Mar 24, 2017, at 3:08 AM, Toni Suter via swift-users > wrote: > > Hi, > > If I declare a variable and initialize it with an array literal whose > elements are integer literals and nil literals, > the compiler will infer the type Array> for that variable: > > let arr = [1, nil, 3] > prin

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Toni Suter via swift-users
Thanks anyway! :-) > Am 24.03.2017 um 12:03 schrieb Rien : > > I always yield to proof ;-) > > hope someone more knowledgable chips in... > > Regards, > Rien > > Site: http://balancingrock.nl > Blog: http://swiftrien.blogspot.com > Github: http://github.com/Balancingrock > Project: http://swif

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Rien via swift-users
I always yield to proof ;-) hope someone more knowledgable chips in... Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl > On 24 Mar 2017, at 11:53, Toni Suter wrote: > > Hmm, I don't know.

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Toni Suter via swift-users
Hmm, I don't know. It also works with other nominal types. For example: struct S { var x: Int var y: Int } let s1 = S(x: 0, y: 1) let s2 = S(x: 2, y: 3) let arr = [s1, nil, s2] print(type(of: arr))// Array> > Am 24.03.2017 um 11:30 schrieb Rien : > > Btw, I just looked it up and

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Rien via swift-users
Btw, I just looked it up and it seems to me that inference only works for literals. Which probably means that tuples are out. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl > On 24 Mar 2017

Re: [swift-users] Type inference of array element type

2017-03-24 Thread Rien via swift-users
IMO this is a boundary problem. How far do you want to go in letting the compiler deduce the actual type? It is possible to make very elaborate constructs that would basically default to a complex tuple/array/dictionary construct with only Any?’s in them. (well, the dict would require a Hashable

[swift-users] Type inference of array element type

2017-03-24 Thread Toni Suter via swift-users
Hi, If I declare a variable and initialize it with an array literal whose elements are integer literals and nil literals, the compiler will infer the type Array> for that variable: let arr = [1, nil, 3] print(type(of: arr))// Array> However, that only works with nominal types such as Int an

Re: [swift-users] @noReturn

2017-03-24 Thread Rien via swift-users
Excellent! Love this list ;-) Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl > On 24 Mar 2017, at 10:12, Philip Erickson wrote: > > I believe returning Never does what you want, e.g. > >

Re: [swift-users] @noReturn

2017-03-24 Thread Zhao Xin via swift-users
The last line should be `fatalError(findReasonAndTerminate())`. Zhaoxin On Fri, Mar 24, 2017 at 5:13 PM, Zhao Xin wrote: > Change you `func findReasonAndTerminate()` to `func > findReasonAndTerminate() -> String`. > Then you can use `fatalError(func findReasonAndTerminate())`. > > Zhaoxin > >

Re: [swift-users] @noReturn

2017-03-24 Thread Zhao Xin via swift-users
Change you `func findReasonAndTerminate()` to `func findReasonAndTerminate() -> String`. Then you can use `fatalError(func findReasonAndTerminate())`. Zhaoxin On Fri, Mar 24, 2017 at 5:02 PM, Rien via swift-users wrote: > Is there any way to mark a function as “no return”? > > Reason: The compi

Re: [swift-users] @noReturn

2017-03-24 Thread Philip Erickson via swift-users
I believe returning Never does what you want, e.g. import Foundation func findReasonAndTerminate() -> Never { let reason: String = findReason() fatalError(reason) } func findReason() -> String { return "some reason" } func buildData() -> Data? { return nil } guard let data = buildData()

[swift-users] @noReturn

2017-03-24 Thread Rien via swift-users
Is there any way to mark a function as “no return”? Reason: The compiler generates an error when the else block from a guard does not terminate the execution by either a return or a fatalError. I want to call out to a function and raise the fatalError in that function. func findReasonAndTermina