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
Gul Banana
Nov 28, 2003

hey, thanks for this! swift reads like a collection of best practices enfleshed, and it will make mac+ios dev way more pleasant. instead of being a step down from the JVM, the CLR, the web etc, now it feels mostly like a step up.

my favourite features: let, enum, and real first class functions, rather than faking them with delegate or SAM types. least favourite is the array stuff, and collections in general. there doesn't seem to be anything equivalent to scala.collection or System.Linq. perhaps those things don't work so well without GC and complex monad comprehension syntax? but they are Extremely useful.

Adbot
ADBOT LOVES YOU

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?

rjmccall posted:

Also I feel very slightly bad for randomly making fun of Ada. Only very slightly, though.

I'm sure Ada can handle it. It has features for everything else.

Toady
Jan 12, 2009

It would be cool to be able to specify how Objective-C code gets presented to Swift (rdar://17184411), like with JavaScriptCore's JSExportAs(), so I could omit class prefixes or move the first parameter name out of the function name in favor of a label.

The level of Objective-C integration is impressive. I'm looking forward to converting piecemeal.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
Found a fun crash. Paste this into a playground:

code:
@objc
protocol Notifiable
{
    let fireDate: NSDate
}
e: opened rdar://17194123

I know you're not supposed to use let now, but I didn't when I wrote this code and then the segfault actually happened in a completely different file a good fifteen minutes of work later. Beta tools are fun :D

Dessert Rose fucked around with this message at 08:45 on Jun 6, 2014

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?

Doh004
Apr 22, 2007

Mmmmm Donuts...
I think he was trying to be nice by not revealing what her heard because, as rjmccall had mentioned earlier, they try to keep their non released names quiet?

Axiem
Oct 19, 2005

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

Doh004 posted:

I think he was trying to be nice by not revealing what her heard because, as rjmccall had mentioned earlier, they try to keep their non released names quiet?

This. I would rather not incur the wrath of the Apple gods.

Instead, I will note that in the Stump the Experts, one of the questions for the audience was "What was the code name for iCloud?", and after the audience gave the correct answer, one of the experts said (paraphrased) "When they first started the MobileMe replacement, the chosen code name was 'Mavericks', but we all thought it was a stupid name, so we decided to name it after a beer instead--thus, Newcastle"

lord funk
Feb 16, 2004

code:
occupations["Jayne"] = "Public Relations"
Best part of The Swift Programming Language.

Hughlander
May 11, 2005

Any access to some of the lower level obj c runtime? Like associated objects ?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

Hughlander posted:

Any access to some of the lower level obj c runtime? Like associated objects ?

We have plans in this area.

Doctor w-rw-rw-
Jun 24, 2008

quote:


Summary:
Swift is described as "Objective-C without the C". Objective-C was C + Smalltalk, so subtracting C yields Smalltalk.

Trying to map Objective-C keyword syntax to function-call / dot syntax brings significant complexity to the language without commensurate benefits. The section of the language spec. describing external vs. internal parameter names is larger than the entire Smalltalk language spec.

"Modern Syntax" was tried before, and it was overwhelmingly rejected by the developer community. Developers are accustomed to Objective-C message syntax (which is Smalltalk syntax), and the APIs don't have to be mapped, so there is less effort.

Steps to Reproduce:
Try to use reasonable syntax in Swift.
Try to comprehend the language specification.


Expected Results:
Syntax is easy to use + understand.

Actual Results:
Struggle with "where does the first parameter name go", "how do these things map" etc.
http://openradar.appspot.com/17180612

Why yes that is definitely a constructive and useful suggestion for Swift :shepface:

Filburt Shellbach
Nov 6, 2007

Apni tackat say tujay aaj mitta juu gaa!
The Advanced talk was great. I'm glad the syntax mungling examples were tempered by words of caution.

Generics are fantastic. Can't believe the code you guys had on screen for the memoization example. There's a whole class of young programmers who are going to be introduced to FP through Swift.

Vanadium
Jan 8, 2005

Doctor w-rw-rw- posted:

Why yes that is definitely a constructive and useful suggestion for Swift :shepface:

Expected Results: I'm writing objc
Actual Results: I'm not writing objc? wtf is going on??

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Vanadium posted:

Expected Results: I'm writing objc
Actual Results: I'm not writing objc? wtf is going on??

Expected Results: this is a language I already know
Actual Results: I have to learn a new thing?? gently caress you Apple!!

toiletbrush
May 17, 2010

Filburt Shellbach posted:

The Advanced talk was great. I'm glad the syntax mungling examples were tempered by words of caution.

Generics are fantastic. Can't believe the code you guys had on screen for the memoization example. There's a whole class of young programmers who are going to be introduced to FP through Swift.
Yeah watched all the Swift talks and I was pretty blown away by how powerful the language is...I don't really like how 'if let' or in read but apart from that I'm really excited to start doing Swift stuff.

I've got a couple questions I haven't seen asked, sorry if they were already asked and I missed em...

Is Swift going to enable better refactoring support in Xcode? I really, really miss Resharper when doing ObjC dev

Also, I'm writing an iPhone app that makes a lot of use of raw C byte arrays for performance, is there a performant way to allocate and read/write a raw c-style array with Swift, or should I leave that bit in ObjC?

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
I just got the chance to really play (ha) with the Playground, building a feature in my app, and it is a dream.

The fact that it doesn't link with the rest of your project is a downside, but it's also an upside. I think if that does get added it needs to be optional. It doesn't take that much time to make mock pieces that your code actually needs to touch; we're not trying to write an entire app in here, just a small piece of code that you'll take into the main project when you're done.

Then you can visualize the progress through your algorithm with graphs. You might say, well, how is a graph of my variable actually useful? And maybe a graph isn't your first choice for representing the data, true. But we're not creating reports to show to other people, here. It is useful to be able to see the value of this variable every time we went through the for loop.

I wrote a reasonably complex (for me) algorithm this way, debugging it fluidly and quickly because I didn't have to plow through six layers of my app to test that it worked how I expected, getting instant visual feedback on the changes I was making and how they changed the behavior of my algorithm.

And when I was done, I just checked the .playground file into my repo, because next time I want to tweak that algorithm or try a different thing or write more unit tests, I already have the environment where all those mock objects are defined, all those graphs are nicely laid out.

This is really, really good.

Meat Street
Oct 17, 2004

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

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

toiletbrush posted:

Is Swift going to enable better refactoring support in Xcode? I really, really miss Resharper when doing ObjC dev

Swift should certainly make it easier to do good tooling like this. I shouldn't speculate about specific future work, though.

toiletbrush posted:

Also, I'm writing an iPhone app that makes a lot of use of raw C byte arrays for performance, is there a performant way to allocate and read/write a raw c-style array with Swift, or should I leave that bit in ObjC?

UnsafePointer has alloc and dealloc operations.

Malcolm XML
Aug 8, 2009

I always knew it would end like this.

Doh004 posted:

I think he was trying to be nice by not revealing what her heard because, as rjmccall had mentioned earlier, they try to keep their non released names quiet?

Yeah they got sued by Carl Sagan of all people regarding a code name.

Are y'all gonna let me program kexts with this?

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.

Toady
Jan 12, 2009

Doctor w-rw-rw- posted:

http://openradar.appspot.com/17180612

Why yes that is definitely a constructive and useful suggestion for Swift :shepface:

I recognize that guy from the Objective-C mailing list. Not that people shouldn't give their critical opinions, but he doesn't even like ARC and has been working on a perpetually delayed Objective-C performance tuning book that is arguably obsolete now for most readers.

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.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Plorkyeran posted:

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.

I assume you can turn them off per file, right? So you could write a tiny core that doesn't check anything and only expose it via an interface that does.

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.

Hughlander
May 11, 2005

toiletbrush posted:


Is Swift going to enable better refactoring support in Xcode? I really, really miss Resharper when doing ObjC dev


Get App Code it's by Jet Brains the same guys that make Resharper and it gives the full Inteli-J/Resharper refactoring experience to objective C and C++. I drank the kool-aid so hard there.

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.

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

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.

Plorkeyran said basically everything I would have, so I'll just note for the record that it's -Ofast.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
Are you supposed to have to annotate an NSManagedObject subclass with @objc?

I was under the impression that you didn't, but I couldn't get instance methods to work until I added it. The strange thing is that I can call class methods on another NSManagedObject subclass without it.

Which one is the bug? :)

