Reputation: 2649
I'm having trouble with a simple app setting up a data controller. I get an error on the line @property (strong, nonatomic) BirdsListDataController *dataController;
in BirdsListViewController.h. I've tried my best to use a @class declaration of BirdsListDataController, as well as trying to remove any #import statements from the .h files and tried to remove a circular #import which you can find commented out in the top of BirdsListViewController.h. I'm guessing it's something simple.
BirdsListViewController.h
#import <UIKit/UIKit.h>
@class BirdsListDataController;
@interface BirdsListViewController : UITableViewController <UITextFieldDelegate>
{
// NSMutableArray *listOfBirds;
IBOutlet UITextField *addNewBirdTextField;
}
//@property (nonatomic, retain) NSIndexPath *checkedIndexPath;
@property (nonatomic, retain) NSString *textLabelContents;
@property (nonatomic, retain) NSMutableArray *workingArray;
@property (strong, nonatomic) BirdsListDataController *dataController;
@property (strong, nonatomic) IBOutlet UITableView *birdListTableView;
@end
BirdsListViewController.m
#import "BirdsListViewController.h"
#import "BirdsListDataController.h"
@interface BirdsListViewController ()
@end
@implementation BirdsListViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
...
BirdsListDataController.h
#import <Foundation/Foundation.h>
@class BirdName;
@interface BirdsListDataController : NSObject
@property (nonatomic, copy) NSMutableArray *listOfBirds;
-(NSUInteger)countOfList;
-(BirdName *)objectInListAtIndex:(NSUInteger)theIndex;
-(void)addBirdNameWithName:(BirdName *)bName;
@end
BirdsListDataController.m
#import "BirdsListDataController.h"
//#import "BirdsListViewController.h"
#import "Bird.h"
@implementation BirdsListDataController
-(id)init
{...
I'm still really new to iOS and Objective C, so hopefully my code isn't too awful to troubleshoot. Thanks for the help.
Upvotes: 4
Views: 7289
Reputation: 2571
For people looking for a better answer than comment/uncomment your code, a better solution is to clean your project and to delete your derived data. Once you've fixed your circular references, the keystroke Command+Shift+K
will clean your project, or you can go to and select Product->Clean
.
To delete your derived data, open Organizer, click on the Projects tab, navigate to your project in the sidebar. You should see "Derived Data" under the project name header. To the right of that should be a button saying delete. If it is enabled, deleting the derived data can also remove hanging errors.
As way of explanation, it seems sometimes that Xcode becomes out of sync with a project, holding on to errors that no longer exists. This is better in more recent version, but still happens occasionally.
Upvotes: 3
Reputation: 706
In my case I had duplicate class names in different folders structure, Once I removed the new class and named it differently everything worked again.
So to translate this into a practical solution, as per "shA.t"'s comment:
if you comment/uncomment your code, or clean project as above answers suggested but still doesnt solve it:
take a step to look back at recent classes changes and double check all class names are unique even if in different directories, double check
them all
For this particular duplicate class name scenario, this will save you the hassle of importing and commenting your #import "class.h"
Upvotes: 0
Reputation: 10129
I'm not certain what is causing your problem, but a few things:
In the code that you've presented there is no reason not to import BirdListDataController.h in BirdListViewController.h, since there is no reference to BirdListViewControllers in BirdListDataController.h. So try replacing your @class declaration with an #import statement.
In BirdListDataController.h you declare @class BirdName, but in BirdListDataController.m you import Bird.h instead of BirdName.h. It seems like something could be wrong there, although I would have to see the code for BirdName.h and Bird.h to know for sure.
Upvotes: 1