ios class not found "Expected a type"
Asked Answered
K

1

2

I'm getting two problems in my FooterSelectorView.h and I have no idea why. One is a warning while the other is an error. For some reason xcode doesn't recognize FooterArchiveItemView so I'm not able to type my object as that which is causing other propblems. Has anyone ever seen anything like this before? How can I fix it?

FooterSelectorView.h

#import <UIKit/UIKit.h>
#import "FooterArchiveItemView.h"

@interface FooterSelectorView : UIImageView

// #warning Type of property 'activeItem' does not match type of accessor 'setActiveItem:'
@property (nonatomic, retain) FooterArchiveItemView *activeItem;

// #error Expected a type
- (void)setActiveItem:(FooterArchiveItemView *)activeItem_;
- (void)update;
- (CGPoint)absoluteCenterOf:(UIView *)obj;

@end

Related Classes

FooterArchiveItemView.h

#import <UIKit/UIKit.h>
#import "AutosizeableView.h"
#import "FooterArchiveView.h"

typedef void (^ DayBlock)(void);

@interface FooterArchiveItemView : AutosizeableView {
    DayBlock dayBlock;
}

@property (nonatomic, retain) IBOutlet UIButton *day;
@property (nonatomic, retain) IBOutlet UIImageView *bullet;

- (void)setDayBlock:(DayBlock)block;

@end

AutosizeableView.h

#import <UIKit/UIKit.h>

@interface AutosizeableView : UIView

@end
Kenway answered 7/3, 2012 at 19:3 Comment(0)
A
9

One thing I'd suggest is that you conform to the Obj-C practice, that, within header interface files, rather than importing custom classes, you forward-declare them. For example, in FooterSelectorView.h, rather than:

#import "FooterArchiveItemView.h"

Forward-declare the class:

@class FooterArchiveItemView

Then, in the implementation file (FooterSelectorView.m), you import. Observing the practice may not actually solve your issue in this case (I don't know exactly what's happening, personally I'd want to see a bit more code to hazard a guess), but it might help isolate the issue for you.

The noted exception to this rule is Apple's frameworks - those are imported into headers.

Aegeus answered 7/3, 2012 at 19:14 Comment(4)
I tried this with no success then I just went around adding this to a number of classes and still nothing. However, then I commented all the class declarations out and it worked. so odd.. -- Is this just a best practice or something?Kenway
Glad it got you somewhere, here's several good explanations: https://mcmap.net/q/63427/-class-vs-importAegeus
Forward declarations are much more safe than imports in the header files, unless you safely construct your header files in such a way that a circular reference causes no problems (header A imports class B and header B imports class A). I assume this is solved through the forward declarations, where the headers (which are imported in .m files) are not doing any importing themselves, meaning they can't get stuck in a loop.Hygroscope
Thank you, it was the solution of my problem. I had a identifier not found exception. By removing #import and adding @class the problem was solved.Hectorhecuba

© 2022 - 2024 — McMap. All rights reserved.