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
shodanjr_gr
Nov 20, 2007
So is there a way to explicitly define a main() entry point for a program written in Swift? The iBook that's available online doesn't specify anything (it just says that stuff in global scope gets executed first) and I don't have access to the Betas so I can play around.

Adbot
ADBOT LOVES YOU

shodanjr_gr
Nov 20, 2007

This is an exception-al (:haw:) writeup. Thank you.

If I'm reading this correctly, this will also handle nested try calls with rethrowing, correct?

Also, does Swift allow C-style typedefs? Those try function signatures look like brainfuck at first glance.

shodanjr_gr
Nov 20, 2007
So doesn't Xcode 6 support creating a Swift app for OS X through the new project wizard? I get the option for iOS apps but not for OSX...

shodanjr_gr
Nov 20, 2007

pokeyman posted:

Xcode 6.1 brings Swift to OS X. Check the App Store for an update!

If you're using 6.1 already then I dunno.

Doh...that makes sense.

shodanjr_gr
Nov 20, 2007
So I've decided to get back into Swift since I've got some time on my hands. Maybe this eluded me the first time around but is there no way to tag methods (for classes) as non-mutating to the instance's state? Basically I'm trying to understand if there exists a mechanism similar to C++'s "const".

shodanjr_gr
Nov 20, 2007

Flobbster posted:

If you use structs instead of classes, then you get what you want the opposite way: all methods are "const" (non-mutating) unless you specify the mutating keyword. This won't help if you're forced to use classes, though (e.g., if you're inheriting from a framework class).

Thanks for the reply! I was aware of that but obviously structs have other tradeoffs. It would be interesting to hear the motivation behind such a design choice (paging rjmccall).

e: "defer" is the most beautiful language feature I have ever seen in my entire life.

shodanjr_gr fucked around with this message at 08:35 on Jun 19, 2015

shodanjr_gr
Nov 20, 2007

Dessert Rose posted:

Seriously. Such an elegant solution to the problem.

Indeed! And from messing around in Playgrounds, it seems that you can have multiple of them within a scope and they get executed in sequence when you bail out. Which makes them even more awesome.



I really appreciate the very detailed response and I can understand that properly enforcing const-correctness imposes some (non-trivial) overhead to developers which leads a lot of folks to cut corners and/or not do it right. So from what I gather, the only way (currently) for the compiler to enforce non-mutation is to use structs and "eat" the value-type overhead?

Adbot
ADBOT LOVES YOU

shodanjr_gr
Nov 20, 2007
Quick question on doing interval matching in a switch statement:

code:
switch diff {
        case 0.0:
		// no difference
        case -Double.infinity..<0.0:
            	// negative difference
        case 0.0...Double.infinity:
               // positive difference
        default:
            // error, shouldn't happen		
        }
Is there a way to implement this without the "cludgy" closed interval in the third case ([0.0 to Infinity]). The half-open range operator can only be half-open on the upper bound as far as I can tell and swapping the operands in order to get a "reverse range" is a no go.

  • Locked thread