I would like to use a NSArray like property in whole class (self.array), but I don't know how. Now I have this code in my LoginVC:
LoginVC.h:
#import <UIKit/UIKit.h>
@interface LoginVC : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *usernameTextField;
@property (strong, nonatomic) IBOutlet UITextField *passwordTextField;
@property (strong, nonatomic) IBOutlet UIScrollView *loginButton;
@property (nonatomic, strong) NSArray *allUsers;
@end
LoginVC.m:
- (void)viewDidLoad
{
if (debug == 1) {
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
}
[super viewDidLoad];
// Do any additional setup after loading the view.
UserController *userController = [[UserController alloc]init];
[userController getUsers];
self.allUsers = [NSArray new];
self.allUsers = [userController getUsers];
}
The method getUser
return a NSArray, but this solution doesnt work. The llbd report an error: *Thread 1: EXC_BAD_ACCESS (code=2, address=0x38)*
I think the problem is with initialization the array and assignment.
Declaration of getUsers:
-(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 method "getUsers" works correctly.
Here is a screen of the error. Its strenge, because self.allUsers contents one object with userName "admin" and its absolutely correct.
https://www.dropbox.com/s/ui5rtq9ov0p2xx9/Screenshot%202014-03-02%2019.24.53.png
I think the problem is in array, because when I delete the code with assignment to array. The error disappears.