Trying to write a custom description method for my NSManagedObject subclass and it instead of print that data in self.myvarname it prints out “Myvarname” or printing self.userCount it prints “UserCount”?
Followed this example: http://brandontreb.com/objective-c-tutorial-helpful-debugging-by-overriding-the-description-method/
Also, why in the xcode console when I type “po myroominstance.name” or “po myroominstance.usage” does it say no property found (given the class below)?
Here is my class:
.h
===================
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface Rooms : NSManagedObject
{
NSString *name;
NSNumber *capacity;
NSString *descr;
NSString *usage;
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * capacity;
@property (nonatomic, retain) NSString * descr;
@property (nonatomic, retain) NSString * usage;
@end
.M
==================
#import "Rooms.h"
@implementation Rooms
@dynamic name;
@dynamic capacity;
@dynamic descr;
@dynamic usage;
-(NSString *) description
{
return [NSString stringWithFormat:@"ID: %@ Name: %@ Website: %n",
usage ,descr,name];
}
@end
UPDATE 1:=========================================================
====== My break point is on this line ==========
Room *myRoom = [Room findFirst];
NSLog(@"The room name is %@", myRoom.name);
================================================
If I break at the NSlog line above, which by the way prints out “The room name is Name” and then type, in the console, “po myRoom.name” I get “Name”. If I type “po myRoom.descr” I get “Descr”.
Neither of the others get the formatting quite correct, but they’re barking up the wrong tree, anyway. You seem to have copied the
-descriptionmethod from the tutorial you linked to and not adjusted it to match your class.You could implement it like so:
(There’s no need to invoke
-intValueoncapacityand then use the “%d” formatting specifier.)However, that doesn’t explain why you’re not getting the results you expect during a debugging session or when asking for the description of one of your instances. Please edit your question and add the specifics of how you’re asking for the description and what exactly you’re getting. For example, are you logging your instances in code? If so, show the logging statements and the output. Are you using
poin the debugger? If so, show the actual command and the output.