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
Plorkyeran
Mar 22, 2007

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

Suspicious Dish posted:

Do you imagine this being used in production, or is it a research language?

The WWDC presentation certainly suggested to me that it's intended to replace Objective C entirely in a relatively prompt timeframe.

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
https://itunes.apple.com/gb/book/swift-programming-language/id881256329 is the book mentioned in the announcement.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
How do generics handle min(5, 5.1)? Mandatory casting to make the type inferrable?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I ported a few smallish classes from Obj-C to Swift to get a feel for it, and so far I'm a fan. The interop is pretty painless (the biggest issue I've encountered is that NSXMLDocument(contentsOfURL: self.baseURL, options: NSXMLNodeOptionsNone, error: &error) doesn't compile (because the constant's CUnsignedInt and it's expecting Int?)), and even just a dumb mechanical translation is a surprising improvement. Way less boilerplate everywhere even while keeping obj-c style naming thanks to type inference and no more initWith, no loving headers, and a lot of little annoyances like having to declare every single property as nonatomic are gone.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
On the Xcode side of things it'd be nice if the warning about it inferring AnyObject suggested adding a cast rather than explicitly annotating as AnyObject, especially for for-int loops since it wasn't totally obvious I could just cast NSArray to Foo[] in the loop header.

Plorkyeran
Mar 22, 2007

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

tef posted:

- You have string interpolation, but no string formatting (yet?)

String(format: "stuff %02X", 5) works fine. The documentation of the standard library current only mentions things different from obj-c (and not even all of that).

Plorkyeran
Mar 22, 2007

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

tef posted:

- Do you normalize unicode identifiers?

Nope!

Plorkyeran
Mar 22, 2007

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

rjmccall posted:

I think we discussed it and decided that not normalizing was the right thing to do. IIRC, the problem is that locale-insensitive normalization is often not good enough, but making the compiler locale-sensitive would be a terrible idea.
Normalization doesn't have anything to with locales. Case-insensitive identifiers would require locale-sensitivity unless you're willing to pretend Turkey doesn't exist, but converting everything to NFC or NFD inherently doesn't involve any change in semantic meaning.

Plorkyeran
Mar 22, 2007

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

rjmccall posted:

That doesn't actually scale to two closures on the same object. Ultimately, this is just asking for cycle detection.
Some sort of syntax to explicitly capture weak references might be nice, but it's also one awful step towards C++'s capture lists...

libextobjc's @weakify/@strongify is the least-bad solution I've seen in obj-c, and it's pretty bad.

Plorkyeran
Mar 22, 2007

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

rjmccall posted:

My Unicode is not very strong. I understand that there are normalizations you can do which would unify some strings, and we should probably at least be doing those. The question is whether (case-sensitive) string equivalence is actually locale-insensitive, because that's what I would expect name lookup to use in a maximally Unicode-aware world.
Yes, case-sensitive comparisons are locale-independent. Normalizing everything to NFC or NFD is basically the equivalent of converting everything to UTF-8 rather having strings in a bunch of different encodings. Pretty much everything else is locale-sensitive: case-sensitive comparisons are locale-sensitive because I and i are different letters in Turkish, accent-dropping is locale-sensitive because sometimes accents are just a pronunciation guide with no semantic meaning (as in coöperate), and sometimes they make letters into entirely different letters, and sorting is just different all over the place.

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.

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.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
set.allObjects as Foo[]

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I don't get why you're trying to call readabilityHandler with a closure. Do you mean
code:
fileHandle.readabilityHandler = { fh in ... }
?

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I'm guessing it's from ML where let x = 5 in ...stuff with x... is how variables are declared.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Advanced Swift video is up.

Was this the first time that Dave Abrahams' involvement was revealed? There was a lot of speculation about what project Apple had to offer that was interesting enough for him to shut down BoostPro, and I suppose that the chance to work on making generic programming possible in a language while avoiding the problems C++ ran into could certainly qualify.

Plorkyeran
Mar 22, 2007

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

Meat Street posted:

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.
Turning off runtime safety checks just to make fast enough code faster is obviously dumb, but sometimes it'll make the difference between being able to use Swift with the checks only enabled in dev builds and having to write the code in something far less safe like C. A certain level of performance is sometimes a hard requirement.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I'm not sure if the Xcode UI actually exposes it, but optimizer flags are in general per-file.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I can't stand actually editing anything in AppCode, but I still use it fairly regularly just for the refactoring tools. I'd prefer something integrated into Xcode, but the tools are totally worth the minor hassle.

Plorkyeran
Mar 22, 2007

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

