I have a workspace that has two projects in it. The first project was essentially a test and develop project where I got things working before worrying about tying everything together for real. The second project is bringing all my individually developed view controllers together in a storyboard.
On one of the view controllers I have a bunch of swipe gestures with quite a bit of UIView animation calls nicely formatted for readability and therefore taking a lot of space. I elected to move them out as a category.
The problem is that the compiler is not seeing the instance variable declarations in the main header file.
What has me pulling my hair out is that I did this in the first project and it all worked fine. So I’m carefully comparing the contents of my second project to the first and I see no differences.
Here’re some file snippets to help demonstrate how/where I’m defining things, and then snippets of code in the category file that is attempting to access them:
GSBViewController.h
@interface GSBViewController : UIViewController
@property (strong, nonatomic) IBOutlet UISegmentedControl *roundPicker;
@property (strong, nonatomic) IBOutlet UIView *roundsSectionView;
GSBViewController.m
#import "GSBViewController+Swipe.h"
@interface GSBGameBuilderViewController ()
{
UIBarButtonItem *rightGatherBarButton;
NSInteger previousRound;
}
@end
@implementation GSBViewController
@synthesize roundPicker;
@synthesize roundsSectionView;
GSBViewController+Swipe.h
#import "GSBViewController.h"
@interface GSBViewController (Swipe)
- (void)establishSwipeGestures;
@end
GSBViewController+Swipe.m
#import "GSBViewController+Swipe.h"
@implementation GSBViewController (Swipe)
- (void)establishSwipeGestures
{
UISwipeGestureRecognizer *swipeLeft =
[[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:@selector(roundsSectionLeft:)];
[swipeLeft setDirection:UISwipeGestureRecognizerDirectionLeft];
[swipeLeft setNumberOfTouchesRequired:1];
[roundsSectionView addGestureRecognizer:swipeLeft];
// bunch-o-code snipped -- for the time being it's actually all commented out
// as a test and because the LLVM compiler was giving up after too many errors
// and I wanted to see if there was more it would like to tell me about this first --
// and very representative -- problem.
}
@end
The complaint from the compiler is “Use of undeclared identifier ’roundsSectionView'”
If I option-click on the use of roundsSectionView in that line of code where I’m adding the gesture recognizer to it the pop-up correctly describes it as declared in GSBViewController.h
So I’m stumped.
Is there something I can do in Xcode (4.3.2 at the time of this posting 🙂 to let me see what the included files are? Or is there something non-file-based that is needed to tie a category into the class it’s augmenting? I don’t remember anything like that being necessary before. In fact, the way I generated the files for this category was through Xcode’s File -> New File… Objective-C Category template. Then I just copied the contents of the old …+Swipe.h and …+Swipe.m files and pasted them into their respective files in the new project.
What @Jacques Cousteau says is correct.
Since you just defined a property and no backing ivar, the category won’t be able to access it. If you use
self.roundsSectionViewit will use the getter method generated for the property and hence it will work.Or you could define a backing variable in your interface
In this case the categories will be able to access the variable. But not any other class.