Re: [swift-users] the pain of strings

2017-06-30 Thread Taylor Swift via swift-users
I agree, and the new format of the swift 4 API docs are much harder to find things in than the swift 3 ones. Perusing all the types and free functions in alphabetical order is so much easier than trying to guess what “topic” something is sorted under. On Sat, Jul 1, 2017 at 12:54 AM, David Baraff

Re: [swift-users] the pain of strings

2017-06-30 Thread David Baraff via swift-users
> On Jun 30, 2017, at 9:48 PM, Taylor Swift via swift-users > wrote: > > > Swift's strings were very deliberately designed this way. It's tougher to get > off the ground, sure, but it's better in the long run. > > > It probably is, but the correct idiom is not very well known, and sadly mos

Re: [swift-users] Class vs Structures

2017-06-30 Thread Taylor Swift via swift-users
An addendum: if something represents a specific “thing” that can’t be duplicated without consequence, often that means it should be stored in one specific place in your code, not made into a class. On Fri, Jun 30, 2017 at 10:10 PM, Brent Royal-Gordon via swift-users < swift-users@swift.org> wrote:

Re: [swift-users] the pain of strings

2017-06-30 Thread Taylor Swift via swift-users
> Swift's strings were very deliberately designed this way. It's tougher to > get off the ground, sure, but it's better in the long run. > > It probably is, but the correct idiom is not very well known, and sadly most tutorials and unofficial guides are still teaching dumb ways of subscripting into

Re: [swift-users] the pain of strings

2017-06-30 Thread Brent Royal-Gordon via swift-users
> On Jun 30, 2017, at 2:44 PM, David Baraff via swift-users > wrote: > > Python: > shortID = longerDeviceID[-2:]# give me the last two > characters > > Swift: > let shortID = > String(longerDeviceID.characters.dropFirst(longerDeviceID.characters.count - > 2)) This actually

Re: [swift-users] Class vs Structures

2017-06-30 Thread Brent Royal-Gordon via swift-users
> On Jun 29, 2017, at 10:40 AM, Vitor Navarro via swift-users > wrote: > > Do you guys have any guideline regarding usage here? Here's my suggestion: Use a class when the object represents a specific *thing* that can't be duplicated without consequence; use a struct (or enum) when the instan

Re: [swift-users] the pain of strings

2017-06-30 Thread Charles Srstka via swift-users
> On Jun 30, 2017, at 4:44 PM, David Baraff via swift-users > wrote: > > I know, I’ve read tons about about this. I sympathize. Unicode, it’s all > very complex. > > But. > > BUT. > > Python: > shortID = longerDeviceID[-2:]# give me the last two > characters > > Swift:

Re: [swift-users] the pain of strings

2017-06-30 Thread David Baraff via swift-users
> On Jun 30, 2017, at 6:06 PM, Kyle Murray wrote: > > Hi David, > > You can see the new APIs for Swift 4's String here: > https://developer.apple.com/documentation/swift/string?changes=latest_minor > wow, > that’s a

Re: [swift-users] the pain of strings

2017-06-30 Thread Adrian Zubarev via swift-users
Plus if you want to play with Swift 4 without running a toolchain or the new Xcode you can do it in your browser: https://swift.sandbox.bluemix.net/#/repl Just change that repl to Swift 4. --  Adrian Zubarev Sent with Airmail Am 1. Juli 2017 um 03:02:38, Adrian Zubarev (adrian.zuba...@devandar

Re: [swift-users] the pain of strings

2017-06-30 Thread Kyle Murray via swift-users
Hi David, You can see the new APIs for Swift 4's String here: https://developer.apple.com/documentation/swift/string?changes=latest_minor The page indicates changes and additions since Xcode 8.3's Swift 3.1, correspo

Re: [swift-users] the pain of strings

2017-06-30 Thread David Baraff via swift-users
I only know a little bit of what I’ve read online in blog posts and such. I don’t have access to the Swift 4 API documentation, since i’m not running the xcode beta yet. Is there someplace I can see the actual new API’s for String, in swift 4? i googled but haven’t found it yet. > On Jun 30

Re: [swift-users] the pain of strings

2017-06-30 Thread Adrian Zubarev via swift-users
The best docs you can get without Xcode I know about is this one here:  https://developer.apple.com/documentation/swift/string In Swift 4 a String will yet again become a collection type. --  Adrian Zubarev Sent with Airmail Am 1. Juli 2017 um 02:57:05, David Baraff (davidbar...@gmail.com) schr

