10 ms·
Swift 1.2 and Xcode 6.3 beta
- sbilstein 12y agoComing to Swift as a Scala developer I really enjoy using the language. While it lacks the functional completeness of other functional languages I like writing it, it's specific set of features is very handy and easy to pick up. I think Apple did a great job building a pragmatic language that gives people good constructs and lets them get their jobs done rather quickly. I'm looking forward to Swift on Xcode stabilize and mature.
- melling 12y agoThis is practical. It's something you wish for within a couple hours of Swift. let x : SomeThing if condition { x = foo() } else { x = bar() } use(x)
- bigdubs 12y agoshort of having a language mechanism for doing an 'uninitialized' let, conditional operators could work: let x : Something = condition ? foo() : bar() but yeah, it would be nice to defer initialization of an immutable.
- jafingi 12y agoLet's hope you don't have a baz.
- LinaLauneBaer 12y agooften times you want to do more stuff in either case so ? does not always work. The if-else approach is more general.
- matt_kantor 12y agoYou could also do this: let x: Something = { if condition { someSideEffect() return foo() } else { anotherSideEffect() return bar() } }() But it's kind of ugly.
- masklinn 12y agoSad that Swift doesn't use an expressive if, then you could just write: let x: Something = if condition { // do stuff foo() } else { // do other stuff bar() }
- 0942v8653 12y agoThat's something I really miss in other languages—the ternary operator is just not good enough for when you have a condition like this. In lisp it's 3 lines which is just the right amount when in other languages you have 6 lines (and until now unnecessary mutability) or only one.
- mikeash 12y agoNote that it's no longer "would," this is a feature included in this beta. OP's code is now legal.
- netcraft 12y agoI wish the es6 const would allow this.
- spott 12y agoso, in c++ you can do initialization of const value via lambda closures that are immediately evaluated: const int a = [=](){ //do stuff here that returns an int: if (condition) { return foo(); } else { return bar(); } }(); Does this idiom work in swift?
- deleted 12y ago[deleted]
- lyinsteve 12y agolet x: String = { if 3 == 4 { return "Hello" } else { return "Goodbye" } }() Although in this case, I'd just use ternary. let x = (3 == 4) ? "Hello" : "Goodbye"
- deleted 12y ago[deleted]
- frewsxcv 12y agoWhy is being logged-in required to view the Release Notes?
- eddieroger 12y agoBecause Apple chooses to only give access to betas and their release notes to registered developers.
- frewsxcv 12y agoHow does that benefit Apple?
- jonknee 12y agoThey probably aren't interested in catering their beta kit to people who aren't Apple Developers... A good way to cut out a ton of noise in one step.
- deleted 12y ago[deleted]
- ChrisLTD 12y agoFor Yosemite they did an open beta: https://appleseed.apple.com/sp/betaprogram https://appleseed.apple.com/sp/betaprogram But in that case, it makes sense to get bug reports from non-developers.
- LeoNatan25 12y agoStill, as I remember, the release notes were still only presented to developers.
- eddieroger 12y agoYou'd have to ask Apple. I have no idea. But if I were to venture a guess, I'd say it has something to do with minimizing the press jumping all over speculative statements for features that are weeks (if not months) away from release still. But that's just one thought. I really have no idea.
- DaNmarner 12y agoThis might be easily overlooked: optional has been introduced (back-ported?) to Objective-C in the form of nullability annotation!
- jPaolantonio 12y agoI think this is a much-needed feature for integrating Swift into existing large Objective-C apps. Dealing with all the AnyObject optionals coming from Cocoa frameworks makes working with Swift painful.
- oleganza 12y agoNot exactly. ObjC code cannot usefully benefit from those annotations (yet? more likely ever). At most, it's good for documenting your ObjC code for fellow readers. The actual use appears in the Swiftland where instead of implicitly unwrapped optionals you get proper explicit optionals or explicit non-optionals.
- ejdyksen 12y agoThe benefit to working with the Cocoa APIs will be immense, though. I assume that, now that this feature exists, Apple will begin annotating their Obj-C APIs.
- oleganza 12y agoThey already started doing it a few months ago with private annotations. This "nonnull"/"nullable" syntax is a result of their work on annotating Cocoa APIs.
- eridius 12y agoThey've been doing it for a while in the Swift overlay module. I'm really happy that this is officially added to obj-c because it provides very valuable API documentation, even if it won't have much practical effect on the code.
- 12y ago
- NeoProgramming 12y agoHow about opening Swift compiler source code (and porting it to other platforms?) And, what are the OS requirements for xcode 6.3? Is it possible to install it to old macosx system (snow leopard, for example)?
- josh64 12y agoIt says this release (6.3) requires Yosemite (but includes SDKs for 10.9 and 10.10). For the record, 5.x doesn't even run on Snow Leopard.
- WildUtah 12y ago"5.x doesn't even run on Snow Leopard." Which is a shame because OSX 10.6.8 was the most stable, zippiest performance OSX ever and still had the nice virtual desktop. Sadly I lament the old virtual desktop. I'd still be on it if I could be.
- ChrisLTD 12y agoShouldn’t Apple finish designing the language before they even consider porting it elsewhere?
- 12y ago
- npalli 12y agoThis is so strange. Right now we have iOS 8.2 beta and 8.3 beta XCode 6.2 beta and 6.3 beta How is the release cycle going to work? When will 8.2 and 8.3 come out and which is more stable for Swift work.
- mikeash 12y agoXcode 6.2 basically only exists for the Apple Watch. I think iOS 8.2 is similar, but I'm less familiar there. Xcode 6.2 has no significant Swift changes that I'm aware of, so if you're just looking at Swift, you should either use the latest public 6.1 release, or the 6.3 beta to get the newer stuff. The release timing will presumably be that .2 comes out with the watch whenever that ends up being, and .3 will be a bit later.
- npalli 12y agoThanks.
- deleted 12y ago[deleted]
- ruddct 12y agoAwesome, the ability to unwrap multiple optionals on one line should be bolded, underlined and all caps at the top of this article. Seriously though, this is an everyday pain point that happens all the time when writing Swift. Glad Apple is listening to developer feedback on this stuff. Translation for those unfamiliar with Swift: Swift has a relatively strong type system. If a variable in Swift can be null at any point, it must be explicitly declared so as part of its type (e.g. an integer that can be null has the type "Int?", an integer that cannot be null has the type "Int"). Swift has a way to 'unwrap' these optional values and do things with them if they exist. Prior to this release, unwrapping multiple optional things required a bunch of nested if statements. With this release, unwrapping multiple optional values can be done in one if statement.
- smithclay 12y agoThe nested if-let statements of doom have been one of my major annoyances -- so glad to hear unwrapping multiple optionals in a single line landed in 1.2. The "wrapping the optionals in a tuple and using switch to pattern match" hack always seemed dirty, and this is a huge step in the right direction for code readability.
- archagon 12y agoIf let (and optionals in general) is my favorite Swift feature and has immediately made my code 10x more stable from the get-go. Glad to see it get expanded like this.
- masklinn 12y agoI'd like to see them expand it the way Rust did: Rust lifted `if let` from Swift (I believe) but made it a more general-purpose refutable pattern matcher, it's just one step below match and works with any enum type not just Option. So you can write: enum Foo { Bar, Baz(i32), Qux(f64) } if let Bar = item { // do something } else if let Baz(val) = other { // do something with val } which is oft shorter than a full-blown `match`, and more convenient when alternating on different "source" items.
- Osmium 12y agoReally happy to see this, was worried we'd have to wait for WWDC for further improvements. For me personally, it's nice to see Swift support for GLKMatrix and GLKVector now, which was an issue I just ran into just a few weeks ago.
- bla2 12y ago> Source files that haven’t changed will no longer be re-compiled by default That's a nice example of "if you're not embarrassed of 1.0, you shipped too late".
- pawelwentpawel 12y agoIf this is actually going to work well - great news for bigger swift projects. The compile time caused by this issue was making the development process really slow. We had to split the whole application into mini sub projects to make it bearable.
- lerno 12y agoThis is the release that makes you go "people were insane to think that Swift 1.1 was anything near usable".
- beltex 12y ago"The number of crashes in the swift-compiler-crashes project shrank -83 % with today's release of Xcode 6.3b. Thank you Swift engineers! :-)" https://twitter.com/practicalswift/status/564921024782041088 https://twitter.com/practicalswift/status/564921024782041088 https://github.com/practicalswift/swift-compiler-crashes/commit/f6da30450923afbc313fbcac16a5367c3f88aec3 https://github.com/practicalswift/swift-compiler-crashes/com...
- chakrit 12y agoThe type inferrence fix ("Type inference for single-expression closures has been improved in several ways:") is the most annoying one for me. Glad they've fixed it. Sure, compiling faster and having less crashes is nice. But that means nothing if it isn't compiling _correctly_.
- k-mcgrady 12y agoGlad enums now work correctly with Objective-c.