Reputation: 363
I am following an online tutorial on how to build apps with Xcode. The video shows how to make a button and connect it to code to print out a statement. I have copied the code from the video 100% but it is not working. I have a more updated version so is there something I need to do differently. I am using Xcode 6.4 and the video was using 6.0. This is my code:
- (IBAction) showFunFact() {
println("You pressed me!")
}
// Error: Expected method Body
// Error: Semantic issue, Implicit declaration of function 'println' is invalid in C99
// Parse Issue: Expected ';' after expression
These are the three errors I am receiving but I think the other 2 are due to the fact that the program dose not recognise the println command. Anyone know how to fix this!?
Upvotes: 0
Views: 498
Reputation: 5258
The reason this isn't working is because the function should be declared like so:
@IBAction func showFunFact() {
println("You pressed me!")
}
The function you have posted above looks like an Objective-C function, so make sure either that a) your file is not an Objective-C file, or b) if you were trying to use Objective-C, then println()
won't work because it's not a method defined in Objective-C. In that case, the appropriate method would be NSLog(@"You pressed me!");
Upvotes: 6
Reputation: 465
xcode will compile many different type of languages - from swift to C++ to objective C and so on.
I am going through a similar phase and can tell you that many of the tutorials I find online are now irrelevant because antiquated. I would recommend Stanford's CS 193P lectures which are refreshed every year and use the latest language / compiler so you can always follow along. (Lectures & docs aval for free in itunesU)
Upvotes: 0
Reputation: 31153
You are using println
in Objective-C code. It is a Swift function, so you have to create a Swift file for that.
In Objective-C you could use NSLog(@"boo!");
Upvotes: 2