简体   繁体   English

从用户*分配给NSArray *的指针类型不兼容

[英]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.

相关问题 从'nsarray'分配给'nsmutablearray'的不兼容指针类型 - incompatible pointer types assigning to 'nsmutablearray ' from 'nsarray ' 不兼容的指针类型从NSArray分配给NSMutableString - Incompatible pointer types assigning to NSMutableString from NSArray 从nsdictionary分配给nsarray的不兼容指针类型 - incompatible pointer types assigning to nsarray from nsdictionary 警告:从“ NSArray”分配给“ NSMutableArray *”的指针类型不兼容 <NSString *> * _Nullable&#39; - Warning: Incompatible pointer types assigning to 'NSMutableArray *' from 'NSArray<NSString *> * _Nullable' 分配给&#39;NSString&#39;到&#39;NSString&#39;的不兼容指针类型 - Incompatible pointer types assigning to 'NSArray' to 'NSString' 不兼容的指针类型从NSString分配给“ UITextField” - Incompatible pointer types assigning to “UITextField” from NSString 从“ NSData *”分配给“ NSMutableData *”的指针类型不兼容 - Incompatible pointer types assigning to 'NSMutableData *' from 'NSData *' 不兼容的指针类型从“ UITableViewCell”分配给“ TableViewCell” - Incompatible pointer types assigning to 'TableViewCell' from 'UITableViewCell' 不兼容的指针类型从“ UIPopoverController *”分配给“ UIDatePicker *” - Incompatible pointer types assigning to 'UIDatePicker *' from 'UIPopoverController *' 从“ CCTMXLayer *”分配给“ CCTMXTiledMap *”的指针类型不兼容 - Incompatible pointer types assigning to 'CCTMXTiledMap*' from 'CCTMXLayer*'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM