★★一段objective-c的代码,错在哪里?

iOS 码拜 9年前 (2015-05-08) 666次浏览 0个评论
 

下面的代码,编译的时候报错,也就是红色代码部分
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

5分
e …printf函数要包含c的iostd库吧
5分
printf換成NSLog
5分
没有错误。
检查拼写和中英文标点是否有误。
5分
命名尽量统一吧。。?
5分
#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
5分
_userName如果不是alloc的就不要release了吧。。。
5分
@property(copy)NSString* userName;
5分
关注一下。。。。。。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明★★一段objective-c的代码,错在哪里?
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!