Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-17 Thread Saagar Jha via swift-users

Saagar Jha

> On Dec 17, 2017, at 22:24, Nevin Brackett-Rozinsky via swift-users 
>  wrote:
> 
> …well that was more complicated than I anticipated.
> 
> The “random” function was (Int) -> Int, so when I removed the “IndexDistance 
> == Int” constraint on “shuffle” I either had to add several “numericCast” 
> calls or make “random” generic.
> 
> So I made “random” generic. And also fixed the modulo bias issue in the Glibc 
> version that Saagar mentioned. Or at least I hope I did. I haven’t tested 
> that part (nor any of the non-Swift-4 / non-macOS parts). Also, I am not sure 
> why “random” had been a closure value stored in a “let” constant, but I 
> changed it to a function.

Great! I'll close my pull request, then.

> 
> While I was at it, I removed the random-access constraint I had placed on 
> “shuffle”. It will now shuffle any MutableCollection, with complexity O(n) 
> for a RandomAccessCollection and O(n²) otherwise. (The constraint was 
> different in different Swift versions, so the entire extension had to be 
> duplicated. Without the constraint the implementation is much sleeker.)
> 
> Nevin
> 
> 
> On Sun, Dec 17, 2017 at 9:26 PM, Nevin Brackett-Rozinsky 
> mailto:nevin.brackettrozin...@gmail.com>> 
> wrote:
> On Sun, Dec 17, 2017 at 7:37 PM, Dave Abrahams  > wrote:
> 
>> On Dec 16, 2017, at 4:34 PM, Nevin Brackett-Rozinsky via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> public extension MutableCollection where Self: RandomAccessCollection, 
>> IndexDistance == Int {
> 
> IndexDistance == Int is an over-constraint, FWIW.  Adding it is generally a 
> mistake.  Not a serious one, but it does limit utility somewhat.
> 
> HTH,
> Dave
> 
> You are correct, however there is an accepted-and-implemented proposal 
> (SE–0191 
> )
>  to eliminate IndexDistance and replace it with Int, so the constraint will 
> always be satisfied starting in Swift 4.1.
> 
> I wrote a version of shuffle() without that constraint, but it is less 
> elegant: the line “for n in 0 ..< count - 1” no longer compiles, and writing 
> “0 as IndexDistance” doesn’t fix it because the resulting Range is not a 
> Sequence, since IndexDistance.Stride does not conform to SignedInteger (at 
> least in Swift 4.0 according to Xcode 9.2).
> 
> A while loop works of course, though a direct conversion requires writing 
> “var n = 0 as IndexDistance” before the loop. Luckily, with a bit of 
> cleverness we can eliminate all mention of IndexDistance, and this time we 
> really and truly don’t need the “guard !isEmpty” line:
> 
> extension MutableCollection where Self: RandomAccessCollection {
> mutating func shuffle() {
> var n = count
> while n > 1 {
> let i = index(startIndex, offsetBy: count - n)
> let j = index(i, offsetBy: random(n))
> n -= 1
> swapAt(i, j)
> }
> }
> }
> 
> Essentially, the constraint is there to make the code nicer on pre-4.1 
> versions of Swift, though I’m happy to remove it if you think that’s better. 
> If nothing else, removing the constraint means people reading the example 
> code in the future won’t be misled into thinking they need to use it 
> themselves, so perhaps it should go just on that account.
> 
> Okay, you’ve convinced me, I’ll update the PR. :-)
> 
> Nevin
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-16 Thread Saagar Jha via swift-users
While we’re still looking at the Fisher-Yates shuffle package, I stumbled upon 
this 

 definition of random():

 public let random: (Int) -> Int = {
 while true {
let x = Glibc.random() % $0
let y = Glibc.random() % $0
guard x == y else { return x }
}
}

Perhaps I’m mistaken here, but if this is random(3) 

 don’t we have to 1. seed it before use and 2. deal with modulo bias? I’m also 
not quite sure why the guard is there, either.

Saagar Jha

> On Dec 16, 2017, at 16:37, Daniel Dunbar via swift-users 
>  wrote:
> 
> Would you like to post a PR to fix these issues?
> 
>  - Daniel
> 
>> On Dec 16, 2017, at 4:34 PM, Nevin Brackett-Rozinsky via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> The example implementation of the Fisher-Yates shuffle found here 
>> 
>>  on Apple’s GitHub (and linked from swift.org/package-manager 
>> ) has some problems. Stripping it down 
>> to just the Swift 4 version, the code is:
>> 
>> public extension MutableCollection where Index == Int, IndexDistance == Int {
>> mutating func shuffle() {
>> guard count > 1 else { return }
>> 
>> for i in 0..> let j = random(count - i) + i
>> guard i != j else { continue }
>> swapAt(i, j)
>> }
>> }
>> }
>> 
>> The main issues are:
>> 
>> 1) It assumes that indices are 0-based.
>> 2) It assumes that indices can be randomly accessed by addition.
>> 
>> The former means it does not work for ArraySlice, and the latter means it 
>> won’t work for all custom types. Additionally, the “count” property (which 
>> is only guaranteed to be O(n) here) is accessed inside the loop, thus making 
>> the algorithm potentially O(n²).
>> 
>> To fix everything, we’ll want RandomAccessCollection conformance. Once we 
>> add that, we no longer need “Index == Int”. The result looks like:
>> 
>> public extension MutableCollection where Self: RandomAccessCollection, 
>> IndexDistance == Int {
>> mutating func shuffle() {
>> for n in 0 ..< count-1 {
>> let i = index(startIndex, offsetBy: n)
>> let j = index(i, offsetBy: random(count-n))
>> swapAt(i, j)
>> }
>> }
>> }
>> 
>> Both of the original guard statements would be superfluous here (notably, 
>> “swapAt” is documented to have no effect when i and j are the same) so I 
>> removed them.
>> 
>> Technically we could get away without random access and still have an O(n) 
>> algorithm, at the cost of copying the indices to an array:
>> 
>> public extension MutableCollection {
>> mutating func shuffle() {
>> guard !isEmpty else { return }
>> 
>> var idx = Array(indices)
>> 
>> for i in 0 ..< idx.count - 1 {
>> let j = i + random(idx.count - i)
>> swapAt(idx[i], idx[j])
>> idx.swapAt(i, j)
>> }
>> }
>> }
>> 
>> In any event, just in case someone was using a cut-and-paste version of the 
>> example code in their own project, now you know it needs adjustment.
>> 
>> Nevin
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-16 Thread Saagar Jha via swift-users

Saagar Jha

> On Dec 16, 2017, at 16:34, Nevin Brackett-Rozinsky via swift-users 
>  wrote:
> 
> The example implementation of the Fisher-Yates shuffle found here 
> 
>  on Apple’s GitHub (and linked from swift.org/package-manager 
> ) has some problems. Stripping it down to 
> just the Swift 4 version, the code is:
> 
> public extension MutableCollection where Index == Int, IndexDistance == Int {
> mutating func shuffle() {
> guard count > 1 else { return }
> 
> for i in 0.. let j = random(count - i) + i
> guard i != j else { continue }
> swapAt(i, j)
> }
> }
> }
> 
> The main issues are:
> 
> 1) It assumes that indices are 0-based.
> 2) It assumes that indices can be randomly accessed by addition.
> 
> The former means it does not work for ArraySlice, and the latter means it 
> won’t work for all custom types. Additionally, the “count” property (which is 
> only guaranteed to be O(n) here) is accessed inside the loop, thus making the 
> algorithm potentially O(n²).
> 
> To fix everything, we’ll want RandomAccessCollection conformance. Once we add 
> that, we no longer need “Index == Int”. The result looks like:
> 
> public extension MutableCollection where Self: RandomAccessCollection, 
> IndexDistance == Int {
> mutating func shuffle() {
> for n in 0 ..< count-1 {
> let i = index(startIndex, offsetBy: n)
> let j = index(i, offsetBy: random(count-n))
> swapAt(i, j)
> }
> }
> }
> 
> Both of the original guard statements would be superfluous here (notably, 
> “swapAt” is documented to have no effect when i and j are the same) so I 
> removed them.

Actually, I believe the first guard is still necessary–if the collection is 
empty, you’d end up with trying to construct the range 0..<-1, which traps. 
Alternatively, stride(from:to) is more lenient.

> 
> Technically we could get away without random access and still have an O(n) 
> algorithm, at the cost of copying the indices to an array:
> 
> public extension MutableCollection {
> mutating func shuffle() {
> guard !isEmpty else { return }
> 
> var idx = Array(indices)
> 
> for i in 0 ..< idx.count - 1 {
> let j = i + random(idx.count - i)
> swapAt(idx[i], idx[j])
> idx.swapAt(i, j)
> }
> }
> }
> 
> In any event, just in case someone was using a cut-and-paste version of the 
> example code in their own project, now you know it needs adjustment.
> 
> Nevin
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Documentation for optional closure arguments

2017-09-20 Thread Saagar Jha via swift-users
Oh, is that what’s happening? I having this issue back in Xcode 8 where it 
wasn’t recognizing my closure parameters, and I couldn’t figure out what was 
wrong.

Saagar Jha

> On Sep 20, 2017, at 17:20, Daryle Walker via swift-users 
>  wrote:
> 
> Trying out Xcode 9. Documenting a function that takes a trailing closure. The 
> list of arguments includes the closure’s arguments! But if the closure is 
> Optional, the inner arguments are not pierced and therefore not included in 
> the outer function’s summary. Can that be fixed?
> 
> Sent from my iPhone
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] XML parsing on Linux, with Swift 3.1

2017-09-05 Thread Saagar Jha via swift-users

Saagar Jha

> On Sep 5, 2017, at 01:19, Georgios Moschovitis via swift-users 
>  wrote:
> 
> Indeed it works, but I don’t get it.
> What’s the difference?
> 
> -g.
> 
> PS: Btw, my original code was giving `seg-fault: 11` even on macOS.
> 
>> On 5 Sep 2017, at 10:53 AM, CK TUNG via swift-users > > wrote:
>> 
>> This revised code, as below, works without segmentation fault
>> 
>> import Foundation
>> 
>> class ParserDelegate: NSObject, XMLParserDelegate {
>> 
>> func startParsing(_ xml:String) {
>> let data = xml.data(using: .utf8)!
>> let xmlParser = XMLParser(data: data)
>> xmlParser.delegate = self
>> xmlParser.parse()
>> }
>> 
>> func parserDidStartDocument(_ parser: XMLParser) {
>> print("Starting document")
>> }
>> 
>> func parser(_ parser: XMLParser, didStartElement elementName: String, 
>> namespaceURI: String?, qualifiedName qName: String?, attributes 
>> attributeDict: [String : String]) {
>> print("*** \(elementName)")
>> }
>> }
>> 
>> let xml = "George"
>> let test = ParserDelegate()
>> test.startParsing(xml)
>> 
>> On Sep 05, 2017, at 02:24 PM, Georgios Moschovitis via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>>> As an example, this SegFaults:
>>> 
>>> import Foundation
>>> 
>>> class ParserDelegate: NSObject, XMLParserDelegate {
>>> func parserDidStartDocument(_ parser: XMLParser) {
>>> print("Starting document")
>>> }
>>> 
>>> func parser(_ parser: XMLParser, didStartElement elementName: String, 
>>> namespaceURI: String?, qualifiedName qName: String?, attributes 
>>> attributeDict: [String : String] = [:]) {
>>> print("*** \(elementName)")
>>> }
>>> }
>>> 
>>> let xml = "George"
>>> let data = xml.data(using: .utf8)!
>>> let xmlParser = XMLParser(data: data)
>>> xmlParser.delegate = ParserDelegate()

XMLParser’s delegate is unowned, so it’s being deallocated when you exit the 
current scope. Hold on to it with a strong reference:

let delegate = ParserDelegate()
xmlParser.delegate = delegate

>>> xmlParser.parse()
>>> 
 On 5 Sep 2017, at 9:01 AM, Georgios Moschovitis 
 mailto:george.moschovi...@icloud.com>> 
 wrote:
 
 Hi,
 
 I would like to parse an RSS feed using Swift 3.1 on Linux.
 I tried to use Foundations’s XML but I only managed to get segmentation 
 faults.
 Is this supposed to work on Linux? I have only seen examples on iOS.
 
 Apart from that a quick search didn’t reveal any useful XML parsing 
 library compatible with Linux.
 
 Any suggestions?
 
 -g.
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Calling (Void) -> () with Void

2017-07-09 Thread Saagar Jha via swift-users
Hello,

I’m having some odd results with closures that take Void as a parameter, and 
was wondering if this was expected behavior or a bug. Specifically, I have the 
following closure:

> Welcome to Apple Swift version 4.0 (swiftlang-900.0.45.6 clang-900.0.26).
> let foo: (Void) -> () = {}

Trying to call foo without parameters fails, of course:

> foo()
error: missing argument for parameter #1 in call
foo()
^
<#Void#>

However, the fix-it doesn’t seem to work:

> foo(Void) // or even: foo(Void())
error: argument passed to call that takes no arguments
foo(Void)
   ^~

while

> foo(()) // Executes with no errors

works. Since Void is a typealias for () this should work, shouldn’t it? Just 
wanted to confirm that I’m not going crazy here.

Regards,
Saagar Jha

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] arc4random_uniform on Linux is missing from Foundation??

2017-05-24 Thread Saagar Jha via swift-users
drand48 is a small LCG and I think it also needs to be seeded before you use it 
with srand48; otherwise it’ll give the same sequence each time.

Saagar Jha

> On May 24, 2017, at 08:15, Edward Connell  wrote:
> 
> Thank you for all the feedback and options. In further investigation, I also 
> ran across the family of xx48 rngs, which appear to be on both platforms. 
> They claim to be uniformly distributed.
> 
> drand48, erand48, jrand48, lcong48, lrand48, mrand48, nrand48, seed48, srand48
> 
> http://pubs.opengroup.org/onlinepubs/007908775/xsh/drand48.html 
> <http://pubs.opengroup.org/onlinepubs/007908775/xsh/drand48.html>
> 
> Any reason not to use one of these instead?
> 
> Thanks, Ed
> 
> On Tue, May 23, 2017 at 3:18 AM, Jens Persson  <mailto:j...@bitcycle.com>> wrote:
> Here's a stripped down verison of my implementation of the Xoroshiro128+ PRNG:
> https://gist.github.com/anonymous/527602968812f853d6147aea8c66d660 
> <https://gist.github.com/anonymous/527602968812f853d6147aea8c66d660>
> 
> /Jens
> 
> 
> On Mon, May 22, 2017 at 11:21 PM, Jens Persson  <mailto:j...@bitcycle.com>> wrote:
> Sorry for the premature send ...
> Here is the site: http://xoroshiro.di.unimi.it <http://xoroshiro.di.unimi.it/>
> There is also a section there about "generating uniform doubles in unit 
> interval" which is worth reading.
> And here's how to get uniform floating point values in the range [0, 1) from 
> various (supposedly) random bit patterns:
> extension Double {
> init(unitRange v: UInt64) {
> let shifts: UInt64 = 63 - UInt64(Double.significandBitCount)
> self = Double(v >> shifts) * (.ulpOfOne/2)
> }
> init(unitRange v: UInt32) {
> self = (Double(v) + 0.5) / (Double(UInt32.max) + 1.0)
> }
> init(unitRange v: UInt16) {
> self = (Double(v) + 0.5) / (Double(UInt16.max) + 1.0)
> }
> init(unitRange v: UInt8) {
> self = (Double(v) + 0.5) / (Double(UInt8.max) + 1.0)
> }
> }
> extension Float {
> init(unitRange v: UInt64) {
> let shifts: UInt64 = 63 - UInt64(Float.significandBitCount)
> self = Float(v >> shifts) * (.ulpOfOne/2)
> }
> init(unitRange v: UInt32) {
> let shifts: UInt32 = 31 - UInt32(Float.significandBitCount)
> self = Float(v >> shifts) * (.ulpOfOne/2)
> }
> init(unitRange v: UInt16) {
> let a = Float(v) + 0.5
> let b = Float(UInt16.max) + 1.0
> self = a / b
> }
> init(unitRange v: UInt8) {
> let a = Float(v) + 0.5
> let b = Float(UInt8.max) + 1.0
> self = a / b
> }
> }
> 
> You will get a very fast and good quality prng using xoroshiro, converting to 
> unit range floating point and then back to uniform range int if you want to, 
> much much faster than arc4random.
> 
> /Jens
> 
> 
> 
> 
> On Mon, May 22, 2017 at 11:17 PM, Jens Persson  <mailto:j...@bitcycle.com>> wrote:
> Check out the generators (especially xoroshiro) on this site:
> 
> On Mon, May 22, 2017 at 6:54 PM, Saagar Jha via swift-users 
> mailto:swift-users@swift.org>> wrote:
> 
> Saagar Jha
> 
>> On May 22, 2017, at 08:44, Edward Connell via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> Any ideas when Foundation on Linux will support arc4random_uniform? This is 
>> kind of an important function.
>> There doesn't seem to be any decent substitute without requiring the 
>> installation of libbsd-dev, which turns out to be messy. Currently I am 
>> doing this, but glibc random with mod does not produce good quality numbers, 
>> due to modulo bias.
> 
> Modulo bias is easy to deal with, though, if you force random to produce a 
> range that is a multiple of the range that you’re trying to produce:
> 
> guard range > 0 else { return 0 }
> var random: Int
> repeat {
>   random = Int(random())
> } while(random > LONG_MAX / range * range)
> return random % range
> 
>> 
>> Has anyone come up with a better solution to get a true uniform distribution 
>> that isn't super messy?
>>  
>> import Foundation
>> 
>> #if os(Linux)
>>  import Glibc
>> #endif
>> 
>> 
>> public func random_uniform(range: Int) -> Int {
>>  guard range > 0 else { return 0 }
>>  #if os(Linux)
>>return Int(random()) % range
>>  #else
>>return Int(arc4random_uniform(UInt32(range)))
>>  #endif
>> }
>> 
>> 
>> Thanks, Ed
>> _

Re: [swift-users] arc4random_uniform on Linux is missing from Foundation??

2017-05-22 Thread Saagar Jha via swift-users

Saagar Jha

> On May 22, 2017, at 08:44, Edward Connell via swift-users 
>  wrote:
> 
> Any ideas when Foundation on Linux will support arc4random_uniform? This is 
> kind of an important function.
> There doesn't seem to be any decent substitute without requiring the 
> installation of libbsd-dev, which turns out to be messy. Currently I am doing 
> this, but glibc random with mod does not produce good quality numbers, due to 
> modulo bias.

Modulo bias is easy to deal with, though, if you force random to produce a 
range that is a multiple of the range that you’re trying to produce:

guard range > 0 else { return 0 }
var random: Int
repeat {
random = Int(random())
} while(random > LONG_MAX / range * range)
return random % range

> 
> Has anyone come up with a better solution to get a true uniform distribution 
> that isn't super messy?
>  
> import Foundation
> 
> #if os(Linux)
>   import Glibc
> #endif
> 
> 
> public func random_uniform(range: Int) -> Int {
>   guard range > 0 else { return 0 }
>   #if os(Linux)
> return Int(random()) % range
>   #else
> return Int(arc4random_uniform(UInt32(range)))
>   #endif
> }
> 
> 
> Thanks, Ed
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift localisation, percentage sign escaping

2017-05-11 Thread Saagar Jha via swift-users
Interpolation doesn’t need escaping, but String(format:) does.

Saagar Jha

