Results 1 to 4 of 4
  1. #1
    Quick question about Date from string

    Member Since
    Feb 14, 2013
    Posts
    4
    Quick question about Date from string
    In my learning book, objective-c for absolute beginners, is written the following example

    Code:
        
        NSDate *today = [NSDate date];
        NSDate *saleDate = [NSDate dateWithString:@"2011-12-04 04:00:00 -700"];
    The second line is giving me problems in that dateWithString doesn't seem to be a method of the NSDate class. Using google I learned that that is only available on the OS X version of the class.

    So I resolved it as follows
    Code:
        NSDate *saleDate = [[[NSDateFormatter alloc] init] dateFromString:@"2011-12-04 04:00:00 -700"];
    Is this the best and fastest way to do so ?

  2. #2
    Quick question about Date from string
    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    8,189
    Specs:
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3
    That is indeed the right class to be using on iOS. You will find as you are learning Obj-C that the Cocoa (OS X) and Cocoa Touch (iOS) frameworks are similar but have subtle differences..
    --
    Regards
    ...Ashwin



    Be sure to read the Community Guidelines | The more information you provide, the better answers you get, remember GIGO.

  3. #3
    Quick question about Date from string

    Member Since
    Feb 14, 2013
    Posts
    4
    Quote Originally Posted by Raz0rEdge View Post
    That is indeed the right class to be using on iOS. You will find as you are learning Obj-C that the Cocoa (OS X) and Cocoa Touch (iOS) frameworks are similar but have subtle differences..
    Ok, thank you!

    Seems a bit circuitous to me to have alloc and init a class to be able to do that. But it might be my little .net knowledge that's throwing me off...

  4. #4
    Quick question about Date from string
    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    8,189
    Specs:
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3
    The "[[object alloc] init]" is a common syntax in Objective-C. You first allocated an instance of the object and then send it the "init" message that is going to initialize all the internal variables.

    All of the NSObjects define the init and dealloc methods that you would send to allocate/initialize the object and deallocate itself..
    --
    Regards
    ...Ashwin



    Be sure to read the Community Guidelines | The more information you provide, the better answers you get, remember GIGO.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 12-27-2013, 01:49 PM
  2. Last Modified Date Question
    By sottovoce in forum Switcher Hangout
    Replies: 4
    Last Post: 03-12-2013, 12:27 PM
  3. Question about safari and adding date to status bar?
    By pcc in forum Switcher Hangout
    Replies: 2
    Last Post: 06-26-2012, 09:38 AM
  4. ''Date modified'' column in Finder app shows the same date for every file
    By commparlimage in forum OS X - Apps and Games
    Replies: 1
    Last Post: 11-19-2011, 11:52 AM
  5. Quick Quick question about shopping on ebay?
    By srgthunder in forum Apple Notebooks
    Replies: 5
    Last Post: 07-18-2007, 11:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •