我有一個用戶類,我通過iPhone應用程序使用,這是從我的用戶類(SUBBLASS OF NSobject)的init和initWithUser函數,當我使用initWithUser函數時,我得到警告在代碼後面描述。請指教。不兼容Objective-c類型警告
// serialize.h
#import <Foundation/Foundation.h>
@protocol Serialize
// serialize the object to an xml string
-(NSString*)ToXML;
@end
// user.h
#import <Foundation/Foundation.h>
#import "Serialize.h"
#import "Contact.h"
@interface User : NSObject <Serialize> {
NSString *email;
NSString *firstName;
NSString *lastName;
NSString *userId;
NSString *userName;
NSString *password;
NSMutableArray *contactList;
}
@property (nonatomic,copy) NSString *email;
@property (nonatomic,copy) NSString *firstName;
@property (nonatomic,copy) NSString *lastName;
@property (nonatomic,copy) NSString *userId;
@property (nonatomic,copy) NSString *userName;
@property (nonatomic,copy) NSString *password;
@property (nonatomic, retain) NSMutableArray *contactList;
//-(id)init;
-(id)initWithUser:(User *)copyUser;
@end
// user.m
#import "user.h"
@implementation User
@synthesize email;
@synthesize firstName;
@synthesize lastName;
@synthesize userId;
@synthesize userName;
@synthesize password;
@synthesize contactList;
-(id)init
{
// call init in parent and assign to self
if((self = [super init]))
{
// do something specific
contactList = [[NSMutableArray alloc] init];
}
return self;
}
-(id)initWithUser:(User *)copyUser
{
if((self = [self init])) {
email = copyUser.email;
firstName = copyUser.firstName;
lastName = copyUser.lastName;
userId = copyUser.userId;
userName = copyUser.userName;
password = copyUser.password;
// release contactList initialized in the init
[contactList release];
contactList = [copyUser.contactList mutableCopy];
}
return self;
}
- (void)dealloc
{
// TODO:
[contactList removeAllObjects];
[contactList release];
[super dealloc];
}
// implementation of serialize protocol
-(NSString*)ToXML
{
return @"";
}
我用它在主控制器這樣
- (void) registerNewUser {
RegistrationViewController *regController = [[RegistrationViewController alloc] init] ;
regController.newUser = [[User alloc] initWithUser:self.user];
[self.navigationController pushViewController:regController animated:YES];
[regController release];
}
行
regController.newUser = [[User alloc] initWithUser:self.user];
給我下面的錯誤,它是推動我堅果幾天的:
不兼容Objective-c類型的結構User *',e xpected「結構的NSString *」路過時的參數1「initWithUser:」從不同的Objective-C型
任何幫助和指導表示讚賞
嗯。你可以發佈'User.h'文件嗎? – Yuji 2010-09-19 03:24:19
'Serialize'是什麼樣的?你有什麼奇怪的「NSObject」類別?任何可能涉及的'#define'? – 2010-09-19 03:37:36
我說上面的序列化的代碼,沒有的#define或類似的東西 – curiousMo 2010-09-19 03:56:40