As a beginner in objective C and xcode, I am trying to do a tutorial program that can be found there: http://www.switchonthecode.com/tutorials/using-core-plot-in-an-iphone-application
I did some changes so it would finally compile, so here’s my .h (please forgive the silly name of my application):
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface yutyyutViewController : UIViewController <CPTPlotDataSource>
{
CPTXYGraph *graph;
}
@end
And here’s my .m (at least the important part):
#import "yutyyutViewController.h"
@implementation yutyyutViewController
- (void)viewDidLoad {
[super viewDidLoad];
CPTMutableLineStyle *dataLineStyle = [CPTMutableLineStyle lineStyle];
xSquaredtPlot.identifier = @"X Squared Plot";
dataLineStyle.lineWidth = 1.0f;
dataLineStyle.lineColor = [CPTColor redColor];
xSquaredtPlot.dataLineStyle = dataLineStyle;
xSquaredtPlot.dataSource = self;
[graph addPlot:xSquaredtPlot];
And I get the EXC_BAD_ACCESS at the first non-commentary line of the three last lines, right after the application started running.
Although I am a beginner, I spent a lot of time looking into this and could not find the solution on internet. It seems like I’m trying to access xSquaredtPlot which is an autorelease and that is why I get the error, but what I understood is that doing a retain in a property in my .h, and a synthesize in my .m. BUt that didn’t fix the problem.
So any help will be gladly appreciated and I’m sorry if I missed the answer although it’s already on the forums.
Regards, Crafti.
The problem is the outdated tutorial. It’s over two years old and a lot has changed in core-plot since then. The crucial step is you need to add an additional linker flag besides
-ObjC. You also need to add-all_load:I went through the tutorial and updated it to work with the current version of core-plot. Note that the view’s class needs to be set to
CPTGraphHostingViewnotCPLayerHostingView. Here is my working version: