下面的代码,编译的时候报错,也就是红色代码部分
MYHelloWorld.h:7:1:error:stray '@' in program
MYHelloWorld.m:5:1:error:stray '@' in program
#import <Foundation/Foundation.h>@interface MYHelloWorld : NSObject{
NSString* _userName;
}@property(nonatomic,retain)NSString* userName;- (id)initWithUserName:(NSString*)userName;
- (void)helloWorld;@end#import "MYHelloWorld.h"@implementation MYHelloWorld@synthesize userName = _userName;- (id)initWithUserName:(NSString *)userName{
self = [super init];
_userName = [userName copy];
return self;
}- (void)helloWorld{
NSString *text = [NSString stringWithFormat:@"%@,Hello World!",_userName];
printf([text UTF8String]);
}- (void)dealloc{
[_userName release];
[super dealloc];
}@end

解决方案 »

  1.   

    e ...printf函数要包含c的iostd库吧
      

  2.   

    #import "MYHelloWorld.h"@implementation MYHelloWorld@synthesize userName ;- (id)initWithUserName:(NSString *)userName{
        self = [super init];
        _userName = [userName copy];
        return self;
    }- (void)helloWorld{
        NSString *text = [NSString stringWithFormat:@"%@,Hello World!",_userName];
        printf([text UTF8String]);
    }- (void)dealloc{
        [_userName release];
        [super dealloc];
    }@end
      

  3.   

    _userName如果不是alloc的就不要release了吧
      

  4.   

    @property(copy)NSString* userName;