OT: Swift is now open source
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Sun Dec 6 02:43:24 PST 2015
On 2015-12-06 03:02, Michel Fortin wrote:
>>> Apple's API is still rather verbose and hard to discover, but that is
>>> not swift's fault.
>>
>> They could have gone the D route by separating the method name from
>> the selector:
>>
>> extern(Objective-C) class Foo
>> {
>> void bar()
>> @selector("thisIsMyReallyLongSelector:withAnotherSelector:");
>> }
>
> You can do that in Swift too with @objc(some:selector:).
But they (Apple) didn't choose to use that feature ;)
> And for Swift 3 they do plan to give Swift-specific names to pretty much all methods in
> the Apple frameworks.
> https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md
Seems interesting.
> You can be less verbose if you want:
>
> let str = "Hello, playground"
> str[str.startIndex.advancedBy(2) ..< str.endIndex.advancedBy(-1)]
I tried that but couldn't make it to work. Not sure what I did wrong.
> Also note that those special index types are actually iterators.
Aha, I didn't know that.
> You're decoding characters (grapheme clusters) as you advance those indexes.
Not really what I needed, for me it would be enough with slicing the bytes.
> It's called indexOf. (Remember, the index type is an iterator.) It does
> return an optional. It will work for any type conforming to the
> ContainerType protocol where Element conforms to Equatable. Like this:
>
> let str = "Hello, playground"
> let start = str.unicodeScalars.indexOf("p")!
> let end = str.unicodeScalars.indexOf("g")!
> str.unicodeScalars[start ..< end] // "play"
> str.unicodeScalars[start ... end] // "playg"
I was looking for a method to return the first element matching a predicate.
If it's an iterator I would expect to be able to get the value it points
to. I can't see how I can do that with an Index in Swift.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list