Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 18, 2010, 07:51 AM   #1
mikezang
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
How can I speedup list for table view?

I use some code as below to prepare list for my table view, it is very slow, is there any faster way to make list?
Code:
-(BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    // Override point for customization after application launch.
	NSBundle *bundle = [NSBundle mainBundle];
	NSString *filePath = [bundle pathForResource:@"index" ofType:@"txt"];
	NSString *contents = [NSString stringWithContentsOfFile:filePath encoding:NSShiftJISStringEncoding error:nil];
	NSArray *list = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
	int i = 0;	
	
	if (list) {
		NSMutableArray *stock = [[NSMutableArray alloc] init];
	
		for (NSString *item in list) {
			if ([item length] != 0 && i != 0) {
				NSRange obs = [item rangeOfString:@"OBS"];
				
				if (obs.location == NSNotFound) {
					obs = [item rangeOfString:@"A100"];
					
					if (obs.location == NSNotFound) {
						[stock addObject:item];
					}
				}
			}
			
			i++;
		}
		
		stockSplit = stock;
	}
}
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Aug 18, 2010, 08:15 AM   #2
robbieduncan
Moderator
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Since you are loading this file from within your application bundle you are 100% in control of the format. Make it a plist in a format that is basically what you want instead of parsing a massive string. The parsing is what is slow.
robbieduncan is offline   0 Reply With Quote
Old Aug 18, 2010, 08:26 AM   #3
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
At the moment, I just test my logic so I put file in SandBox, in fact, this file is downloaded from Internet, so that I can't modify its format
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Aug 18, 2010, 11:47 AM   #4
chown33
macrumors 603
 
Join Date: Aug 2009
Post a sample of the data to be parsed.

Have you looked at NSScanner?
chown33 is offline   0 Reply With Quote
Old Aug 18, 2010, 12:00 PM   #5
Anne R. Kist
macrumors newbie
 
Join Date: Aug 2010
Location: ...in the UK
Processing like this should not be done in the main run loop but moved to a background thread instead.
Anne R. Kist is offline   0 Reply With Quote
Old Aug 18, 2010, 06:26 PM   #6
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by chown33 View Post
Post a sample of the data to be parsed.

Have you looked at NSScanner?
No, I haven't.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Aug 18, 2010, 06:27 PM   #7
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by Anne R. Kist View Post
Processing like this should not be done in the main run loop but moved to a background thread instead.
I also think so, but I am not sure how to do it, can you tell me where I can find a useful sample for background thread?
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Aug 18, 2010, 07:11 PM   #8
dejo
Moderator
 
dejo's Avatar
 
Join Date: Sep 2004
Location: The Centennial State
Quote:
Originally Posted by mikezang View Post
I also think so, but I am not sure how to do it, can you tell me where I can find a useful sample for background thread?
Advice for lengthy App startup processes
__________________
dejo is offline   0 Reply With Quote
Old Aug 18, 2010, 07:30 PM   #9
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by dejo View Post
Nice link.

To answer the unanswered question there:
As an aside, as the main thread is running in the main.c/autorelease pool, is there any issue with creating a separate nested autorelease pool in the worker thread method?
Every thread has its own separate autorelease pool(s). The new thread's pool is not nested with any other thread's pool or pools. This is discussed in the documentation, which everyone should read who plans on copying and pasting code using NSThread:
http://developer.apple.com/iphone/li...Reference.html
http://developer.apple.com/iphone/li.../uid/10000057i
chown33 is offline   0 Reply With Quote
Old Aug 18, 2010, 09:22 PM   #10
mikezang
Thread Starter
macrumors 6502a
 
Join Date: May 2010
Location: Tokyo, Japan
Quote:
Originally Posted by dejo View Post
Thanks for your link, it is very useful.
__________________
iPad Mini 32GB, iPhone 4S 16GB, iPad1 32GB, Mac mini 2.53GHz 4GB 320GB, ThinkPad T60
MyApp: Market Event v1.9.2
mikezang is offline   0 Reply With Quote
Old Aug 19, 2010, 05:11 PM   #11
ianray
macrumors 6502
 
Join Date: Jun 2010
Location: @
See also: http://news.atebits.com/post/1975808...th-uitableview
__________________
My App Store Apps: Dashometer, Exinf, Score&Grade
ianray is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Table View to Detail View hammy35 iPhone/iPad Programming 3 Apr 16, 2014 01:33 AM
View-based table view losing selection highlight Starfox Mac Programming 1 Nov 28, 2012 01:02 AM
Find location of table view cell that calls view controller moonman239 iPhone/iPad Programming 3 Nov 24, 2012 05:31 PM
View based table view layout woes Starfox Mac Programming 0 Nov 8, 2012 10:50 PM
Pushing to a Detail View from a Table View Cell using Xcode Storyboard xcodeApp10 iPhone/iPad Programming 2 Sep 17, 2012 03:45 PM

Forum Jump

All times are GMT -5. The time now is 10:40 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC