Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 699469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:23:23+00:00 2026-05-14T03:23:23+00:00

+ (void)findAndCopyOfDatabaseIfNeeded{ NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [path objectAtIndex:0]; NSFileManager

  • 0
+ (void)findAndCopyOfDatabaseIfNeeded{
NSArray         *path               = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString        *documentsDirectory = [path objectAtIndex:0];

NSFileManager   *fileManager        = [NSFileManager defaultManager];
NSString        *databasePath       = [documentsDirectory stringByAppendingPathComponent:@"DB"];
BOOL success = [fileManager fileExistsAtPath:databasePath];
if(!success){
    NSString *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"DB"];
    [fileManager copyItemAtPath:resourcePath toPath:databasePath error:NULL];
}

NSString        *tracePath          = [documentsDirectory stringByAppendingPathComponent:@"Trace"];
BOOL traceDir = [fileManager fileExistsAtPath:tracePath];
if(!traceDir){
    NSString        *resourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Trace"];
    [fileManager copyItemAtPath:resourcePath toPath:tracePath error:NULL];
}


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy"];

NSDate   *today         = [[NSDate alloc]init];
NSString *resultYear    = [dateFormatter stringFromDate:today];
NSString *traceYearPath = [tracePath stringByAppendingPathComponent:resultYear];
BOOL yearDir = [fileManager fileExistsAtPath:tracePath];
if (!yearDir) {
    [fileManager createDirectoryAtPath:traceYearPath attributes:nil];
}
//[resultYear     release];  ?
//[today      release];  ?
//[dateFormatter  release];  ?

}

I’m using global class like this [ + (void)findAndCopyOfDatabaseIfNeeded ].
hm,, I don’t know NSArray, NSString and NSFileManager are released.

Variable release or Not release ? please advice for me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T03:23:24+00:00Added an answer on May 14, 2026 at 3:23 am
    NSString *resultYear    = [dateFormatter stringFromDate:today];
    //[resultYear     release];  ?
    

    You do not need to release resultYear. The object returned from the stringFromDate: will be autorelease‘d.

    It’s usually safe to assume that objects returned from methods whose names do not start with “create” or “new” will be autorelease‘d. At least with Apple code, but this is a convention for Cocoa in general, so you should also follow it.

    NSDate   *today         = [[NSDate alloc]init];
    //[today      release];  ?
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    //[dateFormatter  release];  ?
    

    You need to release both today and dateFormatter, since you alloc‘ed them. Always pair an alloc with a release or autorelease in your own code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

- (void)viewDidLoad{ [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@VidName ofType:@mov]; NSURL *url =
- (void) showMail { [[CCDirector sharedDirector] pause]; NSString*myemail=@sirano0629@me.com; NSArray*email=[[NSArray alloc]initWithObjects:myemail, nil]; if([MFMailComposeViewController canSendMail]) {
- (void)loadLocations { NSString *url = @<URL to a text file>; NSStringEncoding enc =
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint
- (void)viewDidLoad { moveObjectTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(moveObject) userInfo:nil repeats:YES] -(void)moveObject image.center =
- (void)viewDidLoad { [super viewDidLoad]; definedNames = [[NSArray alloc] initWithObjects:@Ohio, @Newark, @Steve, @Coffee, nil];
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ //currentElenet is NSString
- (void)viewDidLoad { [super viewDidLoad]; definedNames = [[NSArray alloc] initWithObjects:@Ohio, @Newark, @Steve, @Coffee, nil];
- (void)saveCollectionMoment:(NSArray *)collectionMoments { for (NSDictionary *momentData in collectionMoments) { int mID = [[momentData
void ReadContent(string path) { Contract.Requires(path!=null); string contentofileasstring = filehelperobj.GetContent(path); if(String.IsNullOrEmpty(contentofileasstring )) { throw new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.