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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:35:50+00:00 2026-06-06T11:35:50+00:00

I want to be able to do the following: NSString *hoursAndMinutes = [myNSDateObject formattedTime];

  • 0

I want to be able to do the following:

NSString *hoursAndMinutes = [myNSDateObject formattedTime]; // eg. 10:25

Now I can create a category on the NSDate class but since the creation of NSDateFormatter has proven to be quite costly I would like to use a single instance of my NSDateFormatter. Is this a contradiction to the notion of categories or is there a neater way to achieve this?

  • 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-06T11:35:53+00:00Added an answer on June 6, 2026 at 11:35 am

    Categories will only let you maintain static variables. But for your instance that would work perfectly.

    Make a category for your formatter as so

    Header

    @interface NSDateFormatter (myFormats)
    
    + (NSDateFormatter*) specialFormatting;
    
    @end
    

    Implementation file

    @implementation NSDateFormatter (myFormats)
    
    + (NSDateFormatter*) specialFormatting{
        static NSDateFormatter *_specialFormatting;
        static dispatch_once_t onceToken;
        dispatch_once(&onceToken, ^{
            _specialFormatting = [[NSDateFormatter alloc] init];
            // Continue Setting up this format;
        });
        return _specialFormatting;
    }
    
    @end
    

    Then be sure to include your header where you want to use this (i use the prefix.pch file to include things I use all the time)

    then you will not need to declare it and can use it from where it is. And the item will not be created each time you need it..

    The object is never released. but that is what you desire anyhow. since it is still accessible it is not a memory leak.

    You can also provide helper methods that will allow you to just get back the string.

    Hope that helps.

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

Sidebar

Related Questions

Let's suppose I have following two variables: arg1=5 count5=test Now, I want to able
I want to be able to do the following actions with a form submit
I want to be able to achieve the following using guice/gin: Get all sort
I want to be able to parse the following times using ParseExact() function: 01:02:03
I want to be able to do the following: get '/:slug' do haml :page
I want to be able to initialize a CArticle having the following properties: Private
I have the following migration and I want to be able to check if
I want be able to find tags of items under the a certain category.
I have the following declaration in my class called GameManager: -(void)playBackgroundTrack:(NSString*)trackFileName isAmbient:(BOOL*)ambient { }
I want to be able to do the following: Import a flatfile row by

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.