Qcom
Qcom

Reputation: 19163

Expected specifier-qualifier-list before 'string'

With the latest version of Xcode from Apple, I have the following problem.

Upon launching, and starting a new project, no matter what the project, I get an error.

Let's say I would like to build a "Mac OS X Command Line Tool" of type "Foundation".

Then, to add a new class, I go to File > Add File > Cocoa Class > Objective-C Class (subclass of NSObject).

Next, in the .h file of the new class created, I replace with the following code:

//
//  newclass.h
//  Untitled
//

#import <Cocoa/Cocoa.h>


@interface newclass : NSObject
{
    string userName;
}

@property string userName;

@end

And then the implementation with the following code:

//
//  newclass.m
//  Untitled
//

#import "newclass.h"


@implementation newclass

@synthesize userName;

@end

And then click "Build & Run" the following errors occur:

newclass.h:11: error: expected specifier-qualifier-list before 'string'


newclass.h:14: error: expected specifier-qualifier-list before 'string'


newclass.m:11: error: no declaration of property 'userName' found in the interface

What am i doing wrong? I've looked up similar previous questions and they have all had to do with the fact that there have been missing or incorrect inputs as far as I can tell.

I can't seem to find out how mine would relate considering everything is from a new project.

Upvotes: 0

Views: 2609

Answers (3)

Webber Lai
Webber Lai

Reputation: 2022

Try change your .h like this

@interface newclass : NSObject
{
    NSString *userName;
}

@property (nonatomic,retain) NSString *userName;

why your implementation looks like your .h ..... ?

Upvotes: 1

Pete Rossi
Pete Rossi

Reputation: 764

The string type hasn't been defined. I think you meant to use NSString *

Upvotes: 1

Carl Norum
Carl Norum

Reputation: 224844

I think you're looking for NSString *. string is a C++ class and Objective-C is not C++.

Upvotes: 2

Related Questions