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 09-21-2011, 07:07 PM   #1 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 29
appchamp4 is on a distinguished road
Default Decrease load times?

Hi I have an app where one of the features on the main page is a countdown to a certain date.

This is my code in my viewdidload:

Code:
destinationDate = [[NSDate dateWithTimeIntervalSince1970:1358303211] retain];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES];
and my updatelabel method:

Code:
-(void)updateLabel:(NSTimer *)timer {
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    int units = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
    NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
    daysLabel.text = [NSString stringWithFormat:@"%d", [components day]];
    hoursLabel.text = [NSString stringWithFormat:@"%d", [components hour]];
    minutesLabel.text = [NSString stringWithFormat:@"%d", [components minute]];
}
This works great except it takes a little long to show up upon app launch. Is there anyway to reduce the time it takes to execute this?

Thanks
appchamp4 is offline   Reply With Quote
Old 09-21-2011, 07:14 PM   #2 (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 appchamp4 View Post
Hi I have an app where one of the features on the main page is a countdown to a certain date.

This is my code in my viewdidload:

Code:
destinationDate = [[NSDate dateWithTimeIntervalSince1970:1358303211] retain];
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel:) userInfo:nil repeats:YES];
and my updatelabel method:

Code:
-(void)updateLabel:(NSTimer *)timer {
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    int units = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit;
    NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
    daysLabel.text = [NSString stringWithFormat:@"%d", [components day]];
    hoursLabel.text = [NSString stringWithFormat:@"%d", [components hour]];
    minutesLabel.text = [NSString stringWithFormat:@"%d", [components minute]];
}
This works great except it takes a little long to show up upon app launch. Is there anyway to reduce the time it takes to execute this?

Thanks
The time is being taken in the code you didn't show. (loading nibfiles, running your appDidFinishLoading, etc.)

You should learn to use the time profiler instrument in Instruments. It will let you figure out where the time is being spent at startup. Once you know what's taking a long time, you can figure out how to reduce that time.

BTW the code you posted leaks the calendar object. Since you are using a clalendar over and over, why not create one in your init method and save it in a retained property, then use the existing calendar?
__________________
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 09-21-2011, 07:42 PM   #3 (permalink)
Registered Member
 
Join Date: Sep 2011
Posts: 29
appchamp4 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
The time is being taken in the code you didn't show. (loading nibfiles, running your appDidFinishLoading, etc.)

You should learn to use the time profiler instrument in Instruments. It will let you figure out where the time is being spent at startup. Once you know what's taking a long time, you can figure out how to reduce that time.

BTW the code you posted leaks the calendar object. Since you are using a clalendar over and over, why not create one in your init method and save it in a retained property, then use the existing calendar?
great thanks, that was actually really helpful
appchamp4 is offline   Reply With Quote
Old 09-22-2011, 06:45 PM   #4 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 97
Bopols is on a distinguished road
Default

are you testing the load time in the device and not the simulator?
Bopols 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: 394
14 members and 380 guests
7twenty7, eski, EvilElf, HemiMG, iOS.Lover, jarv, n00b, pbart, Pudding, sacha1996, Sami Gh, UMAD, VinceYuan, yuncarl28
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,672
Threads: 94,121
Posts: 402,905
Top Poster: BrianSlick (7,990)
Welcome to our newest member, yuncarl28
Powered by vBadvanced CMPS v3.1.0

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