[swift-evolution] Shortcut for creating arrays

Radosław Pietruszewski radexpl at gmail.com
Sat Apr 9 11:05:10 CDT 2016


FWIW, in Swift 3:

“h j c k”.componentsSeparated(by: “”)

or 

“h j c k”.componentsSeparatedByCharacters(in: .whitespace())

which is slightly better.

Regarding the proposal, I love Ruby’s %w(foo bar) and other nice shortcuts like that, but short-term I think we have bigger problems in Swift.

I would love if we had a macro system that would allow something like this, though.

— Radek

> On 08 Apr 2016, at 18:38, Ross O'Brien via swift-evolution <swift-evolution at swift.org> wrote:
> 
> A function that splits by whitespace would be this:
> 
> "h j c k".componentsSeparatedByCharactersInSet(NSCharacterSet.whiteCharacterSet())
> 
> 'componentsSeparatedByWhitespace' might be a nice addition as a shortcut for that though?
> 
> 
> On Fri, Apr 8, 2016 at 3:38 PM, James Campbell <james at supmenow.com <mailto:james at supmenow.com>> wrote:
> Pehaps we could have a function that splits by whitespace.
> 
> "h j c k".split()
> 
> ___________________________________
> 
> James⎥Alex's Minder
> 
> james at supmenow.com <mailto:james at supmenow.com>⎥supmenow.com <http://supmenow.com/>
> Sup
> 
> Runway East
> 
> 
> 10 Finsbury Square
> 
> London
> 
> 
> EC2A 1AF 
> 
> 
> On 8 April 2016 at 15:05, Ross O'Brien via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Well, you can do this already:
> let words = "rats live on no evil star".componentsSeparatedByString(" ")
> so I don't know how much a shortcut is needed.
> 
> And given '%w' would currently be impossible in Swift as an operator containing a letter, is there a Swiftier function name or operator for this?
> 
> On Fri, Apr 8, 2016 at 2:20 PM, Arsen Gasparyan via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> Hey guys,
> 
> Very often we need to create an array strings. It's a routine task and I really like shortcut in Ruby that shortcut makes everyday coding a little bit easier and fun:
> 
>    words = %w[rats live on no evil star]
> 
> What do you think about adding something like this in Swift?
> 
> Cheers,
> Arsen
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160409/f8588fa7/attachment.html>


More information about the swift-evolution mailing list