[英]Incompatible pointer types assigning to NSArray * from User *
I'm beginner in iOS programming and I need some help with returning array from function. 我是iOS编程的初学者,我需要一些有关从函数返回数组的帮助。 I have this structure of my application(I don't if it's correct):
我的应用程序结构如下(如果正确,则没有此结构):
https://www.dropbox.com/s/md4b2nrdf09wdny/Screenshot%202014-02-28%2018.11.30.png https://www.dropbox.com/s/md4b2nrdf09wdny/Screenshot%202014-02-28%2018.11.30.png
User.h/.m are files generated from CoreData model and have 4 property. User.h / .m是从CoreData模型生成的文件,具有4个属性。
LoginVC.h/.m is using for log in to application (authorization). LoginVC.h / .m用于登录到应用程序(授权)。
UserController is using for work with user structure - save user, update user, get all users etc. UserController用于处理用户结构-保存用户,更新用户,获取所有用户等。
What I need...I have function in UserController.m the function looks like this: 我需要...我在UserController.m中有函数,该函数如下所示:
-(NSArray *)getUsers{
CoreDataHelper *cdh = [(AppDelegate *)[[UIApplication sharedApplication]delegate] cdh];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"User"];
NSArray *Users = [cdh.context executeFetchRequest:request error:nil];
return Users;
}
The function is for getting all users from table User and return Array of users. 该函数用于从表User中获取所有用户并返回用户数组。
I would like to call this function in LoginVC.m, so I push this code to function viewDidLoad: 我想在LoginVC.m中调用此函数,因此我将此代码推送到函数viewDidLoad:
UserController *userController = [[UserController alloc]init];
[userController getUsers];
NSArray *users = [[NSArray alloc]init];
users = [userController getUsers];
But when I start application there is a error or warning - Incomaptible pointer types assigning to NSArray* from User* and I don't know why is the realy problem, because function getAllUsers return Array and I assign to Array. 但是,当我启动应用程序时,会出现错误或警告-从User *分配给NSArray *的指针类型不兼容,我不知道为什么是真正的问题,因为函数getAllUsers返回Array且我分配给Array。 Thank you for help.
谢谢你的帮助。
Coloration is giving you a tips. 着色为您提供提示。
Rename your variable Users
to users
on line : 将您的变量
Users
重命名为以下users
:
NSArray *Users = [cdh.context executeFetchRequest:request error:nil];
我在您发布的代码中没有看到任何User *
,但是我认为对编译器警告的唯一逻辑解释是,在UserController.h
中将getUsers
声明为- (User *)getUsers
而不是- (NSArray *)getUsers
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.