> On May 11, 2017, at 02:44, Adam Sutcliffe via swift-users 
>  wrote:
> 
> Hi,
> 
> I've been having an issue with a localised string,, one of which has a 
> percentage sign in it:
> 
> "GAMERANK_5_DESC" = "Wow! You're racing ahead. Only 5%% of our users get 
> here!";
> 
> the key is built as such:
> 
> Obj-c : NSString *key = [NSString stringWithFormat:@"GAMERANK_%@_DESC",rank];
> 
> Swift: let key = "GAMERANK_\(rank)_DESC"
> 
> Then localised with the same macro:  NSLocalizedString(key, @"");
> 
> The output is different though:
> 
> Obj- C = "Wow! You're racing ahead. Only 5% of our users get here!"
> Swift = "Wow! You're racing ahead. Only 5%% of our users get here!"
> 
> Is this a bug in the swifts localisation parsing? Does the percentage sign 
> not need to be escaped in Swift?
> 
> Cheers
> 
> -- 
> 
> –
> ADAM SUTCLIFFE
> Software Engineer
> 
> –
> +44 (0)7786 692 639 <>
> a...@peak.net 
> peak.net ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] optional variable with ternary operator

2017-05-08 Thread Saagar Jha via swift-users
This functionality was removed via SE-0121, back in the Swift 3 timeframe.

Saagar Jha

> On May 8, 2017, at 19:49, Zhao Xin  wrote:
> 
> I wonder if it has ever been allowed? I am using Xcode and it never allows 
> that. 
> For you specific question, you can use
> 
> var number:Int?
> let result = (number ?? -1) > 0 ? 1 : 2
> 
> Zhaoxin
> 
> On Tue, May 9, 2017 at 1:39 AM, Erica Sadun via swift-users 
> mailto:swift-users@swift.org>> wrote:
> I believe this falls under "future directions" for comparison reform.
> 
> Here's an example of a short term solution: 
> https://gist.github.com/erica/77b110e17e51dbea7d6934e6582f627f 
> 
> 
> -- E, who moved this from SE to Swift Users
> 
> 
>> On May 8, 2017, at 10:13 AM, Saagar Jha via swift-evolution 
>> mailto:swift-evolut...@swift.org>> wrote:
>> 
>> Well, you’re not allowed to compare optionals any more. You can try binding 
>> the value to an Int, so that it’s not an optional anymore:
>> 
>> if let number = number {
>>  let result = number > 0 ? 1 : 2
>> }
>> 
>> Either way, you’ll have to decide what you think should happen when number 
>> is nil.
>> 
>> Saagar Jha
>> 
>>> On May 8, 2017, at 00:36, Suresh Kansujiya via swift-evolution 
>>> mailto:swift-evolut...@swift.org>> wrote:
>>> 
>>> Hey,
>>> 
>>> i am using ternary operator with optional variable. like below ex.
>>> 
>>> var number:Int?
>>> let result = number > 0 ? 1 : 2  
>>> here i am getting this waring : comparison operators with optionals were 
>>> removed from the Swift Standard Library. Consider refactoring the code to 
>>> use the non-optional operators
>>> 
>>> Note : i must need to use ternary operator for checking.
>>> 
>>> Regards
>>> Suresh Kansujiya
>>> ___
>>> swift-evolution mailing list
>>> swift-evolut...@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-evolution 
>>> 
>> 
>> ___
>> swift-evolution mailing list
>> swift-evolut...@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-evolution 
>> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


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

2017-05-01 Thread Saagar Jha via swift-users

Saagar Jha

> On May 1, 2017, at 14:08, Rick Mann  wrote:
> 
>> 
>> 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  wrote:
 
 
 Saagar Jha
 
> On Apr 21, 2017, at 04:35, Rick Mann via swift-users 
>  wrote:
> 
> I have a debugLog() method that looks like this:
> 
> func
> debugLog(_ inMsg: T, _ inFile : String = #file, _ inLine : Int = #line)
 
 Well, for starters, I don’t see why you need to make this function 
 generic. Why not make inMsg an `Any?`?
>>> 
>>> So I can write debugLog()
>> 
>> Have you tried using `Any?`? You can pass in other stuff…
> 
> That's probably fine. I just took it from some example somewhere.
> 
>> 
>>> 
 
> {
>   let df = DateFormatter()
>   df.dateFormat = "-MM-dd HH:mm:ss.SSS"
>   let time = df.string(from: Date())
>   
>   let file = (inFile as NSString).lastPathComponent
>   print("\(time) \(file):\(inLine)\(inMsg)”)
 
 Try \(inMsg ?? “nil”).
>>> 
>>> No, this is missing the point. I don't want to have to write this 
>>> everywhere. I just want to tell the compiler not to issue the warning in 
>>> these cases, much in the way you can tell the compiler to check printf 
>>> format specifiers.
>> 
>> The fundamental issue here is that printing an Optional is probably not what 
>> you want to do, since it will print Optional(“your wrapped value”). If this 
>> is what you want, you will need to be explicit with String(describing:); if 
>> not, then use the nil coalescing operator to fallback to a value you want. 
>> You can also try guaranteeing that the value is not an optional by 
>> unwrapping it.
> 
> What I'm trying to avoid is dealing with it at the call site. I have to do 
> that every time, and for printing of debug messages, "Optional()" is fine 
> (although I have a proposal in mind to address that, too; I'd much rather 
> just see "nil”)

Hmm, your code doesn’t seem to have any warnings anymore…

> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Flatmap initializer inconsistency

2017-05-01 Thread Saagar Jha via swift-users
Well, the question still remains about why the compiler chose init(exactly:) 
over init(). Shouldn’t there at least a warning of ambiguity?

Saagar Jha

> On May 1, 2017, at 12:11, Zhao Xin via swift-users  
> wrote:
> 
> 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 
> mailto:swift-users@swift.org>> wrote:
> 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
> proper value of 662. Is there something I'm misunderstanding, or is
> this a swift bug?
> 
> Thanks,
> Halen
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


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

2017-04-30 Thread Saagar Jha via swift-users
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 > > wrote:
>> 
>> 
>> Saagar Jha
>> 
>>> On Apr 21, 2017, at 04:35, Rick Mann via swift-users >> > wrote:
>>> 
>>> I have a debugLog() method that looks like this:
>>> 
>>> func
>>> debugLog(_ inMsg: T, _ inFile : String = #file, _ inLine : Int = #line)
>> 
>> Well, for starters, I don’t see why you need to make this function generic. 
>> Why not make inMsg an `Any?`?
> 
> So I can write debugLog()

Have you tried using `Any?`? You can pass in other stuff…

> 
>> 
>>> {
>>> let df = DateFormatter()
>>> df.dateFormat = "-MM-dd HH:mm:ss.SSS"
>>> let time = df.string(from: Date())
>>> 
>>> let file = (inFile as NSString).lastPathComponent
>>> print("\(time) \(file):\(inLine)\(inMsg)”)
>> 
>> Try \(inMsg ?? “nil”).
> 
> No, this is missing the point. I don't want to have to write this everywhere. 
> I just want to tell the compiler not to issue the warning in these cases, 
> much in the way you can tell the compiler to check printf format specifiers.

The fundamental issue here is that printing an Optional is probably not what 
you want to do, since it will print Optional(“your wrapped value”). If this is 
what you want, you will need to be explicit with String(describing:); if not, 
then use the nil coalescing operator to fallback to a value you want. You can 
also try guaranteeing that the value is not an optional by unwrapping it.

> 
>> 
>>> }
>>> 
>>> Is there any way to decorate it so that string interpolation of optionals 
>>> passed to it inMsg don't produce the warning about using debugDescription? 
>>> In the case of debug logging, that's completely acceptable, and I don't 
>>> want to have to write String(describing:) everywhere.
>>> 
>>> 
>>> -- 
>>> Rick Mann
>>> rm...@latencyzero.com
>>> 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] UIview frame and bounds properties

2017-04-27 Thread Saagar Jha via swift-users
The issue is that frame and bounds are only known after the initializer is run. 
Properties are set before the initializer, and they have can’t access frame and 
bounds.

Saagar Jha

> On Apr 27, 2017, at 10:32, Mohamed Salah via swift-users 
>  wrote:
> 
> yes I tried self. but it didn’t work as well …. 
> 
>> On Apr 27, 2017, at 9:30 PM, Adrian Zubarev > > wrote:
>> 
>> Have you tried using self.? It’s a good practice to always using self. to 
>> avoid issues where the compiler might use other globally available 
>> variables/constants functions.
>> 
>> 
>> 
>> 
>> -- 
>> Adrian Zubarev
>> Sent with Airmail
>> 
>> Am 27. April 2017 um 19:28:42, Mohamed Salah via swift-users 
>> (swift-users@swift.org ) schrieb:
>> 
>>> Thanks for your support … here you are the piece of code 
>>> 
>>> 
>>> 
>>> import UIKit
>>> 
>>> class FaceVeiw: UIView {
>>> 
>>> /* it make error to use frame or bounds outside any functions  WHY WHY 
>>> WHY */
>>> 
>>> let width = frame.size.width // (Gives an ERROR) frame property is not 
>>> known here
>>> let width2 = bounds.size.width // Gives an ERROR) bound property is not 
>>> know here as well
>>> 
>>> 
>>> override func draw(_ rect: CGRect)
>>> {
>>> let w = bounds.size.width // however bounds is known here
>>> let h = bounds.size.height
>>> 
>>> let w2 = frame.size.width // frame as well known here
>>> let h2 = frame.size.height
>>> 
>>> }
>>> 
>>> 
>>> }
>>> 
>>> 
 On Apr 27, 2017, at 9:23 PM, Saagar Jha >>> > wrote:
 
 Would you mind sharing the code you’re having trouble with?
 
 Saagar Jha
 
> On Apr 27, 2017, at 10:22, Mohamed Salah via swift-users 
> mailto:swift-users@swift.org>> wrote:
> 
> Hi ,
> 
> why UIview frame and bounds properties are not seen outside any functions 
> ?
> 
> please advise
> 
> thank you
> Mohamed Salah
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] UIview frame and bounds properties

2017-04-27 Thread Saagar Jha via swift-users
Would you mind sharing the code you’re having trouble with?

Saagar Jha

> On Apr 27, 2017, at 10:22, Mohamed Salah via swift-users 
>  wrote:
> 
> Hi , 
> 
> why UIview frame and bounds properties are not seen outside any functions ? 
> 
> please advise
> 
> thank you 
> Mohamed Salah 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


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

2017-04-22 Thread Saagar Jha via swift-users

Saagar Jha

> On Apr 21, 2017, at 04:35, Rick Mann via swift-users  
> wrote:
> 
> I have a debugLog() method that looks like this:
> 
> func
> debugLog(_ inMsg: T, _ inFile : String = #file, _ inLine : Int = #line)

Well, for starters, I don’t see why you need to make this function generic. Why 
not make inMsg an `Any?`?

> {
>   let df = DateFormatter()
>   df.dateFormat = "-MM-dd HH:mm:ss.SSS"
>   let time = df.string(from: Date())
>   
>   let file = (inFile as NSString).lastPathComponent
>   print("\(time) \(file):\(inLine)\(inMsg)”)

Try \(inMsg ?? “nil”).

> }
> 
> Is there any way to decorate it so that string interpolation of optionals 
> passed to it inMsg don't produce the warning about using debugDescription? In 
> the case of debug logging, that's completely acceptable, and I don't want to 
> have to write String(describing:) everywhere.
> 
> 
> -- 
> Rick Mann
> rm...@latencyzero.com
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Need clarification on Swift CI benchmark

2017-04-20 Thread Saagar Jha via swift-users
Delta is (OLD_MIN - NEW_MIN) / OLD_MIN expressed as a percent; speedup is 
(OLD_MIN - NEW_MIN) / NEW_MIN as a decimal. A negative delta corresponds to a 
speedup less than 1 (i.e the newer one is slower) and a positive delta to a 
speedup greater than one (i.e. the newer one is faster).

Saagar Jha

> On Apr 20, 2017, at 07:48, Proyb P via swift-users  
> wrote:
> 
> What those PR in Swift CI benchmark shown "Regression", "Old_min", "new_min", 
> "delta" and "speedup" really mean? Speedup can be confusing when Delta is 
> either a positive or negative value.
> 
> https://github.com/apple/swift/pull/3796 
> 
> 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] [swift-evolution] Low efficiency multidimensional array problem

2017-04-18 Thread Saagar Jha via swift-users
It might be helpful if you showed a bit more of the code you’re working on, so 
that we can better see what you’re trying to do. Is there any operation in 
particular that is slow?

Also, CC’ing swift-users since I think it belongs there.

Saagar Jha

> On Apr 18, 2017, at 22:57, Hbucius Smith via swift-evolution 
>  wrote:
> 
> Hello Swift community,
> 
> 
> When I used multidimensional array in swift, I found it is very low 
> efficiency.
> 
>   
> I used in the following way : 
> 
>
> var array = Array.init(repeating: Array.init(repeating: 0, count: 5), 
> count: 5)
>
> array[0][0] = 0
> 
>
>   I have read some posts in stack overflow. It suggests using one dimension 
> to fake multidimensional array. I think it is too ugly. DO we have better 
> choice for this ?
> 
> 
> 
> 
> 
> 
> best wishes for you 
> ___
> swift-evolution mailing list
> swift-evolut...@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] how to detect key pressed on linux console app?

2017-04-11 Thread Saagar Jha via swift-users
AFAIK there isn’t a way to do this in Swift; you’ll have to drop down to C and 
use something like getchar or a library like ncurses. If I recall there was 
some discussion a while back about better command-line APIs for Swift but it 
appears that it fizzled out with the Swift 3 deadline and all.

Saagar Jha

> On Apr 10, 2017, at 22:04, Mr Bee via swift-users  
> wrote:
> 
> Hi all,
> 
> I'd like to know how to detect key pressed event on Linux console app using 
> Swift. Not just waiting input like what readLine() is doing, but more like 
> detecting arrow keys, left/right shift key, F1-10 keys, etc simultaneously 
> while the program keep running. You know, something like game input.
> 
> Thank you.
> 
> Regards,
> 
> –Mr Bee
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Set with element of NSObject subclasses didn't work as expected

2017-03-28 Thread Saagar Jha via swift-users
NSObject’s hash (which Set uses) is done via ObjectIdentifier, which IIRC uses 
something along the lines of the object's address. That’s why you’re getting 
the behavior you’re seeing.

Saagar Jha

> On Mar 28, 2017, at 20:20, Zhao Xin via swift-users  
> wrote:
> 
> Turns out that for `NSObject`, protocol `Equatable` wasn't used. Instead, it 
> used `NSObjectProtocol.isEqual(_ object: Any?)`. Also, override `func 
> isEqual(_ object: Any?) -> Bool` requires to override `var hash: Int { get }` 
> as well.
> 
> I think this behavior should be mentioned in Swift docs or manual in `Set` 
> section.
> 
> Below code works. 
> 
> class Bar:NSObject {
> let value:Int
> 
> override public var hashValue: Int { return value }
> public static func ==(lhs: Bar, rhs: Bar) -> Bool {
> return lhs.value == rhs.value
> }
> // required by NSObjectProtocol
> override func isEqual(_ object: Any?) -> Bool {
> if let rhs = object as? Bar {
> return self == rhs
> }
> return false
> }
> override var hash: Int { return self.hashValue }
> 
> init(_ value:Int) {
> self.value = value
> }
> }
> 
> let barSetA:Set = [Bar(8), Bar(9)]
> let barSetB:Set = [Bar(9), Bar(10)]
> let barResultC = barSetA.intersection(barSetB) // {{NSObject, value 9}}
> let barResultD = barSetA.subtracting(barSetB) // {{NSObject, value 8}}
> 
> Gladly I find it here 
> .
>  
> 
> Zhaoxin
> 
> 
> 
> On Wed, Mar 29, 2017 at 3:50 AM, Zhao Xin  > wrote:
> Please see the code first.
> 
> import Foundation
> 
> class Foo:Hashable {
> let value:Int
> 
> public var hashValue: Int { return value }
> public static func ==(lhs: Foo, rhs: Foo) -> Bool {
> return lhs.value == rhs.value
> }
> 
> init(_ value:Int) {
> self.value = value
> }
> }
> 
> let fooSetA:Set = [Foo(8), Foo(9)]
> let fooSetB:Set = [Foo(9), Foo(10)]
> let fooResultC = fooSetA.intersection(fooSetB) // {{value 9}}
> let fooResultD = fooSetA.subtracting(fooSetB) // {{value 8}}
> 
> 
> class Bar:NSObject {
> let value:Int
> 
> override public var hashValue: Int { return value }
> public static func ==(lhs: Bar, rhs: Bar) -> Bool {
> return lhs.value == rhs.value
> }
> 
> init(_ value:Int) {
> self.value = value
> }
> }
> 
> let barSetA:Set = [Bar(8), Bar(9)]
> let barSetB:Set = [Bar(9), Bar(10)]
> let barResultC = barSetA.intersection(barSetB) // Set([])
> let barResultD = barSetA.subtracting(barSetB) // {{NSObject, value 9}, 
> {NSObject, value 8}}
> 
> 
> Behaviors of `func intersection(Set)` and `func 
> subtracting(Set)` were different between normal Swift class and 
> NSObject subclasses. I had thought they should be the same. It seemed that 
> Set relied on addresses of NSObject instances instead of their 
> hashValues. That made the Set useless.
> 
> Swift version: 3.1 (swiftlang-802.0.48 clang-802.0.48)
> Xcode 8.3 (8E162)
> 
> Zhaoxin
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


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/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.
> >
> >
> > 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() else { findReasonAndTerminate() }
> >
> >
> > On Fri, Mar 24, 2017 at 3:02 AM, Rien via swift-users <
> swift-users@swift.org> wrote:
> > 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 findReasonAndTerminate() {
> >let reason: String = ….
> >fatalError(reason)
> > }
> >
> > main.swift:
> >
> > guard let data = buildData() else { findReasonAndTerminate() }
> >
> >
> > Currently the work around is to add another fatalError like this:
> >
> > guard let data = buildData() else { findReasonAndTerminate(); fatalError
> }
> >
> >
> > but it would be nice to have some attribute like @noReturn:
> >
> > @noReturn
> > func findReasonAndTerminate() { … }
> >
> >
> > Regards,
> > Rien
> >
> > Site: http://balancingrock.nl
> > Blog: http://swiftrien.blogspot.com
> > Github: http://github.com/Balancingrock
> > Project: http://swiftfire.nl
> >
> >
> >
> >
> >
> > ___
> > swift-users mailing list
> > swift-users@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
> >
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Need a way to include swift file into another swift file

2017-02-27 Thread Saagar Jha via swift-users
Hmm, what are you trying to do? The generally accepted way of splitting code 
between files is through the use of extensions; is this not sufficient for your 
needs?

Saagar Jha

> On Feb 27, 2017, at 02:45, Rupendra Limbore via swift-users 
>  wrote:
> 
> Hi All,
> 
> I am using swift as a CGI script with Apache server (just to explore). I need 
> to split my code into different files so as to make it more manageable. Is 
> there any way I can include one swift file into another, like we can do in 
> PHP with “include_once”?
> 
> 
> 
> Best Regards,
> Rupendra Limbore
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Assigning a variable to itself

2017-02-21 Thread Saagar Jha via swift-users
It appears that trying to assign a variable to itself is an error:

var foo = 5
foo = foo // error: assigning a variable to itself

However, I was thinking about this and was wondering why this is an error and 
not a warning. If, for example, the assignment had a side effect (e.g. a didSet 
block) I’d think it would be warning, possibly ignorable with a set of 
parentheses. Thoughts?

Saagar Jha

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Associativity of && and || operator

2017-02-17 Thread Saagar Jha via swift-users
Left associativity is most likely just a holdover from the C family–not 
conforming with it would break expectations for programmers coming from these 
languages. And as you mentioned, the compiler will short-circuit the condition 
and stop evaluating as soon as it encounters a false condition, so there’s no 
measurable benefit.

Saagar Jha

> On Feb 17, 2017, at 12:54 AM, rintaro ishizaki via swift-users 
>  wrote:
> 
> Hello all,
> 
> Why the associativity of Logical{Conjunction,Disjunction}Precedence is "left"?
> 
> If you write: A && B && C, it's grouped as (A && B) && C.
> This means that the && function is always called twice: (&&)((&&)(A, B), C).
> I feel "right" associativity is more natural:  (&&)(A, (&&)(B, C)),
> because the && function is called only once if A is false.
> 
> I know that redundant && calls are optimized away in most cases.
> I also know C and C++ standard says: "The && operator groups left-to-right", 
> and most programming languages follow that.
> 
> But why not "right" associativity?
> What is the difference between logical operators and ?? operator that has 
> "right" associativity?
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] ambiguous minus operator

2017-02-16 Thread Saagar Jha via swift-users
DispatchTimeInterval.nanoseconds expects an Int, while uptimeNanoseconds is an 
UInt64 (an thus so is their difference). You can “fix” this by adding an 
explicit cast:

func -(time1: DispatchTime, time2: DispatchTime) -> DispatchTimeInterval {
return DispatchTimeInterval.nanoseconds(Int(time2.uptimeNanoseconds - 
time1.uptimeNanoseconds))
}

However, you will need to perform checking for when time2 < time1 and then the 
difference doesn’t fit in an Int–these will cause crashes.

Saagar Jha

> On Feb 16, 2017, at 7:56 AM, J.E. Schotsman via swift-users 
>  wrote:
> 
> Hello,
> 
> I am trying to define an operator that subtracts dispatch times:
> 
> #import Dispatch
> 
> func -( time1: DispatchTime, time2: DispatchTime ) -> DispatchTimeInterval
>   {
>   return DispatchTimeInterval.nanoseconds( time2.uptimeNanoseconds - 
> time1.uptimeNanoseconds )
>   }
> 
> Compiler says: Ambiguous use of operator ‘-'
> Found this candidate
> Found this candidate
> 
> As usual the candidates are unknown.
> 
> What am I doing wrong?
> 
> Jan E.
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Rational behind having 2 different behaviors for flatMap?

2017-02-13 Thread Saagar Jha via swift-users
Hmm, it looks like you’re right. I could swear I’ve used flatMap without a 
closure before…oh well, looks like that’s what happens when you send code 
without running it in a Playground.

Saagar Jha

> On Feb 13, 2017, at 5:33 PM, Jon Shier  wrote:
> 
> According to the compiler, the closure argument for flatMap is not optional 
> or defaulted, so it’s always required. I think it should default to { $0 }, 
> but whatever.
> 
> 
> Jon
> 
>> On Feb 13, 2017, at 8:26 PM, Saagar Jha via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> flatMap was designed to work this way. How I rationalize it is that flatMap 
>> “extracts” the value from an array’s elements and expands it. For an Array, 
>> this is just taking out the individual Elements, but for an Optional, which 
>> a “wrapper” around one value, it just takes this value out. Optionals with 
>> no value (the .none case, or nil as it’s more commonly known) have nothing 
>> to contribute and thus are filtered out.
>> 
>> Saagar Jha
>> 
>> P.S. You can call flatMap without a closure: deep.flatMap().flatMap()
>> 
>>> On Feb 13, 2017, at 4:31 PM, Maxim Veksler via swift-users 
>>> mailto:swift-users@swift.org>> wrote:
>>> 
>>> Hi everyone,
>>> 
>>> I've discovered today that Swift will actually choose 2 very differently 
>>> behaving types of flatMap implementation based on the input signature. 
>>> 
>>> For a Sequence of options it will call a flatMap that filters out nil's. 
>>> For a Sequence of Sequence's it will call a flattening function, without 
>>> filtering.
>>> 
>>> Leading to code that (IMHO) reads very not inconsistency, and unexpected. 
>>> Sometime even looking a bit funny such as collection.flatMap.flatMap:
>>> 
>>>   5> let deep = [["1989", nil], [nil, "Red"], [nil, nil]]
>>> deep: [[String?]] = 3 values {
>>>   [0] = 2 values {
>>> [0] = "1989"
>>> [1] = nil
>>>   }
>>>   [1] = 2 values {
>>> [0] = nil
>>> [1] = "Red"
>>>   }
>>>   [2] = 2 values {
>>> [0] = nil
>>> [1] = nil
>>>   }
>>> }
>>>   6> deep.flatMap { $0 }
>>> $R1: [String?] = 6 values {
>>>   [0] = "1989"
>>>   [1] = nil
>>>   [2] = nil
>>>   [3] = "Red"
>>>   [4] = nil
>>>   [5] = nil
>>> }
>>>   7> deep.flatMap { $0 }.flatMap { $0 }
>>> $R2: [String] = 2 values {
>>>   [0] = "1989"
>>>   [1] = "Red"
>>> }
>>> I wonder why it was implemented this way?
>>> 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org <mailto:swift-users@swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> <https://lists.swift.org/mailman/listinfo/swift-users>
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org <mailto:swift-users@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Rational behind having 2 different behaviors for flatMap?

2017-02-13 Thread Saagar Jha via swift-users
flatMap was designed to work this way. How I rationalize it is that flatMap 
“extracts” the value from an array’s elements and expands it. For an Array, 
this is just taking out the individual Elements, but for an Optional, which a 
“wrapper” around one value, it just takes this value out. Optionals with no 
value (the .none case, or nil as it’s more commonly known) have nothing to 
contribute and thus are filtered out.

Saagar Jha

P.S. You can call flatMap without a closure: deep.flatMap().flatMap()

> On Feb 13, 2017, at 4:31 PM, Maxim Veksler via swift-users 
>  wrote:
> 
> Hi everyone,
> 
> I've discovered today that Swift will actually choose 2 very differently 
> behaving types of flatMap implementation based on the input signature. 
> 
> For a Sequence of options it will call a flatMap that filters out nil's. For 
> a Sequence of Sequence's it will call a flattening function, without 
> filtering.
> 
> Leading to code that (IMHO) reads very not inconsistency, and unexpected. 
> Sometime even looking a bit funny such as collection.flatMap.flatMap:
> 
>   5> let deep = [["1989", nil], [nil, "Red"], [nil, nil]]
> deep: [[String?]] = 3 values {
>   [0] = 2 values {
> [0] = "1989"
> [1] = nil
>   }
>   [1] = 2 values {
> [0] = nil
> [1] = "Red"
>   }
>   [2] = 2 values {
> [0] = nil
> [1] = nil
>   }
> }
>   6> deep.flatMap { $0 }
> $R1: [String?] = 6 values {
>   [0] = "1989"
>   [1] = nil
>   [2] = nil
>   [3] = "Red"
>   [4] = nil
>   [5] = nil
> }
>   7> deep.flatMap { $0 }.flatMap { $0 }
> $R2: [String] = 2 values {
>   [0] = "1989"
>   [1] = "Red"
> }
> I wonder why it was implemented this way?
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] for with optional collection?

2017-02-09 Thread Saagar Jha via swift-users
Or even

for item in someOptionalCollection ?? [] {
item.doSomething()
}

Saagar Jha

> On Feb 9, 2017, at 1:30 PM, Jeff Kelley via swift-users 
>  wrote:
> 
> You can do something like this:
> 
> someOptionalCollection?.forEach { item in
>   item.doSomething()
> }
> 
> Or this:
> 
> (someOptionalCollection as? [SomeType])?.forEach { item in
>   item.doSomething()
> }
> 
> Jeff Kelley
> 
> slauncha...@gmail.com  | @SlaunchaMan 
>  | jeffkelley.org 
>> On Feb 9, 2017, at 4:26 PM, Rick Mann via swift-users > > wrote:
>> 
>> Is there any concise way to write the following?
>> 
>> if let collection = someOptionalCollection
>> {
>>for item in collection
>>{
>>}
>> }
>> 
>> I can imagine more complicated things, too:
>> 
>> if let collection = someOptionalCollection as? [SomeType]
>> {
>>for item in collection
>>{
>>}
>> }
>> 
>> It would be nice to be able to just attempt to iterate on an optional 
>> collection (or Sequence?) and not have to write the enclosing if block
>> 
>> Thanks!
>> 
>> -- 
>> Rick Mann
>> rm...@latencyzero.com 
>> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] unsafeBitCast to Unimplemented Class

