I'm using ScriptingBridge.framework in order to interact with Mail.app. The following code is taking about 30 seconds to load 100 messages. I'm running it on a 2.8GHz Core i7 MacBook Pro with 4GB (1333 MHz DDR3) mem. My OS is 10.7.4.
MailApplication *mailApp = [SBApplication applicationWithBundleIdentifier:@"com.apple.mail"];
MailMailbox *inbox = [mailApp inbox];
SBElementArray *messages = [inbox messages];
NSMutableArray *tmp = [NSMutableArray arrayWithCapacity:[messages count]];
for (MailMessage *message in messages) {
RRMailItem *mailitem = [RRMailItem new];
[mailitem setSender:[message sender]];
[mailitem setSubject:[message subject]];
[mailitem setDate:[message dateSent]];
if (message.mailAttachments.count > 0) {
[mailitem setHasAttachment:YES];
}
[tmp addObject:mailitem];
}
RRMailItem is a simple object as follow. It's just an object to hold values. It doesn't have any method:
@interface RRMailItem : NSObject
@property NSString *sender;
@property NSString *subject;
@property NSDate *date;
@property BOOL hasAttachment;
@end
If I remove the if (message.mailAttachments.count > 0)
, the execution time goes down by 50%, to 15 seconds to load the same 100 messages. Much better, but still high. And I need the IF...
How can I improve the code performance? Any hints and tips are welcome.
TIA,
Bob
This link talks about it: