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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:07:11+00:00 2026-05-27T20:07:11+00:00

In a typical iOS application, where should one put application wide objects? I’d like

  • 0

In a typical iOS application, where should one put application wide objects? I’d like to centralized my Date formatting code and I would be interested in hearing suggestions on best practices for doing so.

For example, I have the following code to do date formatting:

NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString *usFormatString = [NSDateFormatter dateFormatFromTemplate:@"EEE, MMM d YYY" options:0 locale:usLocale];

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = usFormatString;

((UILabel *)[selectedCell.contentView viewWithTag:1]).text = [formatter stringFromDate:date];

I’d like to keep the formatting code as DRY as possible.

EDIT: This turned out to be a multipart answer and I took the approach of using a combination of a Singleton and creating a Category for NSString. I upvoted most of you, but I accepted @Jack_Lawrence.

  • 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-27T20:07:12+00:00Added an answer on May 27, 2026 at 8:07 pm

    I like using Objective-C categories for that sort of stuff. Categories are good for extending the abilities of existing objects, especially objects from frameworks that you don’t have control over. Make sure to prefix method names so you don’t conflict with current/future methods Apple may implement.

    In this specific case, I would create a category on NSDate called NSDate+DateFormatting and implement a method that returns an NSString from the date receiver:

    - (NSString *)JL_stringByFormattingDate
    {
        NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
        NSString *usFormatString = [NSDateFormatter dateFormatFromTemplate:@"EEE, MMM d YYY" options:0 locale:usLocale];
    
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = usFormatString;
    
        return [formatter stringFromDate:self.date];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a typical business application, should the focus be on client processing via AJAX
UPDATE 4.0 Seems like iOS 4.0 changed something here. Same code producing incorrect backgrounds
I would like to write a web application that behaves identically to transmission's (the
A typical code fragment obtained from the YouTube embed feature looks like this: <object
A typical SWT sample code looks like the following code: final Display display =
Typical way of creating a CSV string (pseudocode): Create a CSV container object (like
Typical approaches recommend reading the binary via FileStream and comparing it byte-by-byte. Would a
The typical ConfigParser generated file looks like: [Section] bar=foo [Section 2] bar2= baz Now,
During a typical day programming, I implement functions in a way that I would
My question is similar this one here: ResultsController to another ResultsController A typical app

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.