2017-02-07 Thread Saagar Jha via swift-users

Saagar Jha

> On Feb 6, 2017, at 10:57 PM, Andrew Trick  wrote:
> 
> 
>> On Feb 6, 2017, at 8:51 PM, Dave Abrahams  wrote:
>> 
>> 
>> on Mon Feb 06 2017, Andrew Trick  wrote:
>> 
>>> Is a missing declaration a use case that needs to be supported?
>> 
>> I couldn't say.
>> 
>>> Wouldn’t it be more proper to use selector based dispatch in those
>>> cases?
>> 
>> Example, please?  I don't know what that means, though I probably should.
>> 
>> -- 
>> -Dave
> 
> I phrased that as a question because I'm the last person who should be giving 
> advice here... What I had in mind is this:
> 
> if ([self isKindOfClass:NSClassFromString(@“Bar”)]) {
>  self.perform(@selector(FakeBarProtocol.foo))
> }
> 
> It's not type safe, but it's a lot better than outright lying about the 
> reference's dynamic type.
> 
> Of course, the root problem is that Bar's declaration is unavailable, and 
> that's not a normal, expected thing.

Yep, it’s not–that’s why I need to go through this trouble :) My plugin is 
loaded at runtime, so the headers are the best I’ve got (though if you’ve got a 
way to perform a stricter check, I’m all ears!) Until then, all of these 
methods appear to be sugarcoating around perform(selector:)–is there any 
“preferred” way to do this?

Also, class_getName(_:) seems to return a UnsafePointer, is this just a 
C-style string? Should I use this over NSStringFromClass or isKindOfClass?

> 
> -Andy
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] unsafeBitCast to Unimplemented Class

2017-02-04 Thread Saagar Jha via swift-users
Thanks–your not only did you method work, it had the side effect of obviating 
the need for a Bridging Header. One more thing: what happens if self isn’t a 
Bar (crash, I’m guessing)? Is there a way to compare the type of self, other 
than using `is` (which has the same issue as unsafeBitCast in that I don’t have 
the declaration for it)?

Saagar Jha

> On Feb 4, 2017, at 4:02 PM, Dave Abrahams via swift-users 
>  wrote:
> 
> 
> on Fri Feb 03 2017, Saagar Jha  > wrote:
> 
>> Hello,
>> 
>> I’m having an issue migrating some old Objective-C code that looks like this:
>> 
>> @implementation Foo
>> 
>> - (void)load {
>>  // Swizzle one of Bar’s methods to call Foo’s baz method
>> }
>> 
>> - (void)baz {
>>  [self baz];
>>  if ([self isKindOfClass:NSClassFromString(@“Bar”)]) {
>>  Bar *bar = (Bar *)self; // I can’t migrate this
>>  // work with bar
>>  }
>> }
>> 
>> @end
>> 
>> I’m trying to cast self to a Bar at runtime, and use it to call Bar’s 
>> methods. Sounds like an easy
>> to task for unsafeBitCast, right? The issue is that I don’t have access to 
>> the implementation of
>> Bar’s class at compile time (this is a plugin, so it’s loaded by another 
>> application which contains
>> Bar). In Objective-C I can create a header and stick a dummy interface for 
>> Bar in it; the cast will
>> work if Bar exists at runtime. However, in Swift, unsafeBitCast requires me 
>> to use Bar.self, which
>> does not exist. Is there any way to get this cast to work?
> 
> Bar.self exists if you have a declaration of it exposed to swift, which
> would be required for all the “work with bar” code above.  If you don't
> have Bar.self, it's because there's no declaration visible to your Swift
> code.  My usual workaround would be to declare an @objc protocol having
> the bar APIs you want to use, and then cast self to an instance of that
> @objc protocol.  The right way to do that is by using
> UnsafePointer.withMemoryRebound(to: ), e.g.
> 
>  var mutableSelf = self // can't get pointer to immutable value
>  withUnsafePointer(to: &mutableSelf) { selfPtr in
>selfPtr.withMemoryRebound(to: BarProtocol, capacity: 1) { barPtr in
>  let bar = barPtr.pointee
>  // work with bar
>}
>  }
> 
> HTH,
> 
> -- 
> -Dave
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] unsafeBitCast to Unimplemented Class

2017-02-03 Thread Saagar Jha via swift-users
Hello,

I’m having an issue migrating some old Objective-C code that looks like this:

@implementation Foo

- (void)load {
// Swizzle one of Bar’s methods to call Foo’s baz method
}

- (void)baz {
[self baz];
if ([self isKindOfClass:NSClassFromString(@“Bar”)]) {
Bar *bar = (Bar *)self; // I can’t migrate this
// work with bar
}
}

@end

I’m trying to cast self to a Bar at runtime, and use it to call Bar’s methods. 
Sounds like an easy to task for unsafeBitCast, right? The issue is that I don’t 
have access to the implementation of Bar’s class at compile time (this is a 
plugin, so it’s loaded by another application which contains Bar). In 
Objective-C I can create a header and stick a dummy interface for Bar in it; 
the cast will work if Bar exists at runtime. However, in Swift, unsafeBitCast 
requires me to use Bar.self, which does not exist. Is there any way to get this 
cast to work?

Thanks,
Saagar Jha

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 101: JSON or XML?

2017-02-03 Thread Saagar Jha via swift-users
Either should be fine, but in my experience JSON is a lot easier to work with 
due as compared to XML since JSONSerialization being simpler than XMLParser.

Saagar Jha

> On Feb 3, 2017, at 5:00 AM, Roy Henderson via swift-users 
>  wrote:
> 
> Hi,
> 
> I'm about to develop my first non-trivial (for me) Swift 3 app. It will 
> retrieve data from a web server and present it on an iOS device.
> 
> I would welcome guidance regarding whether I should use JSON or XML to store 
> the data on the web server? The effort to generate either format will be 
> similar so my real decision driver is on the client side. Volume will 
> typically be 100-250 "records" per request with each record comprising 5-10 
> text fields.
> 
> I don't want to pull in any third-party components but stay entirely Apple.
> 
> TIA,
> 
> Roy
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Initializers

2017-01-27 Thread Saagar Jha via swift-users
You can’t override a designated initializer with one that is failable. The 
second one is defining a new initializer that is failable, instead of 
overriding the one from its superclass.

Saagar Jha

> On Jan 27, 2017, at 8:45 AM, tuuranton--- via swift-users 
>  wrote:
> 
> See the comments. Why is one allowed but the other one isn't and what's the 
> rationale for this?
> 
> 
> class Vehicle {
> let name: String
> init(name: String) {
> self.name = name
> }
> }
> 
> 
> class Car: Vehicle {
> //Why is this not allowed?
> override init?(name: String) {
> super.init(name: name)
> }
> 
> //But this is allowed?
> init?(name: String, ignore: String) {
> super.init(name: name)
> }
> }
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Is this valid Swift 3 (and later) code?

2017-01-20 Thread Saagar Jha via swift-users
This will fail to compile; it’s a bit too close to Java to work. In particular, 
in Swift you can’t pass a class into a function like invokeLater does; instead, 
Swift uses closures, which Java lacks and must make up with anonymous classes.

Saagar Jha

> On Jan 20, 2017, at 4:16 PM, Ethin Probst via swift-users 
>  wrote:
> 
> Is the following code valid swift 3 (and later) code? If not, is it
> translatable to swift 3? This was translated using Elements Oxidizer
> (http://elementscompiler.com/elements/oxidizer.aspx) using the Hello
> World Java Swing application
> (https://docs.oracle.com/javase/tutorial/displayCode.html?code=https://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java
> and 
> https://docs.oracle.com/javase/tutorial/uiswing/examples/start/HelloWorldSwingProject/src/start/HelloWorldSwing.java).
> It will run in RemObjects Silver in Visual Studio, but is it valid
> Swift 3 code? You don't have to try and compile it--as Elements is the
> only platform that compiles Swift to the JVM (I think?) but does it
> follow the Swift 3 language specification (or the latest version,
> whatever that may be)?
> Code:
> [start code]
> import javax.swing
> 
> public class HelloWorldSwing {
>   private static func createAndShowGUI() {
>   //Create and set up the window.
>   var frame: JFrame! = JFrame("HelloWorldSwing")
>   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
>   //Add the ubiquitous "Hello World" label.
>   var label: JLabel! = JLabel("Hello World")
>   frame.getContentPane().add(label)
>   //Display the window.
>   frame.pack()
>   frame.setVisible(true)
>   }
> 
>   public static func main(_ args: String![]) {
>   //Schedule a job for the event-dispatching thread:
>   //creating and showing this application's GUI.
>   javax.swing.SwingUtilities.invokeLater(class Runnable {
>   func run() {
>   createAndShowGUI()
>   }
>   })
>   }
> }
> [end code]
> -- 
> Signed,
> Ethin D. Probst
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Introduction

2017-01-13 Thread Saagar Jha via swift-users
I’m not a web developer, but have you taken a look at third-party frameworks 
like Vapor ?

Saagar Jha

> On Jan 13, 2017, at 7:28 AM, Greg Wocher via swift-users 
>  wrote:
> 
> Greetings all,
> I am new to the Swift language. I have a background in Windows development. I 
> have developed a bit in C#, asp.net , HTML, CSS, Java script 
> and Java. I have a degree in Computer Information Systems. I am also blind 
> and use Voiceover on my Mac. I have recently switched to the Mac from 
> Windows. I do have a quick question. Is it possible to develop web apps using 
> Swift similar to what you can do with asp.net  and visual 
> studio on the Windows side?
> 
> Regards,
> Greg Wocher
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] [unrelated-to-swift] an issue with structs in C++?

2017-01-11 Thread Saagar Jha via swift-users
Looks like someone’s trying to solve the Mt. Chiliad Mystery :) Anyways, it 
appears that “Epsilon Building” has 5 members instead of 4. That’s probably 
causing the issue.

Saagar Jha

