Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6255613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:23:52+00:00 2026-05-24T14:23:52+00:00

As a beginner in objective C and xcode, I am trying to do a

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:23:53+00:00Added an answer on May 24, 2026 at 2:23 pm

    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:

    Screenshot of linker flags

    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 CPTGraphHostingView not CPLayerHostingView. Here is my working version:

    #import "CorePlotTestViewController.h"
    
    @implementation CorePlotTestViewController
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
    
        // Release any cached data, images, etc that aren't in use.
    }
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        graph = [[CPTXYGraph alloc] initWithFrame: self.view.bounds];
    
        CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
        hostingView.hostedGraph = graph;
        graph.paddingLeft = 20.0;
        graph.paddingTop = 20.0;
        graph.paddingRight = 20.0;
        graph.paddingBottom = 20.0;
    
        CPTXYPlotSpace *plotSpace = (CPTXYPlotSpace *)graph.defaultPlotSpace;
        plotSpace.xRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-6)
                                                       length:CPTDecimalFromFloat(12)];
        plotSpace.yRange = [CPTPlotRange plotRangeWithLocation:CPTDecimalFromFloat(-5) 
                                                       length:CPTDecimalFromFloat(30)];
    
        CPTMutableLineStyle *lineStyle = [CPTMutableLineStyle lineStyle];
        lineStyle.lineColor = [CPTColor blackColor];
        lineStyle.lineWidth = 2.0f;
    
        CPTXYAxisSet *axisSet = (CPTXYAxisSet *)graph.axisSet;
    
        axisSet.xAxis.majorIntervalLength = CPTDecimalFromString(@"5");
        axisSet.xAxis.minorTicksPerInterval = 4;
        axisSet.xAxis.majorTickLineStyle = lineStyle;
        axisSet.xAxis.minorTickLineStyle = lineStyle;
        axisSet.xAxis.axisLineStyle = lineStyle;
        axisSet.xAxis.minorTickLength = 5.0f;
        axisSet.xAxis.majorTickLength = 7.0f;
        axisSet.xAxis.labelOffset = 3.0f;
    
        axisSet.yAxis.majorIntervalLength = CPTDecimalFromString(@"5");
        axisSet.yAxis.minorTicksPerInterval = 4;
        axisSet.yAxis.majorTickLineStyle = lineStyle;
        axisSet.yAxis.minorTickLineStyle = lineStyle;
        axisSet.yAxis.axisLineStyle = lineStyle;
        axisSet.yAxis.minorTickLength = 5.0f;
        axisSet.yAxis.majorTickLength = 7.0f;
        axisSet.yAxis.labelOffset = 3.0f;
    
        CPTScatterPlot *xSquaredPlot = [[[CPTScatterPlot alloc] initWithFrame:graph.bounds] autorelease];
        xSquaredPlot.identifier = @"X Squared Plot";
        CPTMutableLineStyle *plotLineStyle = [[xSquaredPlot.dataLineStyle mutableCopy] autorelease];
        plotLineStyle.lineWidth = 1.0f;
        plotLineStyle.lineColor = [CPTColor redColor];
        xSquaredPlot.dataLineStyle = plotLineStyle;
        xSquaredPlot.dataSource = self;
        [graph addPlot:xSquaredPlot];
    
        CPTPlotSymbol *greenCirclePlotSymbol = [CPTPlotSymbol ellipsePlotSymbol];
        greenCirclePlotSymbol.fill = [CPTFill fillWithColor:[CPTColor greenColor]];
        greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0);
        xSquaredPlot.plotSymbol = greenCirclePlotSymbol;  
    
        CPTScatterPlot *xInversePlot = [[[CPTScatterPlot alloc]
                                        initWithFrame:graph.bounds] autorelease];
        xInversePlot.identifier = @"X Inverse Plot";
        plotLineStyle = [[xInversePlot.dataLineStyle mutableCopy] autorelease];
        plotLineStyle.lineWidth = 1.0f;
        plotLineStyle.lineColor = [CPTColor blueColor];
        xInversePlot.dataLineStyle = plotLineStyle;
        xInversePlot.dataSource = self;
        [graph addPlot:xInversePlot];
    }
    
    -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
        return 51;
    }
    
    -(NSNumber *)numberForPlot:(CPTPlot *)plot 
                         field:(NSUInteger)fieldEnum 
                   recordIndex:(NSUInteger)index 
    {
        double val = (index/5.0)-5;
    
        if (fieldEnum == CPTScatterPlotFieldX) { 
            return [NSNumber numberWithDouble:val]; 
        }
        else { 
            if (plot.identifier == @"X Squared Plot") { 
                return [NSNumber numberWithDouble:val*val]; 
            }
            else { 
                return [NSNumber numberWithDouble:1/val]; 
            }
        }
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a beginner with Objective C and iPhone development. It's there any way to
I'm a beginner in Objective-C and I'm trying to find the most convenient way
I'll preface my question by saying that I'm a beginner objective-c developer. What is
iam beginner in Objective-C, i tried to compile small Hello world program to start,iam
I am a beginner of Objective C and XCode. I use Mac os X
I'm a beginner with Xcode and Objective-C, i want to make a view controller
I'm a beginner at Objective-C and am trying to initialize an NSMutableArray with objects
Is there any objective reason not to remove unused default includes from C# program?
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Absolute beginner question: I have a template file index.html that looks like this: ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.