• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Fastest way to convert an NSDate into an NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fastest way to convert an NSDate into an NSString


  • Subject: Re: Fastest way to convert an NSDate into an NSString
  • From: Mike Abdullah <email@hidden>
  • Date: Mon, 25 Jan 2010 20:33:40 +0000

This approach is probably creating a new NSDateFormatter for each date processed. What if you create your own formatter and use that for all dates?

On 25 Jan 2010, at 20:23, Keith Blount wrote:

> Hello,
>
> I am in the process of converting the data format for my application from one that just uses the NSKeyedArchiver methods to archive my objects to a file on disk to using the NSXML classes to generate a custom XML file (I need to do this for compatibility purposes). My main data object is essentially a (potentially very long) list (or rather tree) of items, each of which have two or three dates associated with them (among other things).
>
> Having completed the initial conversion process, it turns out that currently my XML-writing methods (using NSXMLElement, NSXMLDocument etc) are much, much slower than using NSKeyedArchiver. Using Sample, it turns out that a lot of the time is spent converting the NSDates for each of the items in my list to string objects. I have tried this using two different methods:
>
> NSDate *someDate = ...
>
> [xmlElement addAttribute:[NSXMLNode attributeWithName:"SomeDate" stringValue:[someDate descriptionWithLocale:nil]]];
>
> and
>
> NSXMLNode *attribute = [[NSXMLNode alloc] initWithKind:NSXMLAttributeKind];
> [attribute setName:@"SomeDate"];
> [attribute setObjectValue:someDate]
> [xmlElement addAttribute:attribute];
> [attribute release];
>
> But either way suffers the same performance hit. So, my question is, does anyone know of a much faster and more efficient way of converting NSDates to NSStrings? (A possible solution would be to change my data model to store these dates as strings internally so that the conversion is already done when they come to be written to file, but I was hoping for a more elegant solution.)
>
> Many thanks and all the best,
> Keith
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Fastest way to convert an NSDate into an NSString
      • From: Keith Blount <email@hidden>
    • Re: Fastest way to convert an NSDate into an NSString
      • From: "email@hidden" <email@hidden>
References: 
 >Fastest way to convert an NSDate into an NSString (From: Keith Blount <email@hidden>)

  • Prev by Date: Re: Fastest way to convert an NSDate into an NSString
  • Next by Date: Re: Fastest way to convert an NSDate into an NSString
  • Previous by thread: Re: Fastest way to convert an NSDate into an NSString
  • Next by thread: Re: Fastest way to convert an NSDate into an NSString
  • Index(es):
    • Date
    • Thread