> On Jan 11, 2017, at 8:46 PM, Ethin Probst via swift-users 
>  wrote:
> 
> Hello all,
> I have the following structured array:
>   static struct {
>   LPCSTR text;
>   float x;
>   float y;
>   float z;
>   } lines[5] = {
>   { "MARKER" },
>   { "MICHAEL'S HOUSE", -852.4f, 
> 160.0f, 65.6f },
>   { "FRANKLIN'S HOUSE", 7.9f, 548.1f, 175.5f },
>   { "TREVOR'S TRAILER", 1985.7f, 3812.2f, 32.2f },
>   { "AIRPORT ENTRANCE", -1034.6f, -2733.6f, 13.8f },
>   { "AIRPORT FIELD", -1336.0f, -3044.0f, 13.9f },
>   { "ELYSIAN ISLAND", 338.2f, -2715.9f, 38.5f },
>   { "JETSAM", 760.4f, -2943.2f, 5.8f },
>   { "STRIPCLUB", 127.4f, -1307.7f, 29.2f },
>   { "ELBURRO HEIGHTS", 1384.0f, -2057.1f, 52.0f },
>   { "FERRIS WHEEL", -1670.7f, -1125.0f, 13.0f },
>   { "CHUMASH", -3192.6f, 1100.0f, 20.2f },
>   { "WINDFARM", 2354.0f, 1830.3f, 101.1f },
>   { "MILITARY BASE", -2047.4f, 3132.1f, 32.8f },
>   { "MCKENZIE AIRFIELD", 2121.7f, 4796.3f, 41.1f },
>   { "DESERT AIRFIELD", 1747.0f, 3273.7f, 41.1f },
>   { "CHILLIAD", 425.4f, 5614.3f, 766.5f },
>   {"Strip Club DJ Booth", 126.135f, -1278.583f, 29.270f},
> {"Blaine County Savings Bank", -109.299f, 6464.035f, 31.627f},
> {"Police Station", 436.491f, -982.172f, 30.699f},
> {"Humane Labs Entrance", 3619.749f, 2742.740f, 28.690f},
> {"Burnt FIB Building", 160.868f, -745.831f, 250.063f},
> {"North Yankton Bank", 5309.519f, -5212.375f, 83.522f},
> {"10 Car Garage Back Room", 223.193f, -967.322f, 99.000f},
> {"Humane Labs Tunnel", 3525.495f, 3705.301f, 20.992f},
> {"Ammunation Office", 12.494f, -1110.130f, 29.797f},
> {"Ammunation Gun Range",  22.153f, -1072.854f, 29.797f},
> {"Trevor's Meth Lab", 1391.773f, 3608.716f, 38.942f},
> {"Pacific Standard Bank Vault", 255.851f, 217.030f, 101.683f},
> {"Lester's House", 1273.898f, -1719.304f, 54.771f},
> {"Floyd's Apartment", -1150.703f, -1520.713f, 10.633f},
> {"FIB Top Floor", 135.733f, -749.216f, 258.152f},
> {"IAA Office", 117.220f, -620.938f, 206.047f},
> {"Pacific Standard Bank", 235.046f, 216.434f, 106.287f},
> {"Fort Zancudo ATC entrance", -2344.373f, 3267.498f, 32.811f},
> {"Fort Zancudo ATC top floor", -2358.132f, 3249.754f, 101.451f},
> {"Damaged Hospital", 356.822f, -590.151f, 43.315f},
> {"Slaughterhouse", -80.557f, 6220.006f, 31.090f},
> {"Los Santos County Coroner Office/Morgue", 243.351f, -1376.014f, 39.534f},
> {"Torture Room",  147.170f, -2201.804f, 4.688f},
> {"O'neil Ranch",  2441.216f, 4968.585f, 51.707f},
> {"Main LS Customs", -365.425f, -131.809f, 37.873f},
> {"Yacht", -2023.661f, -1038.038f, 5.577f},
> {"Carrier (MP Only)", 3069.330f, -4704.220f, 15.043f},
> {"Fort Zankudo UFO", 2052.000f, 3237.000f, 1456.973f},
> {"Very High Up", -129.964f, 8130.873f, 6705.307f},
> {"IAA Roof", 134.085f, -637.859f, 262.851f},
> {"FIB Roof", 150.126f, -754.591f, 262.865f},
> {"Maze Bank Roof", -75.015f, -818.215f, 326.176f},
> {"Top of the Mt Chilad", 450.718f, 5566.614f, 806.183f},
> {"Most Northerly Point", 24.775f, 7644.102f, 19.055f},
> {"Vinewood Bowl Stage", 686.245f, 577.950f, 130.461f},
> {"Sisyphus Theater Stage", 205.316f, 1167.378f, 227.005f},
> {"Director Mod Trailer", -20.004f, -10.889f, 500.602f},
> {"Galileo Observatory Roof", -438.804f, 1076.097f, 352.411f},
> {"Kortz Center", -2243.810f, 264.048f, 174.615f},
> {"Chumash Historic Family Pier", -3426.683f, 967.738f, 8.347f},
> {"Paleto Bay Pier", -275.522f, 6635.835f, 7.425f},
> {"God's thumb", -1006.402f, 6272.383f, 1.503f},
> {"Calafia Train Bridge", -517.869f, 4425.284f, 89.795f},
> {"Altruist Cult Camp", -1170.841f, 4926.646f, 224.295f},
> {"Maze Bank Arena Roof", -324.300f, -1968.545f, 67.002f},
> {"Marlowe Vineyards", -1868.971f, 2095.674f, 139.115f},
> {"Hippy Camp", 2476.712f, 3789.645f, 41.226f},
> {"Devin Weston's House", -2639.872f, 1866.812f, 160.135f},
> {"Abandon Mine", -595.342f, 2086.008f, 131.412f},
> {"Weed Farm", 2208.777f, 5578.235f, 53.735f},
> {"Stab City",  126.975f, 3714.419f, 46.827f},
> {"Airplane Graveyard Airplane Tail", 2395.096f, 3049.616f, 60.053f},
> {"Satellite Dish Antenna", 2034.988f, 2953.105f, 74.602f},
> {"Satellite Dishes",  2062.123f, 2942.055f, 47.431f},
> {"Windmill Top", 2026.677f, 1842.684f, 133.313f},
> {"Sandy Shores Building Site Crane", 1051.209f, 2280.452f, 89.727f},
> {"Rebel Radio", 736.153f, 2583.143f, 79.634f},
> {"Quarry", 2954.196f, 2783.410f, 41.004f},
> {"Palmer-Taylor Power Station Chimney",  2

Re: [swift-users] Compiler should issue a warning when a subclass implementation with default values matches a parent implementation without them

2017-01-04 Thread Saagar Jha via swift-users
Ahh, I get what you’re saying now. In this case I’d like to see a warning when 
a “conflicting” function is defined that there may be potential ambiguity.

Saagar Jha



> On Jan 4, 2017, at 8:19 PM, Wagner Truppel  wrote:
> 
> Indeed, and in this case as well the compiler issues no warning even though 
> the ambiguity is evident. I had to try it on a playground to be sure that 
> it’s the parameter-less foo() rather than the default-argumented foo(x:) that 
> gets invoked when we call foo() on an instance.
> 
> Of course, both this ambiguity and the one I started with can be resolved by 
> explicitly calling foo(x: 0) but, as that link points out,  "What is the 
> point of having an optional parameter (a parameter with a default value) if 
> you have to supply it anyway?”
> 
> More importantly, it’s an easy mistake to expect one implementation to be 
> invoked rather than the other, with a potentially costly impact. The compiler 
> has enough information to catch this and I think it should.
> 
> Wagner
> 
> 
>> On 5 Jan 2017, at 03:54, Jacob Bandes-Storch  wrote:
>> 
>> The same ambiguity occurs even without inheritance:
>> 
>> class C {
>>func foo() {}
>>func foo(x: Int = 0) {}
>> }
>> 
>> Somewhat related: https://bugs.swift.org/browse/SR-1408
>> 
>> 
>> On Wed, Jan 4, 2017 at 7:42 PM, Wagner Truppel via swift-users 
>>  wrote:
>> I’m afraid I wasn’t clear enough on my post. The default value I referred to 
>> is the “= 0”. Had it been absent, the call c.foo() would undeniably be 
>> fulfilled by the parent class. However, with the default argument value, 
>> it’s not obvious whether c.foo() should be the parent’s implementation or 
>> the child’s implementation (with the argument set to the default value). 
>> That’s why I’m suggesting a compiler warning because it’s very easy to make 
>> the mistake of calling c.foo() expecting the child’s implementation and it 
>> may be a hard bug to track when it happens.
>> 
>> Wagner
>> 
>> 
>>> On 5 Jan 2017, at 03:35, Saagar Jha  wrote:
>>> 
>>> I’m not quite sure what you mean by "restrictions of parent 
>>> implementations”, however, the “default value” you’re mentioning is a 
>>> fundamental part of OOP–when a subclass overrides a superclass, it gets the 
>>> parent class’s methods for free. There’s no need to issue a warning for 
>>> this, since it’s expected behavior from other Object-Oriented languages.
>>> 
>>> Saagar Jha
>>> 
>>> 
>>> 
 On Jan 4, 2017, at 6:29 PM, Wagner Truppel via swift-users 
  wrote:
 
 Hello,
 
 I wasn’t sure whether to post this message here, at swift-dev, or at 
 swift-evolution. so I’ll try here first. Hopefully it will get to the 
 right group of people or, if not, someone will point me to the right 
 mailing list.
 
 I came across a situation that boils down to this example:
 
 class Parent {
   func foo() {
   print("Parent foo() called")
   }
 }
 
 class Child: Parent {
   func foo(x: Int = 0) {
   print("Child foo() called")
   }
 }
 
 let c = Child()
 c.foo()  // prints "Parent foo() called"
 
 I understand why this behaves like so, namely, the subclass has a method 
 foo(x:) but no direct implementation of foo() so the parent’s 
 implementation is invoked rather than the child's. That’s all fine except 
 that it is not very intuitive.
 
 I would argue that the expectation is that the search for an 
 implementation should start with the subclass (which is does) but should 
 look at all possible restrictions of parent implementations, including the 
 restriction due to default values.
 
 At the very least, I think the compiler should emit a warning or possibly 
 even an error.
 
 Thanks for reading.
 Cheers,
 
 Wagner
 ___
 swift-users mailing list
 swift-users@swift.org
 https://lists.swift.org/mailman/listinfo/swift-users
>>> 
>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
>> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Compiler should issue a warning when a subclass implementation with default values matches a parent implementation without them

2017-01-04 Thread Saagar Jha via swift-users
I’m not quite sure what you mean by "restrictions of parent implementations”, 
however, the “default value” you’re mentioning is a fundamental part of 
OOP–when a subclass overrides a superclass, it gets the parent class’s methods 
for free. There’s no need to issue a warning for this, since it’s expected 
behavior from other Object-Oriented languages.

Saagar Jha



> On Jan 4, 2017, at 6:29 PM, Wagner Truppel via swift-users 
>  wrote:
> 
> Hello,
> 
> I wasn’t sure whether to post this message here, at swift-dev, or at 
> swift-evolution. so I’ll try here first. Hopefully it will get to the right 
> group of people or, if not, someone will point me to the right mailing list.
> 
> I came across a situation that boils down to this example:
> 
> class Parent {
>func foo() {
>print("Parent foo() called")
>}
> }
> 
> class Child: Parent {
>func foo(x: Int = 0) {
>print("Child foo() called")
>}
> }
> 
> let c = Child()
> c.foo()  // prints "Parent foo() called"
> 
> I understand why this behaves like so, namely, the subclass has a method 
> foo(x:) but no direct implementation of foo() so the parent’s implementation 
> is invoked rather than the child's. That’s all fine except that it is not 
> very intuitive.
> 
> I would argue that the expectation is that the search for an implementation 
> should start with the subclass (which is does) but should look at all 
> possible restrictions of parent implementations, including the restriction 
> due to default values.
> 
> At the very least, I think the compiler should emit a warning or possibly 
> even an error.
> 
> Thanks for reading.
> Cheers,
> 
> Wagner
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] reading data from a table in swift

2016-11-26 Thread Saagar Jha via swift-users
Here’s a solution I came up with, which should generalize for any condition and 
for arrays with dimensions >= 1 by 1. I’m not sure if there’s a Swiftier™ way 
to iterate over 2D arrays; if there is I’d like to hear it!

// Find the index of the first row in table in the column specified where the 
condition is true
func firstRow(table: [[Int]], forColumn column: Int, where predicate: (Int) -> 
Bool) -> Int {
for row in 0.. 
Bool) -> Int {
for column in 0..= input1 })
let column1 = firstColumn(table: table1, forRow: 0, where: { $0 >= input1 })
let value1 = table1[row1][column1]

let row2 = firstRow(table: table2, forColumn: 0, where: { $0 >= input2 })
let column2 = firstColumn(table: table2, forRow: row2, where: { $0 > input2 })
let value2 = table2[row2][column2]

Hope this helps,
Saagar Jha



> On Nov 26, 2016, at 12:33, Paul via swift-users  wrote:
> 
> Hi
> 
> I am almost a complete noob to Swift and I am writing my first app.
> 
> I need to read a value from a table and return that to the app to do a few 
> calculations but I am so new I have no idea what is the best method to do 
> this.
> 
> Specifically there are two tables (currently in microsoft excel) that i need 
> to “read” and get a value from . The values in these tables never change so I 
> can convert them into an array or other data structure that would make sense 
> in Swift.
> 
> The first table is about 25 x 25 (rows and columns).
> 
> I need to read down the first column (A) to find the value that is equal to 
> or the next larger value from what the user had input, and then I read across 
> the first row (1) to find the value that is equal to or the next larger 
> value. The cell where the row and column intersect contains a value and I 
> want to extract that value and use it in a few calculations.
> 
> Can anyone help point me in a direction to get started with that?
> 
> The second table is 20 X 13 (rows v columns).
> 
> Similar to the first table, I need to read down the first column (A) to find 
> the value that is equal to or the next larger value from what the user had 
> input…unlike the first table, now I have to read across that specified row to 
> find a cell value that is equal to or the next larger value to what the user 
> input, and then read up to the column to the top row and read the value from 
> the cell in row (0)
> 
> Again, I would appreciate any help about how to accomplish this.
> 
> 
> Thanks in advance
> 
> 
> Paul
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Dollar library, good or not?

2016-10-20 Thread Saagar Jha via swift-users
IMO no. The author's Cent library (https://github.com/ankurp/Cent/) though
looks a lot "Swift-ier" to me, using extensions rather than a global "$".
On Thu, Oct 20, 2016 at 15:05 Rick Mann via swift-users <
swift-users@swift.org> wrote:

> A discussion on swift-evolution prompted me to look at the Dollar library (
> https://github.com/ankurp/Dollar). Is this library an example of good
> design? It doesn't seem to be to me. No doubt much of the actual
> functionality is helpful, I'm just asking about the API design.
>
> For example, why is everything hung off a variable ("$")? Why not just a
> collection of global methods?
>
> It seems to tout the fact that it's good because it does NOT extend any
> built-in objects, but that seems un-swifty.
>
> Thanks,
>
> --
> Rick Mann
> rm...@latencyzero.com
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Will it be better if `fallthrough` works with `label` in nested `switch - case`?

2016-10-14 Thread Saagar Jha via swift-users
This seems like a better solution to me. The other one smacks of goto.
On Fri, Oct 14, 2016 at 20:52 Zhao Xin via swift-users <
swift-users@swift.org> wrote:

> I manage to use below work around.
>
> let count = 1
>
>
> switch count {
>
> case 0, 1:
>
> let buttonId = NSAlertThirdButtonReturn
>
> let shouldFallthrough = { () -> Bool in
>
> switch buttonId {
>
> case NSAlertFirstButtonReturn:
>
> print("do something")
>
> case NSAlertSecondButtonReturn:
>
> print("do something")
>
> case NSAlertThirdButtonReturn:
>
> print("do something")
>
> return true
>
> default:
>
> fatalError()
>
> }
>
>
>
> return false
>
> }()
>
> if shouldFallthrough { fallthrough }
>
> default:
>
> print("do extra things")
>
> }
>
> Zhaoxin
>
>
> On Sat, Oct 15, 2016 at 10:44 AM, Zhao Xin  wrote:
>
> I thought below code would work. It didn't.
>
> let count = 1
>
>
> outerSwitch: switch count {
>
> case 0, 1:
>
> let buttonId = 0
>
> switch  buttonId {
>
> case NSAlertFirstButtonReturn:
>
> print("do something")
>
> case NSAlertSecondButtonReturn:
>
> print("do something")
>
> case NSAlertThirdButtonReturn:
>
> print("do something")
>
> fallthrough outerSwitch // error here
>
> default:
>
> fatalError()
>
> }
>
> default:
>
> print("do extra things")
>
> }
>
> So I have to use `if - else if - else` instead. I think if `fallthrouh`
> works with `label`, the code will be more elegant.
>
> Zhaoxin
>
>
>
>
>
>
>
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] QualityOfService for concurrentPerform in Swift 3

2016-09-25 Thread Saagar Jha via swift-users
Hmm, I didn’t realize that concurrentPerform doesn’t allow you to pass in your 
own queue…this looks like an oversight to me. Maybe someone with more 
experience with libdispatch could explain?

Saagar Jha



> On Sep 25, 2016, at 09:13, Gerriet M. Denkmann  wrote:
> 
> 
>> On 25 Sep 2016, at 23:08, Saagar Jha  wrote:
>> 
>> You might be looking for the DispatchQoS.QoSClass enum.
>> 
>> Saagar Jha
> 
> Probably. But how to make concurrentPerform use any of these enums?
> 
> Gerriet.
> 
> 
> 
>> 
>>> On Sep 25, 2016, at 05:19, Gerriet M. Denkmann via swift-users 
>>>  wrote:
>>> 
>>> In ObjC:
>>> 
>>> dispatch_queue_t queue = dispatch_get_global_queue( 
>>> DISPATCH_QUEUE_PRIORITY_HIGH, 0 );  
>>> dispatch_apply( nbrThreads, queue, ^void(size_t idx) …
>>> 
>>> In Swift 3:
>>> DispatchQueue.concurrentPerform( iterations: nbrThreads) …
>>> 
>>> How can one specify the DISPATCH_QUEUE_PRIORITY or QualityOfService to be 
>>> used by concurrentPerform?
>>> 
>>> Gerriet.
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] QualityOfService for concurrentPerform in Swift 3

2016-09-25 Thread Saagar Jha via swift-users
You might be looking for the DispatchQoS.QoSClass 
 enum.

Saagar Jha



> On Sep 25, 2016, at 05:19, Gerriet M. Denkmann via swift-users 
>  wrote:
> 
> In ObjC:
> 
> dispatch_queue_t queue = dispatch_get_global_queue( 
> DISPATCH_QUEUE_PRIORITY_HIGH, 0 );
> dispatch_apply( nbrThreads, queue, ^void(size_t idx) …
> 
> In Swift 3:
> DispatchQueue.concurrentPerform( iterations: nbrThreads) …
> 
> How can one specify the DISPATCH_QUEUE_PRIORITY or QualityOfService to be 
> used by concurrentPerform?
> 
> Gerriet.
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Encoding an array of tuples with a NSCoder

2016-09-22 Thread Saagar Jha via swift-users
This used to work in a previous beta of Xcode 8 (beta 4, I think…I haven't
checked in the meantime due to issues with Swift 3 migration). I'm guessing
it got changed with the Any/AnyObject work going on in between. I'll go
with using a 2-element array in the meantime.
On Thu, Sep 22, 2016 at 14:27 Philippe Hausler  wrote:

> err sorry mistype it should have read tuples or structs
>
> On Sep 22, 2016, at 2:27 PM, Philippe Hausler via swift-users <
> swift-users@swift.org> wrote:
>
> NSCoding has never worked with either tuples or classes correctly
> (primarily because it is not really designed to do so). I would suggest to
> encode and decode either as an array of array of strings and convert or
> perhaps encode/decode as an array of classes representing the meaning of
> the tuple.
>
> On Sep 22, 2016, at 2:07 PM, Saagar Jha via swift-users <
> swift-users@swift.org> wrote:
>
> Hello,
>
> I’ve been working on migrating some old code over to Swift 3, and I’m
> having some trouble archiving an array of tuples:
>
> class Foo: NSObject, NSCoding {
> var bar: [(string1: String, string2: String)]
>
> required init?(coder aDecoder: NSCoder) {
> bar = aDecoder.decodeObject(forKey: “bar”) as? [(string1: String, string2:
> String)] ?? []
> }
>
> func encode(with aCoder: NSCoder) {
> aCoder.encode(bar, forKey: “bar”) // crash
> }
> }
>
> Unfortunately, this code doesn’t seem to work anymore. Is there any way to
> get a array of tuple encoded without resorting to creating a struct or
> class in its place?
>
> Thanks,
> Saagar Jha
>
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Encoding an array of tuples with a NSCoder

2016-09-22 Thread Saagar Jha via swift-users
Hello,

I’ve been working on migrating some old code over to Swift 3, and I’m having 
some trouble archiving an array of tuples:

class Foo: NSObject, NSCoding {
var bar: [(string1: String, string2: String)]

required init?(coder aDecoder: NSCoder) {
bar = aDecoder.decodeObject(forKey: “bar”) as? [(string1: 
String, string2: String)] ?? []
}

func encode(with aCoder: NSCoder) {
aCoder.encode(bar, forKey: “bar”) // crash
}
}

Unfortunately, this code doesn’t seem to work anymore. Is there any way to get 
a array of tuple encoded without resorting to creating a struct or class in its 
place?

Thanks,
Saagar Jha



___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] what's ^ operator for

