Nicholas Muir
Nicholas Muir

Reputation: 3104

Objective C place NSString in NSLog

Really basic Obj C question:

before you say this is a duplicate I have already checked other answers and that is what I am using to do this with are saying to do it this way.

So I just want to output a NSString to NSLog but I am getting the error expected ")" on the log line.

I am obviously missing somthing really basic.

Here is the code:

//
//  HelloWoldOBJ.m
//  Helloworld2


#import "HelloWoldOBJ.h"

@implementation HelloWoldOBJ

    NSString *make = @"porche";

    NSLog(@"%@", make);

@end

Thanks for your help

Upvotes: 0

Views: 913

Answers (2)

Sanchit Kumar Singh
Sanchit Kumar Singh

Reputation: 513

NSLog(@"%@", make);

The above line must be written inside a method, and that method must be called from somewhere. In short NSLog is not a property, so it can't be just declared like a property. That's why you are getting this error.

Upvotes: 1

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

call your string in viewDidLoad and check

 - (void)viewDidLoad

 {
[super viewDidLoad];

NSString *make = @"porche";

NSLog(@"%@", make);


 }

you get the out put like

enter image description here

Upvotes: 1

Related Questions