Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Possibly-stupid question: can I for-in iterate through an enum, e.g. the Suit enum in the card examples?

Adbot
ADBOT LOVES YOU

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Can do! Let me know if you want the rdar ID once it's filed.

As an aside, I just wrote my first (very simple) view controller in Swift and I'm ready to never look back. Great work, and thanks to you and your team.

edit: filed, rdar://17102392

Meat Street fucked around with this message at 05:51 on Jun 3, 2014

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Sure: https://gist.github.com/tomburns/8975715cd4811d30417f

Like I said, dead simple. But it works!

Radar filed for the enum iteration and linked in my post above.

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Kind of a hack, but if you have the value as a variable and start typing its name, the autocomplete indicates its type.

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit

Axiem posted:

Oh, and I think I heard an Apple Engineer today slip up and use the code name for Swift instead of Swift. Those in Apple: any idea if it is actually a Firefly reference? (Or is it just as likely to have been the wrong word, but not the codename)

So uh, since you don't work at Apple: what was it? Serenity?

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
So this is now a thing: http://terribleswiftideas.tumblr.com

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
rjmccall: I saw that Chris retweeted someone talking about the -Otime flag to disable runtime safety checks. I have to assume this wasn't a general endorsement of using that flag, right? Am I missing something here? Unless your code is basically a series of proofs a la Haskell, I don't know why you'd want to opt out of that.

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
I'm screwing around in a playground this morning, and noticing that my quick little fibonacci function isn't benefitting from any tail recursion. Is this due to the playground environment, or does Swift really not have any tail call optimization?

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Sanity check before I file a radar:

code:
func fibonacci(n: Int) -> Int {
    func fibonacciStep(a: Int, b: Int, n: Int) -> Int {
        if (n > 0) {
            return fibonacciStep(b, a+b, n-1)
        } else {
            return a
        }
    }

    return fibonacciStep(0, 1, n)
}
This should be perfectly legal, right? It crashes Xcode every time as written above, but if I don't nest the functions it works just fine.

e: finally got it to spit out an error instead of crashing:

code:
Playground execution failed: error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x1).
The process has been left at the point where it was interrupted, use "thread return -x" to return to the state before expression evaluation.
* thread #1: tid = 0x4b7f8b, 0x0000000000000001, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x1)
  * frame #0: 0x0000000000000001

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit

Ender.uNF posted:

edit: my rationale is that CoreData already uses exceptions so if you want to interoperate you need to be able to deal with them.

It was a design decision of the language to not have exceptions and I doubt they'll double back on that, nor would I use them if they were added, but this does raise (heh) an interesting question: does the Core Data talk this year have anything to say about usage patterns in Swift?

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
rjmccall (or anyone else), I'm curious: do you have any recommendations as far as getting up to speed on the more functional side of things? Obviously it doesn't have to be Swift-specific. Last time I tried Learn You A Haskell it flew over my head, but maybe I should give it another shot now that I have some more concrete motivation :)

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Just noticed that book 2, Using Swift with Cocoa and Objective-C, is up on iBooks: https://itunes.apple.com/us/book/using-swift-cocoa-objective/id888894773?mt=11

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
New Apple Blog, three words I never thought I'd type together:

https://developer.apple.com/swift/blog/

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
Possibly-stupid question for rjmccall or anyone else: Why does ArraySlice exist? A friend and I were trying to reason about it, but given the copy-on-write Array semantics we couldn't come to a conclusion. I'm probably missing something obvious.

Adbot
ADBOT LOVES YOU

Meat Street
Oct 17, 2004

knowin' nothin' in life but to be legit
That's one way, or you can make the methods you want to test (and the classes they're declared in) public. Either way the issue you're running into is that your classes aren't exposed outside the app module, so your test target can't see them.

  • Locked thread