Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-02-2012, 12:59 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 38
iOS.Lover is on a distinguished road
Default Save text in plist file with specific date

I am trying to store some stings into a plist file , the saving process works fine ,but this notes should be saved based on a specific date , for example I enter a note in 2 Feb then I need enter another note in 5 Feb , and when I move during these dates my notes should show on these dates , I would be grateful if you help me . here is my code :

Code:
//Save Setting ///////////////////
    - (NSString *) saveFilePath
    {
        NSArray *pathArray =
        NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

        NSDate *date = [NSDate date];

        return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"note.plist"];
    }

    - (void)applicationWillTerminate:(UIApplication *)application {

        NSArray *values = [[NSArray alloc] initWithObjects:saveTextToday.text ,nil];
        [values writeToFile:[self saveFilePath] atomically:YES];
        [values release];

    }


- (void)viewDidLoad {
////Save Setting /////////////////////////////////////////////////
    NSString *myPath = [self saveFilePath];
    BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:myPath];

    if (fileExists)
    {

        NSArray *values = [[NSArray alloc] initWithContentsOfFile:myPath];
        saveTextToday.text = [values objectAtIndex:0];

        [values release];
    }

    // notification
    UIApplication *myApp = [UIApplication sharedApplication];

    // add yourself to the dispatch table 
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationWillTerminate:) 
                                                 name:UIApplicationWillTerminateNotification 
                                             object:myApp];
iOS.Lover is offline   Reply With Quote
Old 02-02-2012, 01:05 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

What you want is not clear. You aren't doing anything with the date.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 02-02-2012, 03:54 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 38
iOS.Lover is on a distinguished road
Default

Quote:
Originally Posted by BrianSlick View Post
What you want is not clear. You aren't doing anything with the date.
I crate a custom calendar app which user can write their notes in it , for example in 3 Feb user writes something and this text should be saved in 3 Feb , and when user move to the another days he/she could write something else
iOS.Lover is offline   Reply With Quote
Old 02-02-2012, 04:06 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by iOS.Lover View Post
I crate a custom calendar app which user can write their notes in it , for example in 3 Feb user writes something and this text should be saved in 3 Feb , and when user move to the another days he/she could write something else
So you want to save your notes in a file which is named using the date?

As Brian says, you don't do anything with the date you create.

You need to convert the date into a string that can be part of a legal filename and build that into the filename.

Id suggest simply using noteYYYYMMDD

You can generate specific strings from dates using date formatters. I am no expert at those, and have to puzzle through the documentation and struggle with them any time I need to do anything. Can't really help you with that at the moment.

You could also use an NSCalendar object to get date components from your date, and build your date string yourself.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-02-2012, 04:10 PM   #5 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 38
iOS.Lover is on a distinguished road
Default

thanks , I am using this code to show the date , :

Code:
- (NSString *) showPersianFullDate {
    
        
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSLocale *locale = [NSLocale currentLocale];
    [dateFormatter locale];
    [dateFormatter calendar];
    
    
    //ADDING DAY
    offsetComponents = [[NSDateComponents alloc] init];
    offsetComponents.day = _dayNumber;
    
    NSDate *nextDate = [calendar dateByAddingComponents:offsetComponents toDate:[NSDate date] options:0];
    
    [dateFormatter setDateFormat:@"EEEE ، d MMMM"];
	NSString *currDay = [dateFormatter stringFromDate:nextDate];
    
    [NSString stringWithFormat:@"%@",currDay];
    
    [calendar release];
    [dateFormatter release];
    return currDay;
    
}
But I don't know how can connect this date to saving process
iOS.Lover is offline   Reply With Quote
Old 02-02-2012, 07:04 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by iOS.Lover View Post
thanks , I am using this code to show the date , :

Code:
- (NSString *) showPersianFullDate {
    
        
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    NSLocale *locale = [NSLocale currentLocale];
    [dateFormatter locale];
    [dateFormatter calendar];
    
    
    //ADDING DAY
    offsetComponents = [[NSDateComponents alloc] init];
    offsetComponents.day = _dayNumber;
    
    NSDate *nextDate = [calendar dateByAddingComponents: offsetComponents toDate:[NSDate date] options:0];
    
    [dateFormatter setDateFormat:@"EEEE ، d MMMM"];
	NSString *currDay = [dateFormatter stringFromDate:nextDate];
    
    [NSString stringWithFormat:@"%@",currDay];
    
    [calendar release];
    [dateFormatter release];
    return currDay;
    
}
But I don't know how can connect this date to saving process
You're cutting and pasting bits of code almost at random, without any real idea what you're doing. You have quite a few statements in that function that do absolutely nothing:

These two lines return the value of properties of the date formatter that you create, which you ignore.
Code:
    [dateFormatter locale];
    [dateFormatter calendar];

You create a variable offsetComponents, and set it up to hold a value _dayNumber, for no apparent reason:
Code:
    //ADDING DAY
    offsetComponents = [[NSDateComponents alloc] init];
    offsetComponents.day = _dayNumber;
You add offsetComponents to your date, again for no apparent reason.

This line does absolutely nothing:

Code:
    [NSString stringWithFormat:@"%@",currDay];
The code you've posted is such a confused muddle that I can't even tell what you are trying to do.

Explain to me in words what you want to do with dates.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On



» Advertisements
» Online Users: 403
16 members and 387 guests
Atatator, chiataytuday, dre, FrankWeller, imac74, ipodphone, jeroenkeij, kukat, LunarMoon, MAMN84, n00b, QuantumDoja, reficul, Retouchable, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,675
Threads: 94,124
Posts: 402,909
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Retouchable
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0