As a C# developer, I can read and understand the code without any issues. That's a good thing for Apple. I'm sure Objective-C is great but it's too foreign for me and didn't want to toy with it for fun, not worth the effort. But I can write an app or two with this one.
I just started exploring the Book: The Swift Programming Language by Apple Inc.<p>Link:
<a href="https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11" rel="nofollow">https://itunes.apple.com/us/book/the-swift-programming-langu...</a><p>Hope it helps.
Author here - I didn't expect to see this here this morning. I'd intended to write a longer post :)<p>In any case, here's a few things I learned about swift yesterday building this. Please note that I have about 4 hours swift experience, so feel free to correct anything I say that's wrong.<p>1. To make properties on a class you simply declare the variable on the class e.g.:<p><pre><code> class GameScene: SKScene {
var bird = SKSpriteNode()
// ...
}
</code></pre>
2. The APIs generally have shorter names and it's really nice. E.g.<p><pre><code> SKTexture* birdTexture1 = [SKTexture textureWithImageNamed:@"Bird1"];
</code></pre>
becomes<p><pre><code> var birdTexture1 = SKTexture(imageNamed: "Bird1")
</code></pre>
If I understand it correctly, any overloading `inits` basically look like calling the constructor on the class, whereas any class functions will be called like this:<p><pre><code> var flap = SKAction.repeatActionForever(animation)
</code></pre>
3. You can put inline blocks and it's great<p><pre><code> var spawn = SKAction.runBlock({() in self.spawnPipes()})
</code></pre>
4. The typing is really strong - this takes some getting used to. For instance, `arc4random()` returns a 32 bit unsigned integer. This means before you can use any operators on it you have to make sure you're using compatible types. e.g.<p><pre><code> var quarter = UInt32( self.frame.size.height / 4 )
var y = arc4random() % quarter + quarter;
</code></pre>
If we didn't use `UInt32` to convert `quarter` we'd get an error. After you get the hang of this, it's actually really nice.<p>5. I use `var` everywhere and I'm pretty sure I should be using `let` a lot more. I haven't worked with Swift enough to have a strong intuition about when to use either.<p>I should also mention that my code is just converted from Matthias Gall's code [1].<p>I also want to put in a shameless plug that the point of making this was to advertise the "Making Games with Swift" class that auser and I are building. If you're interested, put in your email here: <a href="https://fullstackedu.com" rel="nofollow">https://fullstackedu.com</a><p>I intend to redo this more fully with Playgrounds. I've been looking for a way to teach kids programming for a while now (if you recall, auser and I built Choc [2] a few months back). I think Playgrounds in Swift are finally the tool we've been waiting for.<p>[1] <a href="http://digitalbreed.com/2014/how-to-build-a-game-like-flappy-bird-with-xcode-and-sprite-kit" rel="nofollow">http://digitalbreed.com/2014/how-to-build-a-game-like-flappy...</a><p>[2] <a href="http://www.fullstack.io/choc/" rel="nofollow">http://www.fullstack.io/choc/</a><p>EDIT: added choc
Good work. I'll have to do 2048 instead, I guess :)<p>I'm quite impressed so far. Having been an Objective C and Ruby engineer, so far Swift seems to offer the best of both.<p>That said, OpenGL support doesn't appear to be finished yet.
If you're new to functional programming styles this swift project might be more relevant: <a href="https://github.com/maxpow4h/swiftz" rel="nofollow">https://github.com/maxpow4h/swiftz</a>
I got mixed feelings about the language at first sight. I guess my mammalian brain recognizes languages based on the particular combination of the following naming decisions.<p>* func, function, fun, defun fu, funct<p>* CamelCase vs snake_case<p>* whitespace, semicolon or comma usage<p>* var, int/integer/uint64/Integer/<p>* choice of (), {}, [] or better (){a[]}<p>* import/include/require, class/class, override, self vs this, new vs Class()<p>PS: next time you design a new language just make a random unique combination of the above.
Always had a problem with Objective C, could never read it (Android Dev) but this right here is pretty impressive. I like the mixture of language features. But my only question, are you still locked to using an mac to develop for iOS. I guess since the language is closed source it depends on some osx libs at compile time.
This being the only code sample of swift I've seen, my overriding takeaway is that for the basic stuff it's remarkably similar to Objective-C with a lick of paint.<p>If people really take to swift, it'll be interesting to see if that's because it creates a shift in programming style, or because people really are just afraid of small syntactical differences.
I am really intrigued by the obj-c interop capability of swift, namely interactions between blocks and closures / anonymous functions.<p>I can see my AFNetworking code becoming much, much more readable now, without the need to @weakify/@strongify self on both sides of the block, but just add a blanket
'[unowned self] in' inside the closure.
This may be a stupid question but is the language in some way tailored to game programming? Apple's examples at WWDC were game companies, their coding demo was a game, and this is the first project I've seen written in it - and it's a game.
pretty neat! I am not an iOS developer but if i understand correctly this uses the new Sprite Kit stuff included in iOS8 for 2d rendering right ? Is this a threat to existing 2d/game engines ? Not sure where SpriteKit integrates into the existing stack for making a game.
Swift looks fine, the only thing I don't like its that is for Apple only products... that kinda defeats the purpose of having a programming language.
Share the latest about Swift here! Be part of the biggest page for the language. Looking for admins. <a href="https://www.facebook.com/swiftofficial" rel="nofollow">https://www.facebook.com/swiftofficial</a>