2016-09-18 Thread Saagar Jha via swift-users
The ^ operator performs a bitwise XOR 
. This is not the same as 
exponentiation.

Saagar Jha



> On Sep 18, 2016, at 05:41, Mr Bee via swift-users  
> wrote:
> 
> Hi all,
>  
> I wrote this in XCode Playground…
> 
> let i = 2^2
> print(i)
> 
> It runs fine without any errors and print 0, while I expect it to print 4 
> from 2 power by 2 or 2². Swift ebook and even Google gave me nothing on this.
> 
> What did I miss?
> 
> Thank you.
> 
> Regards,
> 
> –Mr Bee
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Migrating to Swift 3 using Xcode fails

2016-09-09 Thread Saagar Jha via swift-users
Thanks, I’ve filed rdar://problem/28230945  with the 
xcodeproj.

Saagar Jha



> On Sep 9, 2016, at 10:03, Jordan Rose  wrote:
> 
> Xcode and migration aren't part of the Swift open source project, but this is 
> something I've heard other people complaining about. Can you please file a 
> Radar if you haven't already (bugreport.apple.com 
> <http://bugreport.apple.com/>) and include your project file, then send me 
> the bug number? (For this particular issue, I think we can get away with just 
> the xcodeproj rather than the entire project sources that we'd usually need.)
> 
> Thanks,
> Jordan
> 
> 
>> On Sep 8, 2016, at 19:51, Saagar Jha via swift-users > <mailto:swift-users@swift.org>> wrote:
>> 
>> Ok, here’s what happened:
>> 
>> 1. I had a project that used Swift 2.3 with Xcode 7.
>> 2. I downloaded Xcode 8 beta 1 and used the migrator to migrate to Swift 3 
>> (successfully).
>> 3. I downloaded the Xcode 8 betas, fixing errors as they cropped up due to 
>> new proposals.
>> 4. I downloaded Xcode 8 GM, and the project now fails to build due to it 
>> reverting back to the 2.3 compiler when I right when opened it (I have no 
>> idea how this happened).
>> 5. I trigger the migrator manually, which warns that the project is already 
>> on Swift 3. I force it to go through anyways, hoping to have it swap the 
>> compiler. It proposes no source changes (since I’ve already done this in 
>> previous betas) and it then “fails” for whatever reason.
>> 6. It’s still using the old compiler and my code fails to build.
>> 
>> Saagar Jha
>> 
>> 
>> 
>>> On Sep 8, 2016, at 19:33, Zhao Xin >> <mailto:owe...@gmail.com>> wrote:
>>> 
>>> I​ am confused with your situation. You said, "I’ve migrated one of my 
>>> projects to Swift 3 previously, with an earlier beta of Xcode.". Then in 
>>> Xcode should not using Swift 2.3. Assuming ​X​code using 2.3 wrongly, you 
>>> should use Xcode migration tool again, after that Xcode will use Swift 3.0. 
>>> You manually change code will not cause Xcode using Swift 3.0 automatically.
>>> 
>>> Zhaoxin​
>>> 
>>> On Fri, Sep 9, 2016 at 10:26 AM, Saagar Jha >> <mailto:saa...@saagarjha.com>> wrote:
>>> I am aware that there were new proposals, and I’ve been following along and 
>>> manually migrating. The errors are due to Xcode using the Swift 2.3 
>>> compiler, which doesn’t like the new Swift 3 syntax (for example, it’s 
>>> complaining that it can’t find the new types that have the NS- prefix 
>>> dropped). I’m just looking for the flag in build settings that switches the 
>>> compilers.
>>> 
>>> Saagar Jha
>>> 
>>> 
>>> 
>>>> On Sep 8, 2016, at 16:47, Zhao Xin >>> <mailto:owe...@gmail.com>> wrote:
>>>> 
>>>> ​I think you can just use Xcode's tool that you upgrade to Swift 3.0. 
>>>> However, I suggest you do a backup of your project first in case this is 
>>>> not helpful.
>>>> 
>>>> Also, the errors you saw were probably not because of Xcode converted you 
>>>> code to 2.3 automatically. It wouldn't do that. The real reason is that in 
>>>> Xcode 6 beta6, a lot of Swift 3.0 accepted proposals were implemented and 
>>>> released, which made the Swift 3.0 far more different from the previous 
>>>> 3.0. 
>>>> 
>>>> Xcode's migration tool is closed sourced and is not part of Swift. ​If you 
>>>> have further questions, I suggest you to ask it in Apple's developer forum.
>>>> 
>>>> Zhaoxin
>>>> 
>>>> On Fri, Sep 9, 2016 at 5:01 AM, Saagar Jha via swift-users 
>>>> mailto:swift-users@swift.org>> wrote:
>>>> Hi,
>>>> 
>>>> I’ve migrated one of my projects to Swift 3 previously, with an earlier 
>>>> beta of Xcode. However, after downloading the GM seed, hundreds of errors 
>>>> pop up in my code, since it appears that Xcode has somehow reverted the 
>>>> compiler back to 2.3. Manually migrating using Edit>Convert>To Current 
>>>> Swift Syntax… always fails, due to the fact that the code had been 
>>>> previously migrated. Is there any way to “manually” migrate the code (i.e. 
>>>> change the compiler settings?)
>>>> 
>>>> Thanks,
>>>> Saagar Jha
>>>> 
>>>> 
>>>> 
>>>> 
>>>> ___
>>>> swift-users mailing list
>>>> swift-users@swift.org <mailto:swift-users@swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>>> <https://lists.swift.org/mailman/listinfo/swift-users>
>>>> 
>>>> 
>>> 
>>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org <mailto:swift-users@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Migrating to Swift 3 using Xcode fails

2016-09-08 Thread Saagar Jha via swift-users
Ok, here’s what happened:

1. I had a project that used Swift 2.3 with Xcode 7.
2. I downloaded Xcode 8 beta 1 and used the migrator to migrate to Swift 3 
(successfully).
3. I downloaded the Xcode 8 betas, fixing errors as they cropped up due to new 
proposals.
4. I downloaded Xcode 8 GM, and the project now fails to build due to it 
reverting back to the 2.3 compiler when I right when opened it (I have no idea 
how this happened).
5. I trigger the migrator manually, which warns that the project is already on 
Swift 3. I force it to go through anyways, hoping to have it swap the compiler. 
It proposes no source changes (since I’ve already done this in previous betas) 
and it then “fails” for whatever reason.
6. It’s still using the old compiler and my code fails to build.

Saagar Jha



> On Sep 8, 2016, at 19:33, Zhao Xin  wrote:
> 
> I​ am confused with your situation. You said, "I’ve migrated one of my 
> projects to Swift 3 previously, with an earlier beta of Xcode.". Then in 
> Xcode should not using Swift 2.3. Assuming ​X​code using 2.3 wrongly, you 
> should use Xcode migration tool again, after that Xcode will use Swift 3.0. 
> You manually change code will not cause Xcode using Swift 3.0 automatically.
> 
> Zhaoxin​
> 
> On Fri, Sep 9, 2016 at 10:26 AM, Saagar Jha  <mailto:saa...@saagarjha.com>> wrote:
> I am aware that there were new proposals, and I’ve been following along and 
> manually migrating. The errors are due to Xcode using the Swift 2.3 compiler, 
> which doesn’t like the new Swift 3 syntax (for example, it’s complaining that 
> it can’t find the new types that have the NS- prefix dropped). I’m just 
> looking for the flag in build settings that switches the compilers.
> 
> Saagar Jha
> 
> 
> 
>> On Sep 8, 2016, at 16:47, Zhao Xin > <mailto:owe...@gmail.com>> wrote:
>> 
>> ​I think you can just use Xcode's tool that you upgrade to Swift 3.0. 
>> However, I suggest you do a backup of your project first in case this is not 
>> helpful.
>> 
>> Also, the errors you saw were probably not because of Xcode converted you 
>> code to 2.3 automatically. It wouldn't do that. The real reason is that in 
>> Xcode 6 beta6, a lot of Swift 3.0 accepted proposals were implemented and 
>> released, which made the Swift 3.0 far more different from the previous 3.0. 
>> 
>> Xcode's migration tool is closed sourced and is not part of Swift. ​If you 
>> have further questions, I suggest you to ask it in Apple's developer forum.
>> 
>> Zhaoxin
>> 
>> On Fri, Sep 9, 2016 at 5:01 AM, Saagar Jha via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> Hi,
>> 
>> I’ve migrated one of my projects to Swift 3 previously, with an earlier beta 
>> of Xcode. However, after downloading the GM seed, hundreds of errors pop up 
>> in my code, since it appears that Xcode has somehow reverted the compiler 
>> back to 2.3. Manually migrating using Edit>Convert>To Current Swift Syntax… 
>> always fails, due to the fact that the code had been previously migrated. Is 
>> there any way to “manually” migrate the code (i.e. change the compiler 
>> settings?)
>> 
>> Thanks,
>> Saagar Jha
>> 
>> 
>> 
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org <mailto:swift-users@swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> <https://lists.swift.org/mailman/listinfo/swift-users>
>> 
>> 
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Migrating to Swift 3 using Xcode fails

2016-09-08 Thread Saagar Jha via swift-users
I am aware that there were new proposals, and I’ve been following along and 
manually migrating. The errors are due to Xcode using the Swift 2.3 compiler, 
which doesn’t like the new Swift 3 syntax (for example, it’s complaining that 
it can’t find the new types that have the NS- prefix dropped). I’m just looking 
for the flag in build settings that switches the compilers.

Saagar Jha



> On Sep 8, 2016, at 16:47, Zhao Xin  wrote:
> 
> ​I think you can just use Xcode's tool that you upgrade to Swift 3.0. 
> However, I suggest you do a backup of your project first in case this is not 
> helpful.
> 
> Also, the errors you saw were probably not because of Xcode converted you 
> code to 2.3 automatically. It wouldn't do that. The real reason is that in 
> Xcode 6 beta6, a lot of Swift 3.0 accepted proposals were implemented and 
> released, which made the Swift 3.0 far more different from the previous 3.0. 
> 
> Xcode's migration tool is closed sourced and is not part of Swift. ​If you 
> have further questions, I suggest you to ask it in Apple's developer forum.
> 
> Zhaoxin
> 
> On Fri, Sep 9, 2016 at 5:01 AM, Saagar Jha via swift-users 
> mailto:swift-users@swift.org>> wrote:
> Hi,
> 
> I’ve migrated one of my projects to Swift 3 previously, with an earlier beta 
> of Xcode. However, after downloading the GM seed, hundreds of errors pop up 
> in my code, since it appears that Xcode has somehow reverted the compiler 
> back to 2.3. Manually migrating using Edit>Convert>To Current Swift Syntax… 
> always fails, due to the fact that the code had been previously migrated. Is 
> there any way to “manually” migrate the code (i.e. change the compiler 
> settings?)
> 
> Thanks,
> Saagar Jha
> 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org <mailto:swift-users@swift.org>
> https://lists.swift.org/mailman/listinfo/swift-users 
> <https://lists.swift.org/mailman/listinfo/swift-users>
> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


[swift-users] Migrating to Swift 3 using Xcode fails

2016-09-08 Thread Saagar Jha via swift-users
Hi,

I’ve migrated one of my projects to Swift 3 previously, with an earlier beta of 
Xcode. However, after downloading the GM seed, hundreds of errors pop up in my 
code, since it appears that Xcode has somehow reverted the compiler back to 
2.3. Manually migrating using Edit>Convert>To Current Swift Syntax… always 
fails, due to the fact that the code had been previously migrated. Is there any 
way to “manually” migrate the code (i.e. change the compiler settings?)

Thanks,
Saagar Jha



___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Subview does not report frame size

2016-08-29 Thread Saagar Jha via swift-users
Bugs with Apple’s frameworks (such as UIKit) are generally better filed as a 
radar.

Saagar Jha



> On Aug 29, 2016, at 09:10, Martin Romañuk via swift-users 
>  wrote:
> 
> In Xcode 8 beta 6, asking for frame or bounds of a subview, both are reported 
> as (0,0,1000,1000) which is incorrect.
> The subview was added to a UIViewController view in storyboard and it is 
> contrained to 240 points of width.
> 
> This works fine in Xcode 7, maybe this is not swift related, more like UIKit.
> 
> Regards,
> – Martin –
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Is 12:01:00A.M in DataFormatter.localizedString correct?

2016-08-28 Thread Saagar Jha via swift-users
24 hour time shouldn’t need an AM/PM indicator.

Saagar Jha



> On Aug 28, 2016, at 21:15, Zhao Xin via swift-users  
> wrote:
> 
> It should be called 00:01:00 A.M., instead of 12:01:00 A.M. Shouldn't it?
> 
> import Foundation
> 
> let now = Date()
> var dc = Calendar.current.dateComponents([.year, .month, .day], from: now)
> dc.minute = 1
> let date = Calendar.current.date(from: dc)
> print(DateFormatter.localizedString(from: date!, dateStyle: .long, timeStyle: 
> .long))
> // prints "August 29, 2016 at 12:01:00 AM GMT+8"
> 
> 
> Zhaoxin
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] in-app purchase coding

2016-08-10 Thread Saagar Jha via swift-users
Swift-Users isn't really the best place to discuss Apple's frameworks, but
if you give a bit more detail we may be able to help you.
On Wed, Aug 10, 2016 at 12:10 developer--- via swift-users <
swift-users@swift.org> wrote:

>
> i am using a Macbook Pro running El Capitan (i ran the update today) with the 
> latest version of Xcode. i tried
> to test the practice app on my iPad  (i am updating it to iOS 9.3.2 right now)
>
> DESCRIPTION OF PROBLEM
> i am a student, i have taken all of my programming classes but the school's 
> agreement with Apple does not
> allow them to cover in-app purchases. i have followed the instructions from 
> the book "iOS 9 app development
> essentials" to create a practice app to code & test a built-in in app 
> purchase to unlock built in features. my
> purchaseViewController is FULL of errors.  i have no idea how to fix
> the errors. i have built an app that needs to include several in app 
> purchases, but i desperately need help with
> this and my instructor has never created an in app purchase so she doesn't 
> know how to help me. i would
> very much appreciate being able to send my test app to the support team so 
> that a technician could comment
> out the bad code, and add the correct code so that i can see where i went 
> wrong, and hopefully get instruction
> on how to create several in app purchases for the app i wish to get into the 
> app store.
>
>
> this is the response I got from Apple-
>
> Thank you for contacting Apple Developer Technical Support (DTS). Our
> engineers have reviewed your request and have concluded that there is no
> supported way to achieve the desired functionality given the currently
> shipping system configurations.
>
> If you would like for Apple to consider providing an iAP sample in Swift
> in the future, please submit an enhancement request via the Bug Reporter
> tool at .
>
> While a Technical Support Incident (TSI) was initially debited from your
> Apple Developer Program account for this request, we have assigned a
> replacement incident back to your account.
>
> Thank you for taking the time to file this report. We truly appreciate
> your help in discovering and isolating issues.
>
> Im posting this here because I wonder how many other people have
> experienced the same problem and how they’ve overcome it. I really feel
> ripped off. I chose to learn to develop for iOS for particular reasons, and
> now at the end of school, I’m about to graduate without having been taught
> an obviously vital skill that a developer should absolutely posses. I’ve
> looked for help in the developer forums to no avail…I’ve TRIED to make
> sense of what documentation I could find provided by Apple to no avail.  Ya
> see, my class had barely begun to touch Objective-C when Swift was
> officially released out of beta. The class immediately jumped to Swift. I
> have found a few online courses that say they teach what I need to know but
> I just don’t have confidence in these classes. Must I learn Objective-C to
> accomplish this?? Or does anyone here have any feasible solution to offer
> as advice?? If I had known that this precious skill would not be taught to
> me at this school, I would have sought alternatives. A rep at Apple told me
> that she knew of ONE school that was definitely teaching this material…of
> course it is out of my state and I cannot afford to go there, not even for
> 1 class to learn what I seek. I am in Texas.
> Thanks in advance for any help :)
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift in bare-metal embedded programming/Swift runtime

2016-08-10 Thread Saagar Jha via swift-users


Sent from my iPhone

> On Aug 10, 2016, at 08:31, Jens Alfke via swift-users  
> wrote:
> 
> 
>> On Aug 9, 2016, at 1:10 PM, Rick Mann via swift-users 
>>  wrote:
>> 
>> For the smaller devices, runtime library overhead is a concern (mostly due 
>> to code size). Is it possible to write swift code with no runtime library? I 
>> think this is possible in Rust (came up on another list).
> 
> I have never seen the Swift source code, but I’d be surprised if Swift 
> binaries didn’t require at least the standard C runtime library. (It’s pretty 
> hard to get anything done without at least having malloc/free!)
> 
> Don’t forget that the binary will have to include the implementations of the 
> standard Swift library classes, at least the ones used by your program. I’m 
> sure String in particular is a significant chunk of code, since it has to do 
> all kinds of Unicode stuff. (In fact it might have a dependency on ICU, which 
> is a pretty hefty C library.)
> 
>> These devices usually have memory-mapped registers that are read and written 
>> to affect the operation of the device. Some can be quite small (e.g. 8-bit 
>> registers, simple single physical memory address space), and others quite 
>> robust (full 32- or 64-bit machines with MMUs, etc.).
> 
> Arduinos are probably right out, since there’s no way anyone’s going to port 
> Swift to an 8-bit CPU!
> 
> If you’re going for something bigger than that, why not just use a Raspberry 
> Pi or C.H.I.P. or one of the other tiny ARM PC boards? They all run Linux, 
> and I believe people are already working on porting Swift to run on those.

Minor correction: Swift already builds and runs on the Raspberry Pi :)

> C.H.I.P. costs $9, and I saw a blurb somewhere about a competitor that’s only 
> $5.
> 
> —Jens
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] What are these types with regular expressions?

2016-08-06 Thread Saagar Jha via swift-users
Swift String indexing and sub scripting is different than other languages.
Instead of using Ints, Strings use their own Indexes (a String.Index). To
get an index, you can use the String's startIndex property and then use
advancedBy on it. The Swift Programming Language has more details:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html#//apple_ref/doc/uid/TP40014097-CH7-ID285

On Sat, Aug 6, 2016 at 04:26 晓敏 褚  wrote:

