I have a custom view onto which I draw some graphics from the drawrect function, which works fine.
However I like to draw based on the contens of an array I pass on the the view just before I do a setNeedsDisplay. In the drawRect function If I uses a NSString or NSarray from withing drawRect I get a nested functions error which I do not understand ?
Here’s my code:
// MyView.h
#import <UIKit/UIKit.h>
@interface MyView : UIView {
}
@end
// MyView.m
#import "MyView.h"
@implementation MyView
CGContextRef c;
CGFloat black[4] = {0.0f, 0.0f, 0.0f, 1.0f};
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
// Initialization code
}
return self;
}
- (void)drawRect:(CGRect)rect {
c = UIGraphicsGetCurrentContext();
CGContextSetStrokeColor(c, black);
//Gives a nested functions are disabled error at compiletime
NSString nsz * = @"test";
}
- (void)dealloc {
[super dealloc];
}
@end
the bottom line is that the “nested function” error is just a “general” error you get when you have a really bad syntax error.
Such as forgetting to close a bracket. Or a stray operator.
(Edit — in fact in this case it was a stray ‘ * ‘ operator.)
It actually has nothing to do with “nested functions” (usually), and, the problem could be almost anywhere in the file or even the previous file.
Sorry I could not spot the typo!