I have been working on an app all day which has been working fine until Xcode downloaded libraries or something and then it started having issues. I am just trying to create the getter/setter methods to get a couple of arrays out of my APPDelegate. Like I said it was working fine and then randomly it showed up with this error and now won't build anymore:
property with 'retain(or strong)' attribute must be of object type
Here is the rest of the code:
#import <Foundation/Foundation.h>
#import "Project.h"
#import "TeamMember.h"
@interface Task : NSObject{
NSDate *endDate;
NSDate *startDate;
NSMutableString* notes;
NSMutableString* taskName;
//The error appears first right here over teamMember
TeamMember *teamMember;
Project *project;
}
//The error appears over both of the following lines as well...
@property (nonatomic, retain)TeamMember *teamMember;
@property (nonatomic, retain) Project * project;
@property (nonatomic, retain) NSMutableString *notes;
@property (nonatomic, retain) NSMutableString *taskName;
@property (nonatomic, retain) NSDate *startDate;
@property (nonatomic, retain) NSDate *endDate;
@end
Any ideas? This has got me stumped....
Here is Project.h:
#import <Foundation/Foundation.h>
#import "Task.h"
@interface Project : NSObject{
NSDate *dueDate;
NSDate *startDate;
NSArray *tasksInProject;
NSMutableString* notes;
NSMutableString* description;
NSMutableString* projectName;
}
@property (nonatomic, retain) NSDate *startDate;
@property (nonatomic, retain) NSDate *dueDate;
@property (nonatomic, retain) NSArray *tasksInProject;
@property (nonatomic, retain) NSMutableString *description;
@property (nonatomic, retain) NSMutableString *projectName;
@end
Here is TeamMember.h
#import <Foundation/Foundation.h>
#import "Task.h"
#import "Project.h"
@interface TeamMember : NSObject{
NSMutableArray *projects;
NSMutableString *name;
NSMutableString *title;
NSMutableString *email;
NSMutableString *phone;
NSMutableString *notes;
}
//@property(nonatomic, retain) NSArray *projects;
@property (nonatomic, retain) NSMutableString *name;
@property (nonatomic, retain) NSMutableString *title;
@property (nonatomic, retain) NSMutableString *email;
@property (nonatomic, retain) NSMutableString *phone;
@property (nonatomic, retain) NSMutableString *notes;
@end
It looks like it's caused by recursively including of header files.
Try to add @class Project and @class TeamMember into your Task.h, like this
#import <Foundation/Foundation.h>
#import "Project.h"
#import "TeamMember.h"
@class TeamMember;
@class Project;
@interface Task : NSObject{
NSDate *endDate;
NSDate *startDate;
...
}
@end
You are attempting to retain something that is not an NSObject subclass. Usually this happens when someone tries to retain a float or int.
NSInteger is a scalar and not an object. So you shouldn't retain it, it should be assigned. Changing your property will clear up the warning message. You don't need to do the NSNumber stuff that you added in.
@property (nonatomic, assign) NSInteger integValue;
The error is that you are attempting to retain something that is not an NSObject
subclass. Usually this happens when someone tries to retain
a float
or int
.
You've shown the .h for Project
but not for TeamMember
. Check the latter for this, and if you don't see it then update your code snippet.
It happened to me because i have recursively imported some .h files.
I removed those files and my project started working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With