> I’m writing a program with regular expressions, and I’m finding it
> extremely hard to code with these in swift. I got a [TextCheckingResult]
> from the matching function, and there is no document on what
> TextCheckingResult is and how could I work with it. And when I try to use
> range to get a substring, I got a Range, but the substring:with:
> method requies a Range. But there is no way I could find any
> information about the type(or protocol?) Index, and passing a Int fails.
> What are they, and how can I work with them?
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Assertion Failure When Using the swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a Xcode Toolchain

2016-08-05 Thread Saagar Jha via swift-users
Thanks, I managed to create a small test project with the same issue; I’ve 
filed it as SR-2288 <https://bugs.swift.org/browse/SR-2288>.

Saagar Jha



> On Aug 4, 2016, at 21:01, Mark Lacey  wrote:
> 
>> 
>> On Aug 4, 2016, at 8:51 PM, Saagar Jha via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> Hello Swift Users,
>> 
>> This afternoon I updated my Xcode to Xcode 8 beta 4, and tried to compile 
>> one of my previously migrated Swift 3 projects. Along with a couple of 
>> renames, the compiler kept crashing due to a segmentation fault. Since the 
>> issue appeared to be similar to SR-2227, which was supposedly fixed with a 
>> pull request a couple days ago, I downloaded today’s snapshot toolchain. The 
>> new toolchain throws an assertion:
>> 
>> Assertion failed: (value != OpenExistentials.end() && "didn't see this OVE 
>> in a containing OpenExistentialExpr?"), function walkToExprPre, file 
>> /Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/Sema/CSDiag.cpp,
>>  line 3082.
>> 0  swift0x00010a932ebb 
>> llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
>> 1  swift0x00010a932106 
>> llvm::sys::RunSignalHandlers() + 70
>> 2  swift0x00010a93360f SignalHandler(int) + 383
>> 3  libsystem_platform.dylib 0x7fffa6122d7a _sigtramp + 26
>> 4  libsystem_platform.dylib 0x00010001 _sigtramp + 1508758177
>> 5  swift0x00010a93335e abort + 14
>> 6  swift0x00010a933341 __assert_rtn + 81
>> 7  swift0x000108431879 
>> eraseOpenedExistentials(swift::Expr*&)::ExistentialEraser::walkToExprPre(swift::Expr*)
>>  + 361
>> 8  swift0x0001085b8ea5 (anonymous 
>> namespace)::Traversal::visit(swift::Expr*) + 4981
>> 9  swift0x0001085b6f75 
>> swift::Expr::walk(swift::ASTWalker&) + 53
>> 10 swift0x00010842e375 (anonymous 
>> namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, 
>> swift::Type, swift::ContextualTypePurpose, swift::OptionSet> unsigned int>, swift::ExprTypeCheckListener*) + 1221
>> 11 swift0x000108434ea3 (anonymous 
>> namespace)::FailureDiagnosis::typeCheckArgumentChildIndependently(swift::Expr*,
>>  swift::Type, (anonymous namespace)::CalleeCandidateInfo const&, 
>> swift::OptionSet) + 1987
>> 12 swift0x00010843e9a1 (anonymous 
>> namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 913
>> 13 swift0x000108428f6a swift::ASTVisitor<(anonymous 
>> namespace)::FailureDiagnosis, bool, void, void, void, void, 
>> void>::visit(swift::Expr*) + 170
>> 14 swift0x000108422888 
>> swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 
>> 104
>> 15 swift0x0001084289a8 
>> swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl&,
>>  swift::Expr*) + 4056
>> 16 swift0x0001084ab665 
>> swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, 
>> swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, 
>> swift::constraints::ConstraintSystem&, 
>> llvm::SmallVectorImpl&, 
>> swift::OptionSet) + 917
>> 17 swift0x0001084b17d1 
>> swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, 
>> swift::TypeLoc, swift::ContextualTypePurpose, 
>> swift::OptionSet, 
>> swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 625
>> 18 swift0x00010852c061 swift::ASTVisitor<(anonymous 
>> namespace)::StmtChecker, void, swift::Stmt*, void, void, void, 
>> void>::visit(swift::Stmt*) + 545
>> 19 swift0x00010852c543 swift::ASTVisitor<(anonymous 
>> namespace)::StmtChecker, void, swift::Stmt*, void, void, void, 
>> void>::visit(swift::Stmt*) + 1795
>> 20 swift0x00010852bf8e swift::ASTVisitor<(anonymous 
>> namespace)::StmtChecker, void, swift::Stmt*, void, void, void, 
>> void>::visit(swift::Stmt*) + 334
>> 21 swift0x00010852b369 (anonymous 
>> namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 25
>> 22 swift0x00010852a63f 
>> swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, 
>> swift:

[swift-users] Assertion Failure When Using the swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a Xcode Toolchain

2016-08-04 Thread Saagar Jha via swift-users
Hello Swift Users,

This afternoon I updated my Xcode to Xcode 8 beta 4, and tried to compile one 
of my previously migrated Swift 3 projects. Along with a couple of renames, the 
compiler kept crashing due to a segmentation fault. Since the issue appeared to 
be similar to SR-2227, which was supposedly fixed with a pull request a couple 
days ago, I downloaded today’s snapshot toolchain. The new toolchain throws an 
assertion:

Assertion failed: (value != OpenExistentials.end() && "didn't see this OVE in a 
containing OpenExistentialExpr?"), function walkToExprPre, file 
/Users/buildnode/jenkins/workspace/oss-swift-package-osx/swift/lib/Sema/CSDiag.cpp,
 line 3082.
0  swift0x00010a932ebb 
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift0x00010a932106 llvm::sys::RunSignalHandlers() + 
70
2  swift0x00010a93360f SignalHandler(int) + 383
3  libsystem_platform.dylib 0x7fffa6122d7a _sigtramp + 26
4  libsystem_platform.dylib 0x00010001 _sigtramp + 1508758177
5  swift0x00010a93335e abort + 14
6  swift0x00010a933341 __assert_rtn + 81
7  swift0x000108431879 
eraseOpenedExistentials(swift::Expr*&)::ExistentialEraser::walkToExprPre(swift::Expr*)
 + 361
8  swift0x0001085b8ea5 (anonymous 
namespace)::Traversal::visit(swift::Expr*) + 4981
9  swift0x0001085b6f75 
swift::Expr::walk(swift::ASTWalker&) + 53
10 swift0x00010842e375 (anonymous 
namespace)::FailureDiagnosis::typeCheckChildIndependently(swift::Expr*, 
swift::Type, swift::ContextualTypePurpose, swift::OptionSet, swift::ExprTypeCheckListener*) + 1221
11 swift0x000108434ea3 (anonymous 
namespace)::FailureDiagnosis::typeCheckArgumentChildIndependently(swift::Expr*, 
swift::Type, (anonymous namespace)::CalleeCandidateInfo const&, 
swift::OptionSet) + 1987
12 swift0x00010843e9a1 (anonymous 
namespace)::FailureDiagnosis::visitApplyExpr(swift::ApplyExpr*) + 913
13 swift0x000108428f6a swift::ASTVisitor<(anonymous 
namespace)::FailureDiagnosis, bool, void, void, void, void, 
void>::visit(swift::Expr*) + 170
14 swift0x000108422888 
swift::constraints::ConstraintSystem::diagnoseFailureForExpr(swift::Expr*) + 104
15 swift0x0001084289a8 
swift::constraints::ConstraintSystem::salvage(llvm::SmallVectorImpl&,
 swift::Expr*) + 4056
16 swift0x0001084ab665 
swift::TypeChecker::solveForExpression(swift::Expr*&, swift::DeclContext*, 
swift::Type, swift::FreeTypeVariableBinding, swift::ExprTypeCheckListener*, 
swift::constraints::ConstraintSystem&, 
llvm::SmallVectorImpl&, 
swift::OptionSet) + 917
17 swift0x0001084b17d1 
swift::TypeChecker::typeCheckExpression(swift::Expr*&, swift::DeclContext*, 
swift::TypeLoc, swift::ContextualTypePurpose, 
swift::OptionSet, 
swift::ExprTypeCheckListener*, swift::constraints::ConstraintSystem*) + 625
18 swift0x00010852c061 swift::ASTVisitor<(anonymous 
namespace)::StmtChecker, void, swift::Stmt*, void, void, void, 
void>::visit(swift::Stmt*) + 545
19 swift0x00010852c543 swift::ASTVisitor<(anonymous 
namespace)::StmtChecker, void, swift::Stmt*, void, void, void, 
void>::visit(swift::Stmt*) + 1795
20 swift0x00010852bf8e swift::ASTVisitor<(anonymous 
namespace)::StmtChecker, void, swift::Stmt*, void, void, void, 
void>::visit(swift::Stmt*) + 334
21 swift0x00010852b369 (anonymous 
namespace)::StmtChecker::typeCheckBody(swift::BraceStmt*&) + 25
22 swift0x00010852a63f 
swift::TypeChecker::typeCheckFunctionBodyUntil(swift::FuncDecl*, 
swift::SourceLoc) + 383
23 swift0x00010852a463 
swift::TypeChecker::typeCheckAbstractFunctionBodyUntil(swift::AbstractFunctionDecl*,
 swift::SourceLoc) + 35
24 swift0x00010852afe4 
swift::TypeChecker::typeCheckAbstractFunctionBody(swift::AbstractFunctionDecl*) 
+ 180
25 swift0x0001084e5c56 
typeCheckFunctionsAndExternalDecls(swift::TypeChecker&) + 166
26 swift0x0001084e68f0 
swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, 
swift::OptionSet, unsigned int, 
unsigned int) + 1568
27 swift0x00010818798c 
swift::CompilerInstance::performSema() + 3916
28 swift0x000107c82ad1 
performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, 
llvm::ArrayRef, int&, swift::FrontendObserver*) + 449
29 swift0x000107c8163f 
swift::performFrontend(llvm::ArrayRef, char const*, void*, 
swift::FrontendObserver*) + 2895
30 swift0x000107c43ea0 main + 2448
31 libdyld.dylib0x7fffa5f16255 start + 1


Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Saagar Jha via swift-users
Oh, wait, I can’t read. Ignore that; then there’s no easy way to do it.

Saagar Jha



> On Aug 4, 2016, at 12:42, Saagar Jha  wrote:
> 
> Ahh…then optional chaining is the way to go: `let dobString = 
> serverDateFormatter?.stringFromDate(dob) ?? ""`
> 
> Saagar Jha
> 
> 
> 
>> On Aug 4, 2016, at 12:41, Daniel Tartaglia > > wrote:
>> 
>> That’s not possible. stringFromDate requires an NSDate, but dob is an 
>> optional
>> 
>>> On Aug 4, 2016, at 2:59 PM, Saagar Jha >> > wrote:
>>> 
>>> As such, there shouldn’t be a need for an if; `let dobString = 
>>> serverDateFormatter.stringFromDate(dob)` should be sufficient.
>>> 
>>> Saagar Jha
>>> 
>>> 
>>> 
 On Aug 4, 2016, at 11:55, Zhao Xin via swift-users >>> > wrote:
 
 It can't be done by ?? as stringFromDate(Date) returns String instead of 
 String?
 
 Zhaoxin
 
 
 On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users 
 mailto:swift-users@swift.org>> wrote:
 That’s where I would use the ?? operator:
 
 let dobString = serverDateFormatter.stringFromDate(dob) ?? ""
 
 
 Jeff Kelley
 
 slauncha...@gmail.com  | @SlaunchaMan 
  | jeffkelley.org 
> On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users 
> mailto:swift-users@swift.org>> wrote:
> 
> Currently I do stuff like this:
> 
> let dobString: String
> if let dob = dob {
>   dobString = serverDateFormatter.stringFromDate(dob)
> }
> else {
>   dobString = ""
> }
> 
> Is there a better, more idiomatic, way to do this sort of thing?
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
 
 
 ___
 swift-users mailing list
 swift-users@swift.org 
 https://lists.swift.org/mailman/listinfo/swift-users 
 
 
 
 ___
 swift-users mailing list
 swift-users@swift.org 
 https://lists.swift.org/mailman/listinfo/swift-users 
 
>>> 
>> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Saagar Jha via swift-users
Ahh…then optional chaining is the way to go: `let dobString = 
serverDateFormatter?.stringFromDate(dob) ?? ""`

Saagar Jha



> On Aug 4, 2016, at 12:41, Daniel Tartaglia  wrote:
> 
> That’s not possible. stringFromDate requires an NSDate, but dob is an 
> optional
> 
>> On Aug 4, 2016, at 2:59 PM, Saagar Jha > > wrote:
>> 
>> As such, there shouldn’t be a need for an if; `let dobString = 
>> serverDateFormatter.stringFromDate(dob)` should be sufficient.
>> 
>> Saagar Jha
>> 
>> 
>> 
>>> On Aug 4, 2016, at 11:55, Zhao Xin via swift-users >> > wrote:
>>> 
>>> It can't be done by ?? as stringFromDate(Date) returns String instead of 
>>> String?
>>> 
>>> Zhaoxin
>>> 
>>> 
>>> On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users 
>>> mailto:swift-users@swift.org>> wrote:
>>> That’s where I would use the ?? operator:
>>> 
>>> let dobString = serverDateFormatter.stringFromDate(dob) ?? ""
>>> 
>>> 
>>> Jeff Kelley
>>> 
>>> slauncha...@gmail.com  | @SlaunchaMan 
>>>  | jeffkelley.org 
 On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users 
 mailto:swift-users@swift.org>> wrote:
 
 Currently I do stuff like this:
 
 let dobString: String
 if let dob = dob {
dobString = serverDateFormatter.stringFromDate(dob)
 }
 else {
dobString = ""
 }
 
 Is there a better, more idiomatic, way to do this sort of thing?
 
 ___
 swift-users mailing list
 swift-users@swift.org 
 https://lists.swift.org/mailman/listinfo/swift-users 
 
>>> 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>>> 
>>> 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
>> 
> 

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Saagar Jha via swift-users
As such, there shouldn’t be a need for an if; `let dobString = 
serverDateFormatter.stringFromDate(dob)` should be sufficient.

Saagar Jha



> On Aug 4, 2016, at 11:55, Zhao Xin via swift-users  
> wrote:
> 
> It can't be done by ?? as stringFromDate(Date) returns String instead of 
> String?
> 
> Zhaoxin
> 
> 
> On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users 
> mailto:swift-users@swift.org>> wrote:
> That’s where I would use the ?? operator:
> 
> let dobString = serverDateFormatter.stringFromDate(dob) ?? ""
> 
> 
> Jeff Kelley
> 
> slauncha...@gmail.com  | @SlaunchaMan 
>  | jeffkelley.org 
>> On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> Currently I do stuff like this:
>> 
>> let dobString: String
>> if let dob = dob {
>>  dobString = serverDateFormatter.stringFromDate(dob)
>> }
>> else {
>>  dobString = ""
>> }
>> 
>> Is there a better, more idiomatic, way to do this sort of thing?
>> 
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Development Snapshots: Which Xcode?

2016-08-01 Thread Saagar Jha via swift-users
I checked in my /Library/Developer/Toolchains and found 
"swift-DEVELOPMENT-SNAPSHOT-2016-05-31-a.xctoolchain”. I’m not sure if it’s 
still available, though.
Saagar Jha



> On Aug 1, 2016, at 18:18, Robert Vaessen  wrote:
> 
> Thanks, Saagar.
> 
> No need to look; I'll grab Xcode 8. 
> 
> ———
> Robert Vaessen
> 704-996-1080
> rob...@rvaessen.com 
> On August 1, 2016 at 9:15:14 PM, Saagar Jha (saa...@saagarjha.com 
> ) wrote:
> 
>> It appears so, as further down the page it says:
>> 
>> Swift 3.0
>> • macOS 10.11.5 (El Capitan)
>> • Xcode 8.0 beta or later
>> 
>> I remember there being a Swift 3 toolchain that worked with Xcode 7…let me 
>> see if I can find it.
>> 
>> Saagar Jha
>> 
>> 
>> 
>>> On Aug 1, 2016, at 18:12, Robert Vaessen via swift-users 
>>> mailto:swift-users@swift.org>> wrote:
>>> 
>>> Can swift 3 development snapshots (such as 
>>> swift-DEVELOPMENT-SNAPSHOT-2016-07-29-a-osx.pkg) be installed and then 
>>> selected as  toolchain in Xcode 7.3.1?
>>> 
>>> Looking through the Download section of Swift.org  gives 
>>> me the impression that Xcode 8.0 Beta must be used.
>>> 
>>> ———
>>> Robert Vaessen
>>> 704-996-1080
>>> rob...@rvaessen.com 
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org 
>>> https://lists.swift.org/mailman/listinfo/swift-users 
>>> 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Development Snapshots: Which Xcode?

2016-08-01 Thread Saagar Jha via swift-users
It appears so, as further down the page it says:

Swift 3.0
• macOS 10.11.5 (El Capitan)
• Xcode 8.0 beta or later

I remember there being a Swift 3 toolchain that worked with Xcode 7…let me see 
if I can find it.

Saagar Jha



> On Aug 1, 2016, at 18:12, Robert Vaessen via swift-users 
>  wrote:
> 
> Can swift 3 development snapshots (such as 
> swift-DEVELOPMENT-SNAPSHOT-2016-07-29-a-osx.pkg) be installed and then 
> selected as  toolchain in Xcode 7.3.1?
> 
> Looking through the Download section of Swift.org  gives 
> me the impression that Xcode 8.0 Beta must be used.
> 
> ———
> Robert Vaessen
> 704-996-1080
> rob...@rvaessen.com 
> ___
> swift-users mailing list
> swift-users@swift.org 
> https://lists.swift.org/mailman/listinfo/swift-users 
> 
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Optional chaining and String properties

2016-08-01 Thread Saagar Jha via swift-users
When you write `(s?.characters).count`, the parentheses are evaluated first; 
`(s?.characters)` gives an `String.CharacterView?`. Accessing the 
`String.CharacterView?`’s `count` property requires a `?`: 
`(s?.characters)?.count`. `s?.characters.count`, on the other hand, is applying 
chaining, which only gives an Optional at the end, intermediate properties 
don’t require a `?` unless they’re Optional themselves.

Saagar Jha



> On Aug 1, 2016, at 11:17, Stephen Schaub  wrote:
> 
> I understand that the String.characters property is not optional. However, I 
> am puzzled as to why
> 
> s?.characters.count
> 
> is legal, but
> 
> (s?.characters).count
> 
> is not. This seems counterintuitive. Can someone explain the logic or rules 
> being used here?
> 
> Stephen
> 
> 
> 
> 
> On Mon, Aug 1, 2016 at 2:09 PM, Saagar Jha  > wrote:
> 
> Saagar Jha
> 
> This isn’t quite how optional chaining in Swift works; see the Swift 
> Programming Guide 
> ,
>  specifically “Linking Multiple Levels of Chaining". Basically, 
> `s?.characters.count` works because `s.characters` isn’t Optional. You only 
> use ? on properties that are Optional.
> 
>> On Aug 1, 2016, at 10:26, Stephen Schaub via swift-users 
>> mailto:swift-users@swift.org>> wrote:
>> 
>> With optional chaining, if I have a Swift variable
>> 
>> var s: String?
>> 
>> s might contain nil, or a String wrapped in an Optional. So, I tried this to 
>> get its length:
>> 
>> let count = s?.characters?.count ?? 0
>> 
>> However, the compiler wants this:
>> 
>> let count = s?.characters.count ?? 0
>> 
>> or this:
>> 
>> let count = (s?.characters)?.count ?? 0
>> 
>> My understanding of optional chaining is that, once you start using '?.' in 
>> a dotted expression, the rest of the properties evaluate as optional and are 
>> typically accessed by '?.', not '.'.
>> 
>> So, I dug a little further and tried this in the playground:
>> 
>> var s: String? = "Foo"
>> print(s?.characters)
>> 
>> The result indicates that s?.characters is indeed an Optional instance, 
>> indicating that s?.characters.count should be illegal.
>> 
>> Why is s?.characters.count a legal expression?
>> 
>> 
>> --
>> Stephen Schaub
>> ___
>> swift-users mailing list
>> swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users 
>> 
> 
> 
> 
> 
> -- 
> Stephen Schaub

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Optional chaining and String properties

