Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Timerez

macrumors newbie
Original poster
Jun 4, 2014
19
0
Hello,

I'm new to this site and new to Objective-C/Swift both. I recently started using Swift yesterday via Xcode 6 beta. I know it's beta and I'm attempting to learn how to code in swift but xcode 6 keep crashing. I barely started and I only want to practice to "get it" as I code along.

For example, I'd type in:

Code:
var first: Integer = 5
println(first)

var second: Double = 4.4
println(second)

let sum1 = Double(first) + second
println(sum1)

And boom, it crashes. And I see people are having no problem developing something (Googled and saw someone posting "recreated flappy bird with swift") so I assume it's just me. How do I find the cause of this particular problem and fix it?

Also, my macbook pro is on OSX 10.9.3 and laptop itself is bit old, made in 2008. Is it the laptop or is it something else?

Thanks!
 
Last edited:
No idea why your crashing... but i would recommend downloading the eBook:
https://itunes.apple.com/us/book/id881256329?mt=11

Swift uses 'type inference'... 98% of the time you don't have to do:
PHP:
var first: Integer = 5

Just do:

PHP:
var first = 5

The compiler will figure out its in Int.

Also, make sure you know the difference between 'var' and 'let'.

var = variable (can change)
let = constant (can not change)

var = mutable
let = immutable

example:
PHP:
var numbers = [5,9,12]
let othernumbers = [3,7,11]

numbers.append(2) // this is ok!
othernumbers.append(13) // this will give an error

Read Apple's eBook... Follow the examples and do the 'experiment' sections.
 
No idea why your crashing... but i would recommend downloading the eBook:
https://itunes.apple.com/us/book/id881256329?mt=11

Swift uses 'type inference'... 98% of the time you don't have to do:
PHP:
var first: Integer = 5

var = variable (can change)
let = constant (can not change)

var = mutable
let = immutable

Read Apple's eBook... Follow the examples and do the 'experiment' sections.

1) I already read up to roughly first 100 pages of that ebook as you suggested. I mostly "get it" through reading.
2) I already know how to code but in Java, picking this up along with Obj-C language right now for my internship.
3) I already took note of the difference between let/var.
4) I also already took note of "type interference" - and that is what I am attempting to experiment with.

I basically am asking on how could I counter xcode 6 beta's frequent crashing. :(
 
I basically am asking on how could I counter xcode 6 beta's frequent crashing. :(

I've noticed a rash of crashes while working on their experiments. I think we'll just have to wait for the next beta release of Xcode 6 and see if that fixes the problem. But if you have an example that always causes a crash, submit a bug report to Apple. This is a big reason they release betas.

P.S. I get the following error from your "let sum1 = ..." line:
Code:
Playground execution failed: error: <REPL>:9:26: error: could not find an overload for '+' that accepts the supplied arguments
 
I've noticed a rash of crashes while working on their experiments. I think we'll just have to wait for the next beta release of Xcode 6 and see if that fixes the problem. But if you have an example that always causes a crash, submit a bug report to Apple. This is a big reason they release betas.

P.S. I get the following error from your "let sum1 = ..." line:
Code:
Playground execution failed: error: <REPL>:9:26: error: could not find an overload for '+' that accepts the supplied arguments

Yeah, that's usually the problem but I thought I could make it work. In fact, I copied sample from ebook, it works. However, it won't work if I put 2 variables created together...

1+1 = works
var + 1 = works
var + var = not working (even if I include datatype such as Double(var) + var)...
Edit: also, tried with Double(var) + Double(var) just for the hell of it, and doesn't work. lol

It's just bit odd. And I also crashes as soon as I try and make array too. But you might be right. I might have to wait for next patch for this beta. :(
 
Last edited:
I wrote a simple little app last night in swift/xcode6 with no crashing (current-gen mac book pro w/10.9.3) ... I did find a bunch of autocomplete errors that kept making me pull my hair out.. but no crash.
 
I wrote a simple little app last night in swift/xcode6 with no crashing (current-gen mac book pro w/10.9.3) ... I did find a bunch of autocomplete errors that kept making me pull my hair out.. but no crash.

Do you also have xcode 5 installed? (Dumb question but I want to be sure I don't assume)
 
Yeah, that's usually the problem but I thought I could make it work. In fact, I copied sample from ebook, it works. However, it won't work if I put 2 variables created together...

1+1 = works
var + 1 = works
var + var = not working (even if I include datatype such as Double(var) + var)...
Edit: also, tried with Double(var) + Double(var) just for the hell of it, and doesn't work. lol

I did some more fiddling around and found that the reason for the error is that you've declared first as an Integer. If you declare it as an Int, Playground reports no error. Seems you can't convert an Integer to a Double. I would avoid using Integer unless you have a very specific reason to. Apple wants you to use Int (and type inference even more). See the "Int" section in The Basics chapter for more info.
 
I did some more fiddling around and found that the reason for the error is that you've declared first as an Integer. If you declare it as an Int, Playground reports no error. Seems you can't convert an Integer to a Double. I would avoid using Integer unless you have a very specific reason to. Apple wants you to use Int (and type inference even more). See the "Int" section in The Basics chapter for more info.

Oh wow, I assumed that I was expected to type "Integer" instead of "Int" when declaring datatype. Trying my code again with your advice on avoiding Integer worked for me, and didn't crash the program. And I thought it was the program itself and not the way I wrote code... Thanks for your help. :) I suppose I have to be extra careful with declaring datatype.

Edit: I forgot to ask a question: did your program crash when you used Integer in place of Int?
 
Last edited:
or do as apple intend you to do and do not declare the type!!

If you had read my posts, you'd see that I'm only experimenting. I learn the best through experimenting and I was not sure if it was the program itself or way I wrote. I want to know as much as possible to impress my boss...

Thanks for your advice.
 
It hasn't... yet. I did get frequent crashes while trying to do the "full deck of cards" experiment.

I haven't gotten to that far in either Swift (obviously) or Obj-C, yet. I think I saw that demo in one of my Obj-C related books but haven't read into it. Anyway, thank you for your help on finding the cause of my frequent crashes. I think I'm going to close this post, if I can.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.