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
rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Meat Street posted:

Possibly-stupid question: can I for-in iterate through an enum, e.g. the Suit enum in the card examples?

It's a feature we've thought about. Feel like filing a bug to ask for it?

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

unpurposed
Apr 22, 2008
:dukedog:

Fun Shoe

Meat Street posted:

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.

Mind putting it up for comparisons sake?

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.

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do
Based on comments I've come across elsewhere on the Internet, it sounds like there are a lot of people with strong opinions about Swift, and they tend to be negative toward the language's design because of little things such as the range operators as noted above. You just can't win them all, I guess. (Frankly, I'm in the ".." includes the last number camp, mostly because I see that number as "standing in" for the last dot, but I can survive either way. It's something a good test should catch, if I get it wrong.)

Tomorrow morning, when I can get back to Moscone (instead of dealing with lovely hotel Wi-Fi) I'm going to play around with the Unit Testing.

Looking at the Swift documentation, I don't see any reference to private/public methods. Is everything public, or am I just missing something in the documentation?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Axiem posted:

Looking at the Swift documentation, I don't see any reference to private/public methods. Is everything public, or am I just missing something in the documentation?

Everything is public for now. We expect to have basic access control for 1.0.

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

rjmccall posted:

Everything is public for now. We expect to have basic access control for 1.0.

Ok cool, I came here to ask this. The lack of documentation about access control at all had me worried that the answer was "use a bunch of anonymous functions".

Siguy
Sep 15, 2010

10.0 10.0 10.0 10.0 10.0

quote:

Methods on classes have one important difference from functions. Parameter names in functions are used only within the function, but parameters names in methods are also used when you call the method (except for the first parameter). By default, a method has the same name for its parameters when you call it and within the method itself.

I'm curious about this distinction. Why not let function calls also include parameter names?

Sophy Wackles
Dec 17, 2000

> access main security grid
access: PERMISSION DENIED.





I've been browsing the documentation and Swift looks pretty interesting. Just when I thought I was getting the hang of Objective-C though! So many languages to learn for mobile development.

eschaton
Mar 7, 2007

Don't you just hate when you wind up in a store with people who are in a socioeconomic class that is pretty obviously about two levels lower than your own?

Axiem posted:

Is Swift going to be supporting unit testing and the like? My workplace is thoroughly in the TDD camp (as am I), and having a language that really supports it would be fantastic.

XCTest has basic support for Swift, including the new testing features announced today. If there's anything specific you'd like to see in the Swift testing experience we'd love to hear your thoughts on it.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Siguy posted:

I'm curious about this distinction. Why not let function calls also include parameter names?

There are a couple different things in play here.

First, there's value in all calls to the same entity looking consistent, as opposed to some using argument names and others not. A scripting language probably wouldn't care, but we do. That's probably not in flux.

Second, there was a sense among some of us that native Swift declarations shouldn't feel completely different from imported C/ObjC declarations. ObjC methods have argument names, but C functions do not. I don't think I agree with this position, but it's where we are right now. This probably is in flux.