2016-08-01 Thread Saagar Jha via swift-users

Saagar Jha

This isn’t quite how optional chaining in Swift works; see the Swift 
Programming Guide 
,
 specifically “Linking Multiple Levels of Chaining". Basically, 
`s?.characters.count` works because `s.characters` isn’t Optional. You only use 
? on properties that are Optional.

> On Aug 1, 2016, at 10:26, Stephen Schaub via swift-users 
>  wrote:
> 
> With optional chaining, if I have a Swift variable
> 
> var s: String?
> 
> s might contain nil, or a String wrapped in an Optional. So, I tried this to 
> get its length:
> 
> let count = s?.characters?.count ?? 0
> 
> However, the compiler wants this:
> 
> let count = s?.characters.count ?? 0
> 
> or this:
> 
> let count = (s?.characters)?.count ?? 0
> 
> My understanding of optional chaining is that, once you start using '?.' in a 
> dotted expression, the rest of the properties evaluate as optional and are 
> typically accessed by '?.', not '.'.
> 
> So, I dug a little further and tried this in the playground:
> 
> var s: String? = "Foo"
> print(s?.characters)
> 
> The result indicates that s?.characters is indeed an Optional instance, 
> indicating that s?.characters.count should be illegal.
> 
> Why is s?.characters.count a legal expression?
> 
> 
> --
> Stephen Schaub
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] [swift-evolution] Multi dimensional - iterator, Iterator2D, Iterator3D

2016-08-01 Thread Saagar Jha via swift-users
With your method, don't you need to write a new method for every dimension?
On Mon, Aug 1, 2016 at 08:43 Ted F.A. van Gaalen via swift-users <
swift-users@swift.org> wrote:

> Hi Erica
>
> That would also be a workable solution, but imho still too tedious as
> it has been so for many years, with nested iteration statements…
> many times this is for;; for;; for tables and for;;for;;for;; for 3D
> structuring.
>
>
> Swift offers nice features (like protocols and generics as you know) to
> improve this.
>
> - I no longer have to nest for;; s  so, Now I rather do this:
> Your example can already be coded like this:
>
>iterate2D( 1, 2, { $0 < 64 } ,
>   1, 2, { $0 < 64 } ,
>   {outerIndex,innerIndex in
>   print (outerIndex,InnerIndex)
>
>   return true // Obligatory. return “false" to break
>}  )
>
> With no chances in Swift, this already works like a charm!
> Imho much more readable and compact,
>
> Uses - AFAICS from a programmers’s perspective - no
> underlying deep collection based coding with Sequence. etc.
>
> I am already deploying it in my own apps e.g. l
> (replaced for;; for;; for;; in the app)
>
> By using this new iterator…() functions my coding gets leaner
> and errors are easier to spot.
>
> Actual working code with Swift 2.x here:
>
>   func generateTiles()
>   {
> let w:  Float =   20  // tile size
> let h:  Float =5
> let l:  Float =5
>
>
> let xstart: Float = -120
> let ystart: Float =  -60
> let zstart: Float =  -10
>
>
> let xend: Float = 120
> let yend: Float =  60
> let zend: Float =  10
>
>
> let tolerance:Float = 0.001 // float drift compensation
>
>
> iterate3D( xstart, w * 1.2, { $0 < xend + tolerance } ,
>ystart, h * 1.2, { $0 < yend + tolerance } ,
>zstart, l * 1.2, { $0 < zend + tolerance } ,
>{
> x,y,z in
> self.addTile(x,y,z,
>  w,h,l)
> return true
>}  )
> }
>
> This generates a group of blocks or tiles in my Apple TV app (under
> construction)
> like the one you can see  in the image “Cloinckz” on my website
> www.tedvg.com.
>
> I also prefer the one dimensional iterate(..  too above the for;; or
> stride()
>
> One could extend these iterator…() functions by adding closures for pre
> and post iteration handling,
> like for printing headers and footers before and/or after a complete
> [inner] iteration.
>
> Note that breaking with *return false* -which is equivalent to the “break”
> stmt in
> a classical for;; -  does not only leave a nested iteration, but also the
> outer ones.
> (maybe a TODO to make individual level- break possible)  As it is now, If
> one
> wants to break at the deep iteration level, then one should nest this
> using 1D iterators.
>
>
> Anyway, this is just a thought starting to think about multi-dimensional
> iterators,
> and other (encapsulation?) of multi dimensional data as well.
> In any case for 2D because table data is used very frequently in many
> apps. as
> most data are in tables.
>
> You won’t believe this :o) but in a sense I might not make so much fuzz
> anymore
> to keep the for;;  as this proves to me that I can solve things much
> better that I thought.
> So, I have to rethink this.
>
> Kind Regards
> Ted
> www.ravelnotes.com
>
>
>
>
>
>
>
> On 31.07.2016, at 18:33, Erica Sadun  wrote:
>
> I'm replying on Swift-Users and bcc'ing in Swift-Evolution to comply with
> the core team's request to focus SE on the current mission statement.
>
> At some point soon, Russ Bishop's PR
> https://github.com/apple/swift/pull/3600 will be incorporated into Swift
> 3. This PR adds `prefix(while:)` and `drop(while:)` to finish implementing
> SE-0045.  Once that's done, you can  combine `sequence(first:, next:)` and
> `prefix(while:)` to into a single function `sequence(first:, next:,
> while:)` like this:
>
> public func sequence(first: T, next: (T) -> T?, while test: (T) ->
> Bool) -> UnfoldSequence> {
> return sequence(first: first, next: next).prefix(while: test)
> }
>
> The combined sequence/prefix call allows you to create loops like this:
>
> for outerIndex in sequence(first: 1, next: { $0 * 2 }, while: { $0 <= 64
> }) {
> for innerIndex in sequence(first: 1, next: { $0 * 2 }, while: { $0 <=
> 64 }) {
> print(outerIndex, innerIndex)
> }
> }
>
> These loops can be nested. break and continue work.  You can use tuples
> for multiple arguments. While I'd like to see a combined form adopted into
> Swift 4b (the deferred "sugar"), it isn't a high priority.
>
> -- E
>
>
> On Jul 31, 2016, at 7:18 AM, Ted F.A. van Gaalen via swift-evolution <
> swift-evolut...@swift.org> wrote:
>
>
> On 31.07.2016, at 04:28, jaden.gel...@gmail.com wrote:
>
> What benefit do Iterator2D and 

Re: [swift-users] My Email

2016-08-01 Thread Saagar Jha via swift-users
I'm sorry; it looks like I jumped to conclusions too quickly :) Either way,
is there a way to delete messages?
On Mon, Aug 1, 2016 at 06:18 Dvir Julius - Play Actual 
wrote:

> Hello Sirs,
>
> The email was sent by mistake.
> I am not a spammer :-)
>
> This email domain belongs to a company of mine, and as I said, it was
> mistakenly sent to you sirs.
>
> *Sincerely,*
>
> *Dvir Julius*
>
>
> On 1 August 2016 at 16:12:10, Saagar Jha (saagarjh...@gmail.com) wrote:
>
> It's most likely just spam…just leave it alone. Replying will make it more
> likely that he'll respond.
>
> On Mon, Aug 1, 2016 at 04:35 James Campbell via swift-users <
> swift-users@swift.org> wrote:
>
>> :) Did you mean to do this ?
>>
>> *___*
>>
>> *James⎥Head of Trolls*
>>
>> *ja...@supmenow.com ⎥supmenow.com
>> *
>>
>> *Sup*
>>
>> *Runway East *
>>
>> *10 Finsbury Square*
>>
>> *London*
>>
>> * EC2A 1AF *
>>
>> On 27 July 2016 at 14:05, Dvir Julius - Play Actual via swift-users <
>> swift-users@swift.org> wrote:
>>
>>> d...@playactual.com
>>>
>>> *Sincerely,*
>>>
>>> *Dvir Julius*
>>>
>>>
>>> ___
>>> swift-users mailing list
>>> swift-users@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
>>>
>>>
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
> --
> -Saagar Jha
>
> --
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] My Email

2016-08-01 Thread Saagar Jha via swift-users
It's most likely just spam…just leave it alone. Replying will make it more
likely that he'll respond.

On Mon, Aug 1, 2016 at 04:35 James Campbell via swift-users <
swift-users@swift.org> wrote:

> :) Did you mean to do this ?
>
> *___*
>
> *James⎥Head of Trolls*
>
> *ja...@supmenow.com ⎥supmenow.com
> *
>
> *Sup*
>
> *Runway East *
>
> *10 Finsbury Square*
>
> *London*
>
> * EC2A 1AF *
>
> On 27 July 2016 at 14:05, Dvir Julius - Play Actual via swift-users <
> swift-users@swift.org> wrote:
>
>> d...@playactual.com
>>
>> *Sincerely,*
>>
>> *Dvir Julius*
>>
>>
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Will Swift 3.0 be part of the OS

2016-07-28 Thread Saagar Jha via swift-users
IIRC it will be part of the system once the ABI is stabilized (which it should 
be with Swift 3).

Saagar Jha



> On Jul 28, 2016, at 18:39, Xuan Liu via swift-users  
> wrote:
> 
> Hi there,
> 
> I remember it is mentioned (or I am wrong) in WWDC that swift 3.0 will be 
> part of the OS, rather than packaged with single apps?
> 
> Can someone help? Thanks.
>  
> --
> Thanks,
> Xuan Liu
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Compact iteration of optional collection?

2016-07-28 Thread Saagar Jha via swift-users
The nil check and creating an empty array have very similar performance, in my 
naïve testing. 

Saagar Jha



> On Jul 28, 2016, at 14:59, Jacob Bandes-Storch via swift-users 
>  wrote:
> 
> You should test it out — I'd guess there's a good chance it gets optimized 
> out.
> On Thu, Jul 28, 2016 at 2:58 PM Rick Mann  > wrote:
> Yeah, I suppose that works. Feels a bit clunky, like the language lacks 
> specific support for this (in that it provides specific support for so many 
> other common constructs). But I guess I can make do with that.
> 
> I suppose there's a bit of a performance hit, in that constructing an empty 
> array and iterating over it is more expensive than a simple nil check, but 
> that's unlikely to cause issues in practice.
> 
> Thanks.
> 
> > On Jul 28, 2016, at 14:56 , Jacob Bandes-Storch  > > wrote:
> >
> > How about "for item in someOptionalContainer ?? []"  ?
> >
> > On Thu, Jul 28, 2016 at 2:55 PM, Rick Mann via swift-users 
> > mailto:swift-users@swift.org>> wrote:
> > I often call methods that return an optional collection. I then iterate 
> > over it. The problem is, it's a bit cumbersome to write:
> >
> >  if let container = someOptionalContainer
> > {
> > for item in container
> > {
> > }
> > }
> >
> > I wish I could just write
> >
> > for item in someOptionalContainer
> > {
> > }
> >
> > such that if the optional is nil, it just skips the iteration altogether.
> >
> > Is there a syntax for that (especially in Swift 3)?
> >
> >
> > --
> > Rick Mann
> > rm...@latencyzero.com 
> >
> >
> > ___
> > swift-users mailing list
> > swift-users@swift.org 
> > https://lists.swift.org/mailman/listinfo/swift-users 
> > 
> >
> 
> 
> --
> Rick Mann
> rm...@latencyzero.com 
> 
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Undefined symbols for architecture x86_64

2016-07-24 Thread Saagar Jha via swift-users
I’m guessing a framework you’ve added wasn’t built for x86. Try switching your 
build target to an iOS device.

Saagar Jha



> On Jul 24, 2016, at 18:25, Ryan Lovelett via swift-users 
>  wrote:
> 
> When linking a Cocoa framework using the release configuration I am
> getting the error below. Oddly compiling in the debug configuration
> works fine.
> 
> The code looks like this:
> 
> let _ = URLComponents(url: track.request.url, resolvingAgainstBaseURL:
> true)? .queryItems?.sorted(isOrderedBefore: { $0.name < $1.name })
> 
> Weirder still, if I make a fresh project that contains just this single
> line of code then it also compiles fine (debug and release). Not sure
> how to resolve the linker error. Also not sure how to get it to a small
> isolated test. Xcode Version 8.0 beta 3 (8S174q)
> 
> Suggestions?
> 
>> Ld 
>> /Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Products/Release/VHS.framework/Versions/A/VHS
>>  normal x86_64
>>   cd /Users/ryan/Source/VHS
>>   export MACOSX_DEPLOYMENT_TARGET=10.12
>>   
>> /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
>>  -arch x86_64 -dynamiclib -isysroot 
>> /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
>>  
>> -L/Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Products/Release
>>  
>> -F/Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Products/Release
>>  -F/Users/ryan/Source/VHS/Carthage/Build/Mac -filelist 
>> /Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Intermediates/VHS.build/Release/VHS.build/Objects-normal/x86_64/VHS.LinkFileList
>>  -install_name @rpath/VHS.framework/Versions/A/VHS -Xlinker -rpath -Xlinker 
>> @executable_path/../Frameworks -Xlinker -rpath -Xlinker 
>> @loader_path/Frameworks -mmacosx-version-min=10.12 -fobjc-link-runtime 
>> -L/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
>>  -Xlinker -add_ast_path -Xlinker 
>> /Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Intermediates/VHS.build/Release/VHS.build/Objects-normal/x86_64/VHS.swiftmodule
>>  -framework Argo -framework Curry -single_module -compatibility_version 1 
>> -current_version 1 -Xlinker -dependency_info -Xlinker 
>> /Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Intermediates/VHS.build/Release/VHS.build/Objects-normal/x86_64/VHS_dependency_info.dat
>>  -o 
>> /Users/ryan/Library/Developer/Xcode/DerivedData/VHS-dosminuksbrtjudnsmhzbgzhsbib/Build/Products/Release/VHS.framework/Versions/A/VHS
>> Undefined symbols for architecture x86_64:
>>  "Swift.UnsafeMutableBufferPointer.(subscript.materializeForSet : 
>> (Swift.Int) -> A).(closure #1)", referenced from:
>>  function signature specialization  of generic 
>> specialization  
>> with Swift.UnsafeMutableBufferPointer : 
>> Swift.MutableCollection in Swift and 
>> Swift.UnsafeMutableBufferPointer : 
>> Swift.RandomAccessCollection in Swift> of Swift._siftDown > Swift.MutableCollection, A: Swift.RandomAccessCollection> (inout A, index : 
>> A.Index, subRange : Swift.Range, isOrderedBefore : inout 
>> (A.Iterator.Element, A.Iterator.Element) -> Swift.Bool) -> () in VCR.o
>>  function signature specialization  of generic 
>> specialization  
>> with Swift.UnsafeMutableBufferPointer : 
>> Swift.MutableCollection in Swift and 
>> Swift.UnsafeMutableBufferPointer : 
>> Swift.RandomAccessCollection in Swift> of Swift._heapSort > Swift.MutableCollection, A: Swift.RandomAccessCollection> (inout A, subRange 
>> : Swift.Range, isOrderedBefore : inout (A.Iterator.Element, 
>> A.Iterator.Element) -> Swift.Bool) -> () in VCR.o
>>  function signature specialization  of generic 
>> specialization  
>> with Swift.UnsafeMutableBufferPointer : 
>> Swift.MutableCollection in Swift and 
>> Swift.UnsafeMutableBufferPointer : 
>> Swift.RandomAccessCollection in Swift> of Swift._partition > Swift.MutableCollection, A: Swift.RandomAccessCollection> (inout A, subRange 
>> : Swift.Range, isOrderedBefore : inout (A.Iterator.Element, 
>> A.Iterator.Element) -> Swift.Bool) -> A.Index in VCR.o
>> ld: symbol(s) not found for architecture x86_64
>> clang: error: linker command failed with exit code 1 (use -v to see 
>> invocation)
> 
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Why there's no Character literals?

2016-07-10 Thread Saagar Jha via swift-users
Yes, but then a similar complaint could be made that I wanted a String this 
time. The only real way to tell the difference is to use something like single 
quotes.

> On Jul 10, 2016, at 14:03, Rick Mann via swift-users  
> wrote:
>
>
>> On Jul 10, 2016, at 11:44 , Saagar Jha via swift-users 
>>  wrote:
>>
>> Well, what if you wanted to create a String with one character? There’s no 
>> way to differentiate.
>
> That hardly seems like the justification. In that case, you'd specify the 
> type:
>
>let s: String = '\n'
>
>
>>
>>> On Jul 7, 2016, at 02:35, 王 黎明 via swift-users 
>>> [swift-users@swift.org](mailto:swift-users@swift.org) wrote: >
>>
>> In Swift, we must specify the type for Character variables(because there’s 
>> no Character literals):
>>
>> let eol: Character = “\n”
>>
>> it's not a big problem, but, Is it the unique case that can’t use type infer?
>>
>> swift-users mailing list swift-users@swift.org 
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
>> --
>> -Saagar Jha
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> --
> Rick Mann
> rm...@latencyzero.com
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Why there's no Character literals?

2016-07-10 Thread Saagar Jha via swift-users
Well, what if you wanted to create a String with one character? There’s no
way to differentiate.

> On Jul 7, 2016, at 02:35, 王 黎明 via swift-users
[swift-users@swift.org](mailto:swift-users@swift.org) wrote: >

In Swift, we must specify the type for Character variables(because there’s
no Character literals):

let eol: Character = “\n”

it's not a big problem, but, Is it the unique case that can’t use type
infer?
--

swift-users mailing list swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] When does `Data.init?(capacity:)` fail?

2016-06-19 Thread Saagar Jha via swift-users
Not quite:

Swift’s policy on memory allocation failure is that fixed-size object
allocation is considered to be a runtime failure if it cannot be handled.
OTOH, APIs that can take a variable and arbitrarily large amount to
allocate should be failable. NSData falls into the later category.

Source <http://article.gmane.org/gmane.comp.lang.swift.user/1709>


On Sun, Jun 19, 2016 at 10:00 AM Karl  wrote:

> As I understand it, that’s not an error in the ‘try’ sense of the word. If
> that failure happens, it’s a catastrophic issue which should bring down the
> application.
>
> So the initialiser shouldn’t be failable; you’re right. File a bug at
> bugs.swift.org.
>
> Karl
>
> On 18 Jun 2016, at 06:06, Saagar Jha via swift-users <
> swift-users@swift.org> wrote:
>
> This <http://article.gmane.org/gmane.comp.lang.swift.user/1702> might be
> relavant. Basically, Data’s init will fail if memory can’t be allocated
> for it.
>
>
> On Fri, Jun 17, 2016 at 11:38 AM Adrian Zubarev via swift-users <
> swift-users@swift.org> wrote:
>
>> Hello there, I’m trying to optimize my code and reduce copying from
>> different buffers into a new one.
>>
>> I thought I just create a Data value with enough capacity and write
>> directly into it. My problem is that Data.init?(capacity:) can fail, but
>> why and when?
>>
>> Can someone explain this behavior to me?
>>
>> I’m sending data via TCP sockets and when recn function write directly
>> into a Data struct.
>>
>>
>>
>> --
>> Adrian Zubarev
>> Sent with Airmail
>>
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
> --
> -Saagar Jha
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> --
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] When does `Data.init?(capacity:)` fail?