Doctor w-rw-rw-
Jun 24, 2008
Did you annotate the properties as NSManaged?

Hughlander
May 11, 2005

Plorkyeran posted:

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.

It's increasingly off topic but make sure you are giving the VM 4 gigs through the options and 3.0 fixes the bug of files outside the project root which caused me heartache.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Doctor w-rw-rw- posted:

Did you annotate the properties as NSManaged?

Yes. Also it apparently only works if I actually specify the name of the class. @objc isn't sufficient.

I'm not sure it actually works, though, because when I try to assign to an instance variable inside the class, it crashes.

I'm about to give up on converting my model to Swift for now and just try my luck at the controller layer.

Doctor w-rw-rw-
Jun 24, 2008

Dessert Rose posted:

Yes. Also it apparently only works if I actually specify the name of the class. @objc isn't sufficient.

I'm not sure it actually works, though, because when I try to assign to an instance variable inside the class, it crashes.

I'm about to give up on converting my model to Swift for now and just try my luck at the controller layer.

You've posted no example code, so we can only spitball and hope we don't run into the same issue. If you could please share?

ManicJason
Oct 27, 2003

He doesn't really stop the puck, but he scares the hell out of the other team.
I am disappointed in the intermediate Swift talk. One of the speakers said that F1 cars do not have turbos in one of his examples. GET WITH THE TIMES! (All F1 cars are turbocharged starting this year.)