Dessert Rose posted:

Am I supposed to be able to modify enum values if I pattern-match them?
Enums are value types, so you're passing a copy each time you call update. You have to box the enum if you want to pass a reference.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Common themes in #swift-lang:

How do I get the length of a string?

Why isn't Swift perfect? Four years is far longer than Apple should need to create a programming language.

Why does Swift make it so hard to just use AnyObject everywhere?

Swift is just like Objective C + X, where X is a language that has very little in common with Swift.

I want to learn Swift but I don't own any Apple products.

Plorkyeran
Mar 22, 2007

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

ultramiraculous posted:

Woah what. Why is it not thread safe in both cases? It seems like either situation is a place where you'd do a dispatch_once if you were doing it yourself.

dispatch_once_t has to be static (dispatch_once does clever things to avoid the need for synchronization that aren't guaranteed to work if the memory address was ever non-zero), so dispatch_once doesn't really work for member variables.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
How would reading from stdin work with the whole continuous evaluation thing? If it just reads one time then it's pointless, and if it reads every time the expression is evaluated it'd be unusable.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
code:
switch x {
    case .None: println("nil")
    case .Some("fred"): println("fred")
    case .Some(let x): println("other: " + x)
}

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
NSNumber uses tagged pointers now, so NSNumber(int:2) doesn't create an NSNumber object and referential equality on NSNumbers isn't a meaningful operation.

Plorkyeran
Mar 22, 2007

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

Axiem posted:

If I must have one AppDelegate, is there a way that I can pass in a value from the build configuration to that AppDelegate, so that I can at least choose which View Controller to load?
The simplest thing to do is just set an environment variable in the debug settings for your tests and check it with getenv.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
It's parsed as let result = (response.toInt() && result > 0), not (let result = response.toInt()) && result > 0

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
You can pass the explicit types as a regular parameter:

code:
func fetchObjects<T: IntegerLiteralConvertible>(_: T.Type) -> [T] {
    return [1,2,3]
}

println(fetchObjects(Int))
println(fetchObjects(Float))

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
What would Closure even be? An empty protocol? To be able to call it you'd need to know the function's signature, and there's only one type for each signature.

Plorkyeran
Mar 22, 2007

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

Axiem posted:

I have noticed that there is also a DebugPrintable protocol, though I haven't entirely figured out where it decides which protocol to use. And it doesn't appear to me as though say, XCTAssert* functions use either of them, either.
Just from the name my guess would be that it's used for po in lldb.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Beta 4's out with some awesome changes. I'm very happy about internal being the default access modifier and private being private to the implementation file rather than class. I'm also very happy to see String trying to actually do the right thing by default with unicode and CGFloat being less awful.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
I'm not sure if .HasValue even makes all that much sense. I can't think of any situations where you'd want to check if an optional has a value but not do anything with that value if it exists that aren't insane or dumb. I don't find the optional bool scenario all that confusing, but I definitely don't think that if x { ... x! ... } is something that the language should be encouraging when it has a much better construct for that.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
if x? { ... } would be a cute way to do explicit optional -> boolean conversions.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
It would have been nice to know a few months ago that iTunes was going to be rejecting Swift libraries targeting iOS 7.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
The error message when submitting is just "Invalid Info.plist value. The value for the key 'MinimumOSVersion' in bundle {framework name} is invalid. The minimum value is 8.0" and it happens only if the framework contains any Swift code. Maybe just a miscommunication somewhere about what was supported? Sideloading the ipa to an iOS 7 device works fine.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Using CocoaPods from Swift isn't any more of an issue than any other Obj-C code. The main problematic bit is that all of the Swift files have to be in the final application target (both because CocoaPods can't create framework targets yet and because iOS 7 doesn't support Swift frameworks). The best solution I've come up with for that is to add the Swift source files to preserve_paths in the podspec and tell people to manually add the files to their application target after installing the pod (and prefixing names and not using internal access since your code isn't being built into its own framework).

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
My general rule of thumb is that if it would be reasonable, sensible and possible to chain another method call after the method taking a closure, it shouldn't use the trailing closure syntax even if there happens not to be another call after it; otherwise it probably should. This is slightly more broad than statementy things.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Just write correct code the first time.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Requiring 10.10 makes me sad :(

Adbot
ADBOT LOVES YOU

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed
Shortly after Swift was first announced I had a very dumb argument with a person who was convinced that the Swift compiler would be both faster and more reliable if they'd written just enough of it in C++ to bootstrap and then wrote the real thing in Swift.

  • Locked thread