2016-06-17 Thread Saagar Jha via swift-users
This  might be
relavant. Basically, Data’s init will fail if memory can’t be allocated for
it.


On Fri, Jun 17, 2016 at 11:38 AM Adrian Zubarev via swift-users <
swift-users@swift.org> wrote:

> Hello there, I’m trying to optimize my code and reduce copying from
> different buffers into a new one.
>
> I thought I just create a Data value with enough capacity and write
> directly into it. My problem is that Data.init?(capacity:) can fail, but
> why and when?
>
> Can someone explain this behavior to me?
>
> I’m sending data via TCP sockets and when recn function write directly
> into a Data struct.
>
>
>
> --
> Adrian Zubarev
> Sent with Airmail
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift 3.0 and Xcode 7.3.x

2016-06-17 Thread Saagar Jha via swift-users
You won't be able to submit to the App Store with any alternative tool
chain (such as Swift 3).
On Fri, Jun 17, 2016 at 10:59 Patrice Kouame via swift-users <
swift-users@swift.org> wrote:

> Hi Jordan - thanks for the quick reply (especially in the middle of WWDC!)
>
> I suspected as much with 7.3.x (unfortunately), but I’ve heard of folks
> running a 3.0 toolchain (from swift.org) with 7.3.x.  Besides an
> unsupported playground, what other types of side effects can I expect? Just
> trying to prepare for my worst case scenario where Xcode 8 remains flaky on
> El Capitan for a while.
>
> BTW: My Xcode 8 beta on 10.11.5 crashes repeatedly, very reproducible see
> my posts https://forums.developer.apple.com/thread/49000
> and my open bug radar report # 26849825 “Xcode 8 beta IDE crashes
> consistently”.  I hope Apple can take a look at this.  This is my first
> beta that crashed out of the box. I hope this can get some traction.  I’m
> surely not the only one.
>
> regards,
> Patrice
>
> On Jun 17, 2016, at 1:14 PM, Jordan Rose via swift-users <
> swift-users@swift.org> wrote:
>
> Hi, Patrice. Unfortunately it’s unlikely that we’ll have a Swift 3.0 for
> Xcode 7.x, because it depends on the macOS 10.12 and iOS 10 SDKs. That
> said, we (Apple) would definitely like to hear about issues running Xcode 8
> on El Capitan; if you haven’t already, please file a bug report at
> bugreport.apple.com!
>
> Best,
> Jordan
>
> On Jun 16, 2016, at 17:31, Patrice Kouame via swift-users <
> swift-users@swift.org> wrote:
>
> Swift 3.0 for Mac is currently being distributed with Xcode 8 beta.
>
> Will a swift 3.0 toolchain for Xcode 7.3.x ever happen?
>
> Currently having issues with the beta on El Capitan and my machine
> is (apparently) no longer a candidate for future MacOs versions, notably
> Sierra.
>
> Thanks in advance.
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Redeclaration of guard variable is ignored at top-level

2016-06-16 Thread Saagar Jha via swift-users
Looks like a bug…strangely, lldb’s giving number: Int = 5678.


On Thu, Jun 16, 2016 at 10:18 PM Martin R via swift-users <
swift-users@swift.org> wrote:

> Hi,
>
> I wonder why the Swift compiler does not complain about the
> redeclaration of `number` after the guard-statement in top-level code:
>
> // main.swift
> import Swift
>
> guard let number = Int("1234") else { fatalError() }
> print(number) // Output: 1234
> let number = 5678
> print(number) // Output: 1234
>
> It looks as if the statement `let number = 5678` is completely ignored.
>
> However, doing the same inside a function causes a compiler error:
>
> func foo() {
> guard let number = Int("1234") else { fatalError() }
> print(number)
> let number = 5678 //  error: definition conflicts with previous
> value
> }
>
> Tested with
> - Xcode 7.3.1, "Default" and "Snapshot 2016-06-06 (a)" toolchain
> - Xcode 8 beta.
>
> Am I overlooking something or is that a bug?
>
> Martin
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Trouble with function properties

2016-06-16 Thread Saagar Jha via swift-users
That’s how the Swift interpreter prints out closures. Try let testClosure =
{} in the REPL and you’ll get a similar result, except with different
arguments and return value due to {} being () -> ().


On Wed, Jun 15, 2016 at 8:13 PM Doug Hill via swift-users <
swift-users@swift.org> wrote:

> Thank you Saagar for looking over this code for me. I guess I got really
> caught up in the weird diagnostic message and assumed things weren’t
> working.
> Now I see that ‘afunc’ works as I expected:
>
> 60> g.afunc(numberRecords:1,userRecord:(13,9))
> 13 9
> $R3: (Int, (Int, Int)) = {
>   0 = 13
>   1 = {
> 0 = 9
> 1 = 1
>   }
> }
>
> Although I would be interested in why the compiler spits out the first
> message in the first place (e.g. the message with the strange description
> of afunc).
>
> Looking forward to see what I can do with Swift,
>
> Doug Hill
>
> On Jun 15, 2016, at 6:49 PM, Saagar Jha  wrote:
>
> `Gen` defines `afunc`, but you’re trying to access `aFunc`.
>
> On Wed, Jun 15, 2016 at 6:22 PM Doug Hill via swift-users <
> swift-users@swift.org> wrote:
>
>> I’m just starting to learn Swift and attempting to do some
>> functional-style programming. Specifically I’m learning how to create
>> generic algorithms that can be reused for many different types.
>> What I’m attempting to do is create a new object, passing functions to
>> the initializer. The class would store these functions as properties and
>> then use them for functional-style algorithms.
>>
>> The problem is I’m running into weird compiler errors/messages that I’m
>> trying to figure out. I'm hoping someone here can give me some pointers on
>> what these errors mean, and most likely what I’m doing wrong.
>>
>>   Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31) Target:
>> x86_64-apple-macosx10.9
>>
>> // =
>> class Gen {
>> typealias func1Type = (numberRecords:InputKeyType, userRecord:
>> InputValueType ) -> (OutputKeyType, OutputValueType)
>>
>> var afunc: func1Type
>>
>> init( inFunc: func1Type ) {
>> afunc = inFunc
>> }
>> }
>>
>> var g: Gen =
>> Gen( inFunc: { (numberRecords: Int, userRecord: (Int, Int)) -> (Int,
>> (Int, Int)) in
>> var b: Int = numberRecords
>> var (age, numFriends) = userRecord
>> print( (age), (numFriends) )
>> return (age, (numFriends, 1))
>> }
>> )
>> // =
>>
>>
>> What I get as output from the Swift compiler are these confusing
>> messages. I included some print statements that hopefully gives some more
>> info about what’s happening.
>>
>> g: Gen = {
>>   afunc = 0x0001012024d0 $__lldb_expr7`partial apply forwarder for
>> reabstraction thunk helper from @callee_owned (@unowned Swift.Int, @unowned
>> Swift.Int, @unowned Swift.Int) -> (@unowned (Swift.Int, (Swift.Int,
>> Swift.Int))) to @callee_owned (@in Swift.Int, @in (Swift.Int, Swift.Int))
>> -> (@out (Swift.Int, (Swift.Int, Swift.Int))) at repl6.swift
>> }
>>
>> print( (g) )
>> Gen
>>
>> print( (g.aFunc) )
>> repl.swift:48:9: error: value of type 'Gen> Int)>' has no member 'aFunc'
>> ^ ~
>>
>>
>> There’s a good chance I’m doing something wrong but I don’t know how to
>> figure out what that problem is. Any ideas?
>>
>> Thanks.
>>
>> Doug
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
> --
> -Saagar Jha
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Trouble with function properties

2016-06-15 Thread Saagar Jha via swift-users
`Gen` defines `afunc`, but you’re trying to access `aFunc`.

On Wed, Jun 15, 2016 at 6:22 PM Doug Hill via swift-users <
swift-users@swift.org> wrote:

> I’m just starting to learn Swift and attempting to do some
> functional-style programming. Specifically I’m learning how to create
> generic algorithms that can be reused for many different types.
> What I’m attempting to do is create a new object, passing functions to the
> initializer. The class would store these functions as properties and then
> use them for functional-style algorithms.
>
> The problem is I’m running into weird compiler errors/messages that I’m
> trying to figure out. I'm hoping someone here can give me some pointers on
> what these errors mean, and most likely what I’m doing wrong.
>
>   Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31) Target:
> x86_64-apple-macosx10.9
>
> // =
> class Gen {
> typealias func1Type = (numberRecords:InputKeyType, userRecord:
> InputValueType ) -> (OutputKeyType, OutputValueType)
>
> var afunc: func1Type
>
> init( inFunc: func1Type ) {
> afunc = inFunc
> }
> }
>
> var g: Gen =
> Gen( inFunc: { (numberRecords: Int, userRecord: (Int, Int)) -> (Int, (
> Int, Int)) in
> var b: Int = numberRecords
> var (age, numFriends) = userRecord
> print( (age), (numFriends) )
> return (age, (numFriends, 1))
> }
> )
> // =
>
>
> What I get as output from the Swift compiler are these confusing messages.
> I included some print statements that hopefully gives some more info about
> what’s happening.
>
> g: Gen = {
>   afunc = 0x0001012024d0 $__lldb_expr7`partial apply forwarder for
> reabstraction thunk helper from @callee_owned (@unowned Swift.Int, @unowned
> Swift.Int, @unowned Swift.Int) -> (@unowned (Swift.Int, (Swift.Int,
> Swift.Int))) to @callee_owned (@in Swift.Int, @in (Swift.Int, Swift.Int))
> -> (@out (Swift.Int, (Swift.Int, Swift.Int))) at repl6.swift
> }
>
> print( (g) )
> Gen
>
> print( (g.aFunc) )
> repl.swift:48:9: error: value of type 'Gen Int)>' has no member 'aFunc'
> ^ ~
>
>
> There’s a good chance I’m doing something wrong but I don’t know how to
> figure out what that problem is. Any ideas?
>
> Thanks.
>
> Doug
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Swift Binary Size vs. Obj-C

2016-06-15 Thread Saagar Jha via swift-users
Yep, I just took a simple app and opened up the ipa. 90% of it is the
“Frameworks” directory containing the Swift frameworks libSwiftCore.dylib,
libSwiftDarwin.dylib, etc.


On Wed, Jun 15, 2016 at 3:43 PM Seth Friedman via swift-users <
swift-users@swift.org> wrote:

> Hi all,
>
> I've seen a ton of blog posts written about all of the cool and exciting
> things about Swift, but I haven't see anything really about the downsides
> (besides the occasional post about pain points with interoperability).
> What's of biggest concern to me when considering migrating my company's app
> from Objective-C to Swift is binary size. Swift binary size seems to be
> several times larger than Objective-C, and I'm curious what data there is
> in the community to support this suspicion.
>
> For some quick data points, I created a single view controller project in
> Obj-C and one in Swift, turned off bitcode to get a better idea of what the
> binary size on device would be, and archived them. I did this in Xcode 8
> Beta 1 using Swift 3 so that I'd make sure to get any binary size
> improvements in Swift 3.
>
> The Obj-C IPA file was 639 KB. The Swift IPA file was *23.6 MB*. I know
> that the Swift runtime libs are about 4.5 MB, but subtracting that, the
> Swift IPA file is still *30x bigger than the Obj-C equivalent*. Next, I
> tried adding a simple table view controller, a Person model with a first
> and last name, and a data source that puts the first and last names in the
> table view in an attempt to make a functioning app. However, the binary
> sizes were about the same (the Obj-C one actually decreased to 635 KB).
>
> When we're talking about binary sizes this small, it's not a big deal, but
> my company's app is currently 81 MB, about 35 MB of which is code, and the
> rest is assets. If the code part of the binary size increases by orders of
> magnitude like this, we'll go way over the 100 MB cellular limit that Apple
> has set. This is also a really bad experience for customers in emerging
> markets like China and India that have poor connections.
>
> Can anyone confirm or deny that Swift binary size is orders of magnitude
> larger than Objective-C? I'm looking for the specific increase we'll see to
> take to my management in order to make a justification for whether it's
> worth it for our customers.
>
> Thanks!
>
> Seth Friedman
>
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] proper syntax for inout array handling?

2016-06-09 Thread Saagar Jha via swift-users
Nevermind, I lied. Swift does allow direct pointer arithmetic:

import Foundation

var source = [UInt8](repeating: 0x1f, count: 32)
var destination = [UInt8](repeating: 0, count: 64)

memcpy(&destination, source, 32) // the C function

memcpy(&destination + 3, source, 13) // the + operator works to offset



On Thu, Jun 9, 2016 at 7:21 PM Saagar Jha  wrote:

> Swift handling of Arrays isn’t like C (for which you can use 
> UnsafePointer)-you
> don’t access the pointer of the third element. Instead, you can use Array
> slices, which makes it a one liner:
>
> destination[destinationStartIndex.. source[sourceStartIndex..
> In your case,
>
> destination[0..<0 + 32] = source[0..<0 + 32]
> destination[3..3 + 13] = source[0..<0 + 13]
>
> As a function:
>
> func memcpy(source: [UInt8], destination: inout [UInt8], sourceStartIndex: 
> Int = 0, destinationStartIndex: Int = 0, count: Int) {
> destination[destinationStartIndex.. source[sourceStartIndex.. }
>
> memcpy(source: source, destination: &destination, count: 32)
>
> memcpy(source: source, destination: &destination, destinationStartIndex: 3, 
> count: 13)
>
>
>
> On Thu, Jun 9, 2016 at 1:38 PM Ken Burgett via swift-users <
> swift-users@swift.org> wrote:
>
>> I am converting a very dirty C program to Swift3, and their is plenty of
>> pointer arithmetic to be dealt with.  As part of the effort, I have
>> created a 'memcpy clone to help with some of the transformation.
>> Here is the output from the REPL:
>> 
>>1. var source = [UInt8](repeating: 0x1f, count: 32)
>>2. var destination = [UInt8](repeating: 0, count: 64)
>>3.
>>4. func memcpy(dest: inout [UInt8], src: inout [UInt8], count: Int)
>>5. {
>>6.   for ix in 0...count-1
>>7.   {
>>8. dest[ix] = src[ix]
>>9.   }
>>   10. }
>>   11.
>>   12. memcpy(dest: &destination, src: &source, count: 32 )
>>   13.
>>   14. memcpy(dest: &destination[3], src: &source, count: 13)
>> error: repl.swift:14:26: error: cannot convert value of type 'UInt8' to
>> expected argument type '[UInt8]'
>> memcpy(dest: &destination[3], src: &source, count: 13)
>> ==
>> which shows me that the compiler does not like the form of
>> &destination[13], and doesn't treat it as a [UInt8].
>>
>> What is the correct syntax for using a base + offset as a source or
>> destination for a memory copy?
>>
>>
>> --
>> Ken Burgett
>> Principal Software Engineer
>> Email: k...@iotone.io
>> Office: 530.693.4449
>> Mobile: 831.332.6846
>> URL: www.iotone.co
>> ___
>> swift-users mailing list
>> swift-users@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-users
>>
> --
> -Saagar Jha
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] proper syntax for inout array handling?

2016-06-09 Thread Saagar Jha via swift-users
Swift handling of Arrays isn’t like C (for which you can use UnsafePointer)-you
don’t access the pointer of the third element. Instead, you can use Array
slices, which makes it a one liner:

destination[destinationStartIndex.. wrote:

> I am converting a very dirty C program to Swift3, and their is plenty of
> pointer arithmetic to be dealt with.  As part of the effort, I have
> created a 'memcpy clone to help with some of the transformation.
> Here is the output from the REPL:
> 
>1. var source = [UInt8](repeating: 0x1f, count: 32)
>2. var destination = [UInt8](repeating: 0, count: 64)
>3.
>4. func memcpy(dest: inout [UInt8], src: inout [UInt8], count: Int)
>5. {
>6.   for ix in 0...count-1
>7.   {
>8. dest[ix] = src[ix]
>9.   }
>   10. }
>   11.
>   12. memcpy(dest: &destination, src: &source, count: 32 )
>   13.
>   14. memcpy(dest: &destination[3], src: &source, count: 13)
> error: repl.swift:14:26: error: cannot convert value of type 'UInt8' to
> expected argument type '[UInt8]'
> memcpy(dest: &destination[3], src: &source, count: 13)
> ==
> which shows me that the compiler does not like the form of
> &destination[13], and doesn't treat it as a [UInt8].
>
> What is the correct syntax for using a base + offset as a source or
> destination for a memory copy?
>
>
> --
> Ken Burgett
> Principal Software Engineer
> Email: k...@iotone.io
> Office: 530.693.4449
> Mobile: 831.332.6846
> URL: www.iotone.co
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] Looking for a Swift3 JSON parser

2016-06-08 Thread Saagar Jha via swift-users
This  one looks promising–it doesn’t
require Foundation and looks like it supports Swift 3. It has a package as
well.

On Wed, Jun 8, 2016 at 7:50 AM Ken Burgett via swift-users <
swift-users@swift.org> wrote:

> I am looking for a parser for JSON is compatible with Swift 3 on Linux.
> SwiftyJSON looks interesting, but it is Swift 2.2 compatible, AFAIK.
> Any URL will be appreciated, and a Swift3 package would bring joy.
>
> --
> Ken Burgett
> Principal Software Engineer
> Email: k...@iotone.io
> Office: 530.693.4449
> Mobile: 831.332.6846
> URL: www.iotone.co
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users


Re: [swift-users] expression too complex

2016-06-06 Thread Saagar Jha via swift-users
I’ve seen that this tends to happen with operators that are really
overloaded-stuff like +, *, etc. The compiler seems to take longer to
figure out which function to use.

On Mon, Jun 6, 2016 at 3:09 PM Joe Groff via swift-users <
swift-users@swift.org> wrote:

>
> > On Jun 6, 2016, at 3:06 PM, G B via swift-users 
> wrote:
> >
> > Is progress being made on the type checker to get the compiler to stop
> whinging about the complexity of expressions?
>
> Yes, a lot of cases work much better in Swift 3. You might give these a
> try in a nightly build. Please file a bug if you continue to see this in
> Swift 3 though.
>
> -Joe
>
> >
> > I can’t really trim down the full project to isolate a good test case,
> but I’m getting a compiler error on this line of code:
> > let v=T.Vector4Type([axis[0]*s, axis[1]*s, axis[2]*s, cos(a/2.0)])
> >
> >
> > Interestingly, this line compiled fine (everything is the same except
> the last list element is moved to the front):
> > let v=T.Vector4Type([cos(a/2.0), axis[0]*s, axis[1]*s, axis[2]*s])
> >
> >
> >
> > The initializer that this code is embedded in is this:
> > public init(axis:T.Vector3Type, angle a:T){
> >let s=sin(a/2.0)
> >let v=T.Vector4Type([axis[0]*s, axis[1]*s, axis[2]*s, cos(a/2.0)])
> >let l=v.length()
> >self.init(v/l)
> > }
> >
> > I’m running this in a playground, I don’t know if that makes a
> difference.
> >
> > I’m willing to wait a little longer for the complier to do its job if it
> means I don’t have to break my code down to one operation per line.
> > ___
> > swift-users mailing list
> > swift-users@swift.org
> > https://lists.swift.org/mailman/listinfo/swift-users
>
> ___
> swift-users mailing list
> swift-users@swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-- 
-Saagar Jha
___
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users