Re: [swift-users] the pain of strings

2017-06-30 Thread Adrian Zubarev via swift-users
Well you’ve mentioned Swift 4 in your original post, therefore I provided a solution using Swift 4. It’s returning a view called `Substring`. --  Adrian Zubarev Sent with Airmail Am 1. Juli 2017 um 00:38:42, David Baraff (davidbar...@gmail.com) schrieb: I’m sorry, but I don’t see suffix() as a

Re: [swift-users] Class vs Structures

2017-06-30 Thread Maury Markowitz via swift-users
> On Jun 29, 2017, at 2:42 PM, Taylor Swift via swift-users > wrote: > > When in doubt, go with a struct. Probably nineteen types out of twenty I > write are structs. The the 20th is likely when you're using one of Obj-C's features, like KVO. ___ s

Re: [swift-users] the pain of strings

2017-06-30 Thread David Baraff via swift-users
I’m sorry, but I don’t see suffix() as a member function in any documentation, nor does it complete in Xcode. Is this perhaps only in Swift 4? If so, that’s a definite improvement! Begin forwarded message: > From: Adrian Zubarev > Subject: Re: [swift-users] the pain of strings > Date: June 30

Re: [swift-users] the pain of strings

2017-06-30 Thread Adrian Zubarev via swift-users
This looks way better than the subscript in Python and 1000 times better than your example. It might be a good idea to look up possible API first before writing such ugly long lines. I mean they get the job done, but just why so complicated? :( --  Adrian Zubarev Sent with Airmail Am 1. Juli

Re: [swift-users] the pain of strings

2017-06-30 Thread Adrian Zubarev via swift-users
let longString = "1234567890" print(longString.suffix(2)) // prints "90" --  Adrian Zubarev Sent with Airmail Am 30. Juni 2017 um 23:45:01, David Baraff via swift-users (swift-users@swift.org) schrieb: I know, I’ve read tons about about this. I sympathize. Unicode, it’s all very complex. But

[swift-users] the pain of strings

2017-06-30 Thread David Baraff via swift-users
I know, I’ve read tons about about this. I sympathize. Unicode, it’s all very complex. But. BUT. Python: shortID = longerDeviceID[-2:] # give me the last two characters Swift: let shortID = String(longerDeviceID.characters.dropFirst(longerDeviceID.characters.count - 2)) I can

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Taylor Swift via swift-users
You should probably use `withExtendedLifetime(_:_:) ` for this. On Fri, Jun 30, 2017 at 2:54 PM, Charles Srstka via swift-users < swift-users@swift.org> wrote: > > On Jun 30, 2017, at 1:47 PM, Mike Ferenduros via swift-

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Mike Ferenduros via swift-users
Awesome, thanks :) > On 30 Jun 2017, at 22:27, Joe Groff wrote: > > >> On Jun 30, 2017, at 12:25 PM, Mike Ferenduros >> wrote: >> >> Ah, I think I was unclear - I want to extend the lifetime into an escaping >> closure, not just within a scope, and I was wondering what the minimal way >> i

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 12:25 PM, Mike Ferenduros > wrote: > > Ah, I think I was unclear - I want to extend the lifetime into an escaping > closure, not just within a scope, and I was wondering what the minimal way is > to do that. I see. Using `withExtendedLifetime` inside the closure still o

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Mike Ferenduros via swift-users
Ah, I think I was unclear - I want to extend the lifetime into an escaping closure, not just within a scope, and I was wondering what the minimal way is to do that. > On 30 Jun 2017, at 22:15, Joe Groff wrote: > > >> On Jun 30, 2017, at 12:13 PM, Mike Ferenduros >> wrote: >> >> With an emp

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 12:13 PM, Mike Ferenduros > wrote: > > With an empty body, you mean? I'd say it's probably more readable to nest the code that's dependent on the lifetime of the object in the block body, though you can just put `withExtendedLifetime(x) { }` at the end of the region (or

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 11:47 AM, Mike Ferenduros via swift-users > wrote: > > I'm doing a RAII sort of thing with an object, and would like to keep it > alive until an completion-block is called (asynchronously). > > Is it sufficient to say '_ = x' in the completion-block to keep a live > ref

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Mike Ferenduros via swift-users
With an empty body, you mean? > On 30 Jun 2017, at 22:00, Joe Groff wrote: > > >> On Jun 30, 2017, at 11:47 AM, Mike Ferenduros via swift-users >> wrote: >> >> I'm doing a RAII sort of thing with an object, and would like to keep it >> alive until an completion-block is called (asynchronous

