0

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!?

0

3 Answers 3

6

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!");

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for clarifying this, I had accidentally selected to use Objective-C instead of swift. It works now!
2

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!");

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.