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

  • SEARCH
  • Home
  • 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 7523863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:55:31+00:00 2026-05-30T02:55:31+00:00

In iOS there are two C structs that denote paths that describe drawable shapes:

  • 0

In iOS there are two C structs that denote paths that describe drawable shapes: CGPathRef and CGMutablePathRef. From their names it would seem that CGPathRef refers to a path that once created cannot be changed, while CGMutablePathRef refers to a modifiable path. However, as it turns out, a CGPathRef can be passed to a function that expects a CGMutablePathRef and it appears to me the only difference is that the former generates a warning if the function it is passed to modifies the path, while the latter doesn’t. For example, the following program:

#import <UIKit/UIKit.h>

@interface TestView : UIView {
    CGPathRef immutablePath;
    CGMutablePathRef mutablePath;
}
@end
@implementation TestView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        mutablePath = CGPathCreateMutable();
        immutablePath = CGPathCreateCopy(mutablePath); // actually you might just do "immutablePath = CGPathCreateMutable();" here - The compiler doesn't even complain

        self.backgroundColor = [UIColor whiteColor];
    }

    return self;
}


- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesBegan executed!");
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextAddPath(context, immutablePath);
    CGPathAddRect(immutablePath, NULL, CGRectMake(100.0, 100.0, 200.0, 200.0)); // generates a warning specified later
    CGContextFillPath(context);
}


@end


@interface TestViewController : UIViewController
@end

@implementation TestViewController

@end

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    // Instantiate view controller:
    TestViewController *vc = [[TestViewController alloc] init];
    vc.view = [[TestView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    return YES;
}
@end


int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, @"AppDelegate");
    }
}

This is the warning given by the compiler:
Passing ‘CGPathRef’ (aka ‘const struct CGPath *’) to parameter of type ‘CGMutablePathRef’ (aka ‘struct CGPath *’) discards qualifiers

Maybe I’m missing the point here, but is there any other difference between these two except to remind the programmer that maybe he didn’t intend the path being referenced (by CGPathRef) to be modified?

  • 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-30T02:55:32+00:00Added an answer on May 30, 2026 at 2:55 am

    It is possible in C to pass the wrong type to a function, but it is almost always not a good idea. Even if technically they might appear to be defined the same thing, there is probably a good reason Apple has them as separate things. Most likely it is to make more code readable and understandable, or Apple plans on making changes later.

    After all that, a jump to definition reveals the real differences:

    typedef struct CGPath *CGMutablePathRef;
    typedef const struct CGPath *CGPathRef;
    

    CGPathRef is a const typedef (google it if you’re not quite sure what this does). However C allows you to break const definitions which is why you are still able to pass your CGPathRef to a function expecting a CGMutablePathRef and modify it fine. It also explains why it throws a discards qualifiers warning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there an IOS API that wraps the google 'distance between two locations' API?
Starting with iOS 5, there are two notification styles: banner and alert (the old
I've got these two structs that I need to store in files. I can't
I've got these two structs that I need to store in files. I can't
In iOS 5 SDK, there're two methods of UIViewController, presentModalViewController:animated: and presentViewController:animated:completion:. What's the
I cloned from https://github.com/facebook/facebook-ios-sdk.git today, and noticed two spots in the code which have
In iOS is there anyway to prevent a UIView containing multiple buttons (siblings) from
I have a code with two targets that uses functions specific to iOS 4
How do I create a png image from text in iOS?
I'm diving into iOS development and am building a game that has multiple game

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.