Re: [swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Charles Srstka via swift-users
> On Jun 30, 2017, at 1:47 PM, Mike Ferenduros via swift-users > wrote: > > I'm doing a RAII sort of thing with an object, and would like to keep it > alive until an completion-block is called (asynchronously). > > Is it sufficient to say '_ = x' in the completion-block to keep a live > refer

[swift-users] Is '_ = x' guaranteed to hold a reference to x?

2017-06-30 Thread Mike Ferenduros via swift-users
I'm doing a RAII sort of thing with an object, and would like to keep it alive until an completion-block is called (asynchronously). Is it sufficient to say '_ = x' in the completion-block to keep a live reference to the object? I was told that the optimiser is free to discard this line, and thus

Re: [swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Taylor Swift via swift-users
I believe UnsafeRawPointer is a subtype of any UnsafePointer type, so UnsafePointer’s are always implicitly convertible to UnsafeRawPointers. So even the following compiles: import Foundation func f(_ a:UnsafeRawPointer) { } let data = Data(bytes: [1, 2, 3, 4]) data.withUnsafeBytes{ (ptr:Unsaf

Re: [swift-users] Swift alternative for heterogeneous collection of objects with "generic" contents.

2017-06-30 Thread Joe Groff via swift-users
> On Jun 29, 2017, at 10:59 PM, Mikhail Seriukov via swift-users > wrote: > > Hello everyone, > In objc there is quite common pattern when we use a base class with a type > property and concrete subclasses where type is uniquely identifying the > subclass. > We can then safely put subclasses

Re: [swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Joe Groff via swift-users
> On Jun 30, 2017, at 7:40 AM, Martin R via swift-users > wrote: > > I have a C function > >void myfunc(const void *ptr); > > which is imported to Swift as > >func myfunc(_ ptr: UnsafeRawPointer!) > > This compiles and runs without problems: > >let data = Data(bytes: [1, 2, 3,

[swift-users] swift package manager sources as symbolic links

2017-06-30 Thread Rick Summerhill via swift-users
I have an application using only swift source code that works fine on mac osx. It is a UI app and I’d like to create a command line version separate from UI version. I’ve also separated the model code into a separate framework and linked it to the UI version. I’d like to use that framework co

Re: [swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Martin R via swift-users
> On 30. Jun 2017, at 16:57, Daniel Dunbar wrote: > >> >> On Jun 30, 2017, at 7:40 AM, Martin R via swift-users >> wrote: >> >> I have a C function >> >> void myfunc(const void *ptr); >> >> which is imported to Swift as >> >> func myfunc(_ ptr: UnsafeRawPointer!) >> >> This compiles

Re: [swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Daniel Dunbar via swift-users
> On Jun 30, 2017, at 7:40 AM, Martin R via swift-users > wrote: > > I have a C function > >void myfunc(const void *ptr); > > which is imported to Swift as > >func myfunc(_ ptr: UnsafeRawPointer!) > > This compiles and runs without problems: > >let data = Data(bytes: [1, 2, 3,

[swift-users] Passing Data to a f(void *) function

2017-06-30 Thread Martin R via swift-users
I have a C function void myfunc(const void *ptr); which is imported to Swift as func myfunc(_ ptr: UnsafeRawPointer!) This compiles and runs without problems: let data = Data(bytes: [1, 2, 3, 4]) data.withUnsafeBytes { (ptr) in myfunc(ptr) } // (A) and the type of `pt

Re: [swift-users] Compilation time problems when building matrices

2017-06-30 Thread Elia Cereda via swift-users
> The intermediates are also things you’re going to want to store if anything > for code clarity since the array literal starts looking messy when you shove > long expressions into it. Yes, I agree. I guess having everything in the matrix looks kind of nice with simple expressions, but starts t

[swift-users] UIDocumentBrowserViewController Bug in Xcode 9 Beta 2?

2017-06-30 Thread Howard Lovatt via swift-users
Hi, I am having problems with UIDocumentBrowserViewController Bug in Xcode 9 Beta 2, was working with beta 1. The symptom is that you can't create a new document, on most pages the + icon is missing or greyed out. On the browse page it is present and not greyed out, but doesn't work. EG If you s