Other than that, that talk did an awesome job selling some of the power in Swift. I'm definitely going to jump into the advanced stuff this weekend. I was unreasonably excited to see that you can do pattern matching with ... and _ in the middle of case statements. It reminds me of the fun I had playing with Prolog in college.

Axiem
Oct 19, 2005

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

ManicJason posted:

I was unreasonably excited to see that you can do pattern matching with ... and _ in the middle of case statements. It reminds me of the fun I had playing with Prolog in college.

The insane power of the case statements in Swift is one of my favorite features of the language. It just gives you so much power compared to most languages.

Flobbster
Feb 17, 2005

"Cadet Kirk, after the way you cheated on the Kobayashi Maru test I oughta punch you in tha face!"
I've been racking by brain over some difficulty getting some complex mathematical expressions to compile involving CGRects and CGFloats, and I finally managed to distill it down to this problem:

code:
let x = Double(4) * Int(5)   // Could not find an overload for '*' that accepts the supplied arguments
...so I was surprised that see that mixed arithmetic doesn't seem to be supported if the types of the expressions (in my original case, they were variables) are explicit (as opposed to writing 4.0 * 5, which works). I couldn't find anything in the book or the docs about implicit type coercion/promotion, so is this a bug or a feature of a very strong type system?

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?

tef
May 30, 2004

-> some l-system crap ->

Axiem posted:

The insane power of the case statements in Swift is one of my favorite features of the language. It just gives you so much power compared to most languages.

I'm hearing the usual slew of things about swift, "It's proprietary" (yep, and it locks you in just as much as using objective-c does) but isn't really a language or platform for anything but apple dev.

However one thing I am hearing over and over is both the enums and case statements. I dunno about using swift but I certainly hope other languages pinch them.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice

Flobbster posted:

I've been racking by brain over some difficulty getting some complex mathematical expressions to compile involving CGRects and CGFloats, and I finally managed to distill it down to this problem:

code:
let x = Double(4) * Int(5)   // Could not find an overload for '*' that accepts the supplied arguments
...so I was surprised that see that mixed arithmetic doesn't seem to be supported if the types of the expressions (in my original case, they were variables) are explicit (as opposed to writing 4.0 * 5, which works). I couldn't find anything in the book or the docs about implicit type coercion/promotion, so is this a bug or a feature of a very strong type system?

The book calls out that Swift does not do any automatic conversion, you must explicitly do it. It's under "The Basics", "Integer and Floating-Point Conversion":

quote:

Conversions between integer and floating-point numeric types must be made explicit:

The rules for combining numeric constants and variables are different from the rules for numeric literals. The literal value 3 can be added directly to the literal value 0.14159, because number literals do not have an explicit type in and of themselves. Their type is inferred only at the point that they are evaluated by the compiler.

Simulated
Sep 28, 2001
Lowtax giveth, and Lowtax taketh away.
College Slice
Bug Dump!

rdar://17215811 - Improve Swift Closure Syntax

rdar://17215836 - Swift: Provide runtime introspection/reflection capabilities with language syntax

rdar://17215845 - Swift should use consistent keywords

rdar://17215852 - Swift should provide explicit syntax for user-defined attributes

rdar://17215880 - Swift should provide a macro-like language extension system

rdar://17215884 - Swift: Any should be capable of containing a function/closure

rdar://17215895 - Swift should adopt a state of the art error handling mechanism
"If Swift is intended to some day write operating system code, drivers, etc then it would be nice to have a way to write robust code that doesn’t abort the kernel (or the current I/O thread) because someone forgot that an integer value can overflow if a driver receives a malformed packet."

rdar://17215909 - Swift: Array and Dictionary’s behavior is inscrutable

rdar://17215916 - Swift extensions should use associated objects to allow addition of stored properties to objects

rdar://17215920 - Swift: functions that define argument names should allow passing arguments in any order.

rdar://17215927 - Swift should provide an async/await-like abstraction over GCD



For those wanting to test this stuff in a VM: I thought I'd setup a 10.10 VM and install the Xcode beta in that. Don't do it. For whatever reason it is horribly ungodly slow; something is wrong with how VMWare Fusion is hosting 10.10. It is literally unusable - the pauses waiting for intellisense to popup are maddening. Use a 10.9 VM to test stuff out; it works much better.

Adbot
ADBOT LOVES YOU

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...
rdar://17216333 - I should be able to include 'nil' in a switch statement over a nullable enum.

I suppose I could just add "None" as an enum case as a temporary workaround. Maybe I should stop thinking in nullable-by-default patterns.

Doctor w-rw-rw- posted:

You've posted no example code, so we can only spitball and hope we don't run into the same issue. If you could please share?

I haven't made the effort to trim it down into a good example case, because it involves having a full Core Data stack. Here are the parts that are the problem, but I have a feeling this will not actually reproduce it:

Quest.swift:

code:
@objc(Quest)
class Quest : NSManagedObject, Notifiable
{
    @NSManaged var completed: Bool

[...]

    func complete()
    {
        if (completed) { return }
        
        completed = true; // EXC_BAD_ACCESS
        
        if (resetType != .Countdown)
        {
            giveReward()
        }
        
        if (resetType != .None)
        {
            next_reset = NSDate(timeIntervalSinceNow: 0) + NSTimeInterval(reset_time)
        }
    }
}
QuestsViewController.m:
code:
- (void)longPress:(UILongPressGestureRecognizer *)gesture
{
    if (gesture.state == UIGestureRecognizerStateBegan)
    {
        UITableViewCell *cell = (UITableViewCell *)[gesture view];
        NSIndexPath *path = [self.table_view indexPathForCell:cell];
        Quest *q = [self.fetchedResultsController objectAtIndexPath:path];
        if (!q.completed)
        {
            [q complete]; // crash!
        }
        else
        {
            [q fail];
        }
        [APP_DELEGATE updateQuestNotifications];
    }
}
Note that the ObjC equivalent Quest.m does exactly the same thing and works.

  • Locked thread