You still can provide argument names for free functions (in which case they'll become required); they're just not the default.

EngineerJoe
Aug 8, 2004
-=whore=-



Super interesting thread. It's neat to see the thought that goes into designing a language that will be as important as Swift. My question is will we be able to get the string representation of enums?

EL BROMANCE
Jun 10, 2006

COWABUNGA DUDES!
🥷🐢😬



Whenever I looked into learning Obj-C, all the books pretty much said "Oh before you learn this, you REALLY should get your head around C first...". Is Swift developed so you can essentially go into it fresh? I've done basic stuff in Python and a few web scripts but never any C based languages and that always put me off making even basic apps for iOS.

Also, presumably even though the keynotes were showing how well Swift lives alongside C and Obj-C, that's only really there for legacy purposes and Swift is all you'd actually need for fully featured apps, if that's the only language you want to use?

EngineerJoe
Aug 8, 2004
-=whore=-



EL BROMANCE posted:

Whenever I looked into learning Obj-C, all the books pretty much said "Oh before you learn this, you REALLY should get your head around C first...". Is Swift developed so you can essentially go into it fresh? I've done basic stuff in Python and a few web scripts but never any C based languages and that always put me off making even basic apps for iOS.

Also, presumably even though the keynotes were showing how well Swift lives alongside C and Obj-C, that's only really there for legacy purposes and Swift is all you'd actually need for fully featured apps, if that's the only language you want to use?

Swift doesn't sit on top of C like Obj-C does so you should be fine. It might even be easier if you don't know C since it diverges pretty significantly. I think that, from what's been said so far, you should be fine only knowing Swift for iOS development however there's a huge amount of open source code and libraries that you will lose out on if you cut out objective-c completely.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
At the moment trying to learn Swift without knowing Objective-C is probably not going to end well, but long term it seems perfectly reasonable to learn it without knowing C or Objective-C first, although you'll probably end up needing to know all three to write anything substantial.

lord funk
Feb 16, 2004

Plorkyeran posted:

At the moment trying to learn Swift without knowing Objective-C is probably not going to end well, but long term it seems perfectly reasonable to learn it without knowing C or Objective-C first, although you'll probably end up needing to know all three to write anything substantial.

I disagree. I think if your goal is to learn Swift you aren't going to get much benefit from trudging through ObjC. Plus the pedagogical advantage of learning in the Playground environment is fantastic.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Flobbster posted:

I'd love to see a language do something similar to a proper mathematical interval syntax for integral ranges.

Factor does this, but like everything else the operators are postfix.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

lord funk posted:

I disagree. I think if your goal is to learn Swift you aren't going to get much benefit from trudging through ObjC. Plus the pedagogical advantage of learning in the Playground environment is fantastic.
If your goal is to just learn Swift then sure, you won't need to ever learn objective-c once the docs are fully in place. If your goal is to actually write nontrivial apps in Swift, you'll need to know Objective-C at least well enough to debug issues when using Objective-C libraries.

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Haven't finished reading the book yet... is there a way to inspect the type of a variable or constant in the playground? like ghc's :t

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.

lord funk
Feb 16, 2004

Plorkyeran posted:

If your goal is to just learn Swift then sure, you won't need to ever learn objective-c once the docs are fully in place. If your goal is to actually write nontrivial apps in Swift, you'll need to know Objective-C at least well enough to debug issues when using Objective-C libraries.

I look at it from the same perspective as what EL BROMANCE said about the books that insisted that you needed a solid C foundation. I skipped that when learning ObjC, and I work with old C frameworks like CoreAudio all the time. You just kind of look up what you need when you get there. :shrug:

I'm really excited for the talk about integrating Swift with ObjC.

Question for rjmccall: will there be a Swift version of sets?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!

Meat Street posted:

Kind of a hack, but if you have the value as a variable and start typing its name, the autocomplete indicates its type.

Thanks, this worked well enough that I figured out where my problem was.

If you do a range subscript on an Array, you don't get an Array back. You get a Slice. They're not freely interchangeable. So if you want an Array, convert it with Array(names[0..5])

Axiem
Oct 19, 2005

I want to leave my mind blank, but I'm terrified of what will happen if I do

eschaton posted:

XCTest has basic support for Swift, including the new testing features announced today. If there's anything specific you'd like to see in the Swift testing experience we'd love to hear your thoughts on it.

I'll play with it and see what I come up with. Is the best way to provide feedback to file Radars, or is there someway else?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Filburt Shellbach posted:

Haven't finished reading the book yet... is there a way to inspect the type of a variable or constant in the playground? like ghc's :t

I'm not totally up on playgrounds, but IIRC, you can option-click on random things.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

lord funk posted:

Question for rjmccall: will there be a Swift version of sets?

Almost certainly.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

EngineerJoe posted:

Super interesting thread. It's neat to see the thought that goes into designing a language that will be as important as Swift. My question is will we be able to get the string representation of enums?

Yes, it's something we want to make easy to do.

Toady
Jan 12, 2009

Flappy Bird in Swift: https://github.com/fullstackio/FlappySwift

Py-O-My
Jan 12, 2001

Axiem posted:

there are a lot of people with strong opinions about Swift, and they tend to be negative toward the language's design because of little things

:monocle:

a neurotic ai
Mar 22, 2012
Was/is there any relation between the language 'Swift' and the code name attributed to the CPU in the A6 SoC (also swift).

IIRC A7 is Cyclone.

'yeah I'm working on swift right now'

'Sorry which division?'

Seems like cross wires or a coincidence?

Kobayashi
Aug 13, 2004

by Nyc_Tattoo
I don't write code for my day job, so I'm much less knowledgeable than most of the people in this thread. I'm trying to get my head around optionals. At a high level, I think it's trying to prevent accidentally using a declared but uninitialized variable from crashing the program. So:

code:
var s1: String   // won't compile because there's no value?
var s2 = "value"  // OK, with String inferred? 
var s3: String?  // OK and essentially means "nil" right now?
Am I on the right track?

FamDav
Mar 29, 2008

Kobayashi posted:

I don't write code for my day job, so I'm much less knowledgeable than most of the people in this thread. I'm trying to get my head around optionals. At a high level, I think it's trying to prevent accidentally using a declared but uninitialized variable from crashing the program. So:

code:
var s1: String   // won't compile because there's no value?
var s2 = "value"  // OK, with String inferred? 
var s3: String?  // OK and essentially means "nil" right now?
Am I on the right track?

yes. You can think of String? as a class that can either have Some String or None.

In most languages you have to do something like

code:

var butts : String? = nil

if butts.isSome() {
  butts.getValue().doAThing()
}
whereas in swift, they effectively generate this logic for you when you do

code:
butts?.doAThing();
which is p nice imo

ultramiraculous
Nov 12, 2003

"No..."
Grimey Drawer

Ocrassus posted:

Was/is there any relation between the language 'Swift' and the code name attributed to the CPU in the A6 SoC (also swift).

IIRC A7 is Cyclone.

'yeah I'm working on swift right now'

'Sorry which division?'

Seems like cross wires or a coincidence?

I'm pretty sure rjmccall mentioned it was a recent marketing name.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

EngineerJoe posted:

Super interesting thread. It's neat to see the thought that goes into designing a language that will be as important as Swift. My question is will we be able to get the string representation of enums?

Also can you add a deriving mechanism like Haskell so I don't have to reimplement stuff like equality and string representation + json serialization?

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
Are there any documentation playgrounds in the shipping Xcode beta? I couldn't find the NSDateFormatter one mentioned in SotU.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Malcolm XML posted:

Also can you add a deriving mechanism like Haskell so I don't have to reimplement stuff like equality and string representation + json serialization?

We want to, yes.

Geno
Apr 26, 2004
STUPID
DICK
So the only way for me to mess around with this language right now is paying $99 for a developer license? :psydwarf:

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
I'm sure it is politically difficult, but we really need a better way to communicate besides filing radars. I know you guys are eager to get feedback but there's a layer of beauracracy in between us that measures their self worth by how many radars they can close in a single day, or possibly deriving which misinterpretation will be the most anger-inducing*. I'm not saying this for your benefit obviously, I'm sure you'd have already released it and started a public discussion forum/mailing list if it were up to you.

aBagorn
Aug 26, 2004

FamDav posted:

whereas in swift, they effectively generate this logic for you when you do

code:
butts?.doAThing();
which is p nice imo

C# is supposed to be getting this syntax in its next version. In the meanwhile I'm liking what I'm tinkering with in Swift so far

Doctor w-rw-rw-
Jun 24, 2008
Swift code:
// Playground - noun: a place where people can play

import Cocoa


func foo(inout x:Array<String>) -> Array<String> {
    x[0] = "qwer"
    return x
}

foo(["asdf", "1234"])
This crashes my Xcode. Known problem? Anyone else able to reproduce?

Adbot
ADBOT LOVES YOU

Glimm
Jul 27, 2005

Time is only gonna pass you by

Doctor w-rw-rw- posted:

Anyone else able to reproduce?

Yep, crashed mine right away

  • Locked thread