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 8035835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:25:43+00:00 2026-06-05T02:25:43+00:00

There are methods in Cocoa classes that accept an address of a pointer. Most

  • 0

There are methods in Cocoa classes that accept an address of a pointer. Most commonly the argument is address of future NSError * object in CoreData validation methods (among others). This way it is possible to put custom or owned object into the place of the address that given argument points to.

My question is: why can’t we do that with simple pointer arguments? E.g. let’s say I have a method:

- (void)addObject:(id)someObject toArray:(NSMutableArray *)array;

I can easily pass the mutable array as second argument, call addObject: on it and after the method call the array will be modified. Why is this not done with NSError * objects? Are pointers passed to methods are defined as const by default? Is this to avoid accessing NULL?

  • 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-06-05T02:25:44+00:00Added an answer on June 5, 2026 at 2:25 am

    Why is this not done with NSError * objects?

    Because there’s no such thing as an NSMutableError. Your example works because you can modify the contents of the array without modifying the pointer to the array itself. However, since NSError instances are immutable, you cannot modify an NSError. As such, you must necessarily create a new error object. And if you want to return that error object along with some other piece of data, at least one of those must be done via an out-parameter (such as an NSError **).

    Are pointers passed to methods are defined as const by default?

    Nope. Inside that method you’re welcome to do this:

    - (void)addObject:(id)someObject toArray:(NSMutableArray *)array {
      someObject = somethingElse;
      [array addObject:someObject];
    }
    

    What’s important to remember here is that you’re only changing a pointer in a slot in memory. The memory slot corresponding to someObject is just a space on the stack, and you’re changing the contents of that space to have a value that points to a different allocated object than the one you were given.

    Is this to avoid accessing NULL?

    Any NULL protection you need must be done yourself.

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

Sidebar

Related Questions

There are many Cocoa methods that require an NSError object as a parameter to
Is there a way to configure XCode to autocomplete Cocoa methods with the most
Are there methods to obfuscate during/after compile that are automated?
In Java there are methods to go about scanning the classpath/all classes/within a package
In some sample codes there are methods and classes declared WITHIN other methods and/or
Specifically in JAX-RS (I'm not sure that is relevant) there are methods that allow
There are 2 methods for external css assignments.I am using the first method; most
In a cocoa app of mine, there is a method that does some operations
Looking at https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSAttributedString_AppKitAdditions/Reference/Reference.html , there are quite a few document formats that AppKit makes
Are there methods for encoding and decoding XML in .NET? I can't seem to

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.