简体   繁体   中英

Incompatible pointer types assigning to NSArray * from User *

I'm beginner in iOS programming and I need some help with returning array from function. 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

User.h/.m are files generated from CoreData model and have 4 property.

LoginVC.h/.m is using for log in to application (authorization).

UserController is using for work with user structure - save user, update user, get all users etc.

What I need...I have function in UserController.m the function looks like this:

-(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.

I would like to call this function in LoginVC.m, so I push this code to function 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. Thank you for help.

Coloration is giving you a tips.

Rename your variable Users to users on line :

NSArray *Users = [cdh.context executeFetchRequest:request error:nil];

我在您发布的代码中没有看到任何User * ,但是我认为对编译器警告的唯一逻辑解释是,在UserController.h中将getUsers声明为- (User *)getUsers而不是- (NSArray *)getUsers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM