So long story short, I have some odd bugs in some code I’m messing with and it turns out that it comes from an object being identified as the wrong class.
Here is my code, with the NSLog statement I put before anything touches the object… I can’t figure out why it’s showing as the wrong class.
Photo.h
@interface Photo : NSObject
{
}
@property (nonatomic, retain) UIImage *image;
@property (nonatomic, retain) IBOutlet NSString *descr;
@end
Photo.m
@implementation Photo
@synthesize image;
@synthesize descr;
@end
CameraViewController.h
#include "Photo.h"
@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate>
{
IBOutlet UIImageView *imageView;
}
@property (nonatomic, retain) Photo *photo;
-(void)takePhoto;
-(void)resetImage;
@end
and finally…
CameraViewController.m
#import "Photo.h"
....
@implementation CameraViewController
@synthesize photo;
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%@", NSStringFromClass([_photo class]));
// Do any additional setup after loading the view.
}
This prints out:
UIImageView
I would expect it to print out
Photo
or at the very least
NSObject
Am I missing something???
Sending an object the
classmessage retrieves that object’s dynamic type. The object must be assigned prior to querying it for itsclass. In other words, declaring a property asPhoto*is not sufficient for itsclassto returnPhoto: you must also assign it an instance ofPhotoor one of its subclasses. In the later case, the result of sendingclassmessage will be different (i.e. theClassof the subclass will be returned).