开发者

Expected specifier-qualifier-list before 'string'

开发者 https://www.devze.com 2023-01-28 16:50 出处:网络
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.

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.


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


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


Try change your .h like this

@interface newclass : NSObject
{
    NSString *userName;
}

@property (nonatomic,retain) NSString *userName;

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号