New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
iOS Development Discussion on developing apps for the iOS platform.

Quick question about Date from string


Post Reply New Thread Subscribe

 
Thread Tools
SaveMe

 
Member Since: Feb 14, 2013
Posts: 4
SaveMe is on a distinguished road

SaveMe is offline
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 ?
QUOTE Thanks
Raz0rEdge

 
Raz0rEdge's Avatar
 
Member Since: Jul 17, 2009
Location: MA
Posts: 7,699
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
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.
QUOTE Thanks
SaveMe

 
Member Since: Feb 14, 2013
Posts: 4
SaveMe is on a distinguished road

SaveMe is offline
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...
QUOTE Thanks
Raz0rEdge

 
Raz0rEdge's Avatar
 
Member Since: Jul 17, 2009
Location: MA
Posts: 7,699
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
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.
QUOTE Thanks

Post Reply New Thread Subscribe


« Simple App Needs HELP | Making Sine Wave Sounds In Xcode »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Quick iPhoto question RhysC Images, Graphic Design, and Digital Photography 2 08-06-2012 10:46 AM
Quick macbook question hexdevil Apple Notebooks 1 09-04-2008 05:45 PM
iWeb quick Question albertlv OS X - Apps and Games 1 07-05-2008 09:37 PM
3.06GHz iMac Ordered, Just A Quick Question... p0ssum man Switcher Hangout 6 06-24-2008 05:12 PM
Quick question Dazzypants OS X - Operating System 4 10-26-2006 11:08 AM

All times are GMT -4. The time now is 02:48 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?