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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:07:35+00:00 2026-05-19T02:07:35+00:00

I have a category on NSDate, and I want to implement some functions to

  • 0

I have a category on NSDate, and I want to implement some functions to manipulate the date, like :

NSDate *thedate = [NSDate date];
[thedate setToMidnight];

so I have a function in NSDate like :

-(void)setToMidnight {
   some code with calendars and comps

   self = theNewDate;
}

This works inside the function, but outside this member function, thedate has not changed.
I understand this malfunction because I’ve been told that self is just a local variable created inside the member function.
So, how can I make this work ?

Of course, I could have written :

thedate = [thedate dateAsMidnightDate]
or thedate = [NSDate dateAtMidnightFromDate:thedate]

but I feel it has more sense inside the instance class, as I don’t want to change the date but just adjust some values of the previously created one.

  • 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-19T02:07:36+00:00Added an answer on May 19, 2026 at 2:07 am

    You can’t. Specifically:

    1. A function or method cannot modify local variables in the calling context.

    2. NSDate is not mutable (i.e. you can’t modify an NSDate once it’s created).

    Therefore, no such method can be written. The closest you can get would be a class that wraps an NSDate and forwards messages to that internal NSDate object, which reassigns the date instance variable when you want to make it represent a new date.

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

Sidebar

Related Questions

I have category model, in which I want to load some default data. How
I have built a category for NSDate and I would like to encapsulate an
I have created an NSDate category that would give me a last sunday date.
I have a custom category (disciplines) in my method plugin which I want to
I have some products that belongs to the some category. Each category can have
I have Category and a Product models. I want for each product to belong
I have a Core Data model with an NSDate property. I want to filter
I have a category table like this: I can list categories as list and
I have a Category object like this: def parent_default(context): ''' default parent id if
I'm creating a category over NSDate. It has some utility methods, that shouldn't be

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.