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

  • SEARCH
  • Home
  • 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 7772045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:47:47+00:00 2026-06-01T16:47:47+00:00

can somebody please explain me the difference between the following code snippets for filling

  • 0

can somebody please explain me the difference between the following code snippets for filling the myStrings array:

    NSString *match = @"ad*.png";

    NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
    NSPredicate *fltr = [NSPredicate predicateWithFormat:@"SELF like %@", match];

    NSArray *onlyPNGs = [dirContents filteredArrayUsingPredicate:fltr];

    myStrings = [NSMutableArray array];
    for(int i=0;i<[onlyPNGs count];i++)
    {
        [myStrings addObject:(NSString *)[onlyPNGs objectAtIndex:i]];
    }
    NSLog([myStrings description]);

When I fill my array this way, after the constructor, myStrings becomes null somehow but instead of filling with filter, if I add items manually everythings fine:

     [myStrings addObject:@"adburgerking1.png"];
    [myStrings addObject:@"adburgerking2.png"];
    [myStrings addObject:@"adburgerking3.png"];
    [myStrings addObject:@"addominos1.png"];
    [myStrings addObject:@"admcdonalds1.png"];
    [myStrings addObject:@"admcdonalds2.png"];
    [myStrings addObject:@"admcdonalds3.png"];
    [myStrings addObject:@"admeshuriskender1.png"];
    [myStrings addObject:@"adquickchina1.png"];
    [myStrings addObject:@"adsencam1.png"];
    [myStrings addObject:@"adsultanahmetkoftecisi1.png"];

Thanks in advance!!!

  • 1 1 Answer
  • 1 View
  • 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-06-01T16:47:49+00:00Added an answer on June 1, 2026 at 4:47 pm

    From your first comment: myStrings is a property with retain semantics – a property will only retain a value if accessed as a property (self.myStrings = ...), if you directly assign to a underlying variable (myStrings = ...) there will be no retain.

    From your second comment: [[NSMutableArray alloc] init] vs. [NSMutableArray array] – [[NSMutableArray alloc] init] returns an array you own, you don’t retain it to keep it; however [NSMutableArray array] returns an array you do not own, you must retain it if you wish to keep it.

    So what you need is:

    self.myStrings = [NSMutableArray array];
    

    The RHS returns an array you do not own, the LHS will retain it – now it will stay around.

    You might be tempted to use:

    myStrings = [[NSMutableArray alloc] init];

    as the RHS returns an array you own and the LHS just stores it without retaining it as you’re accessing the variable and not the property. However this version will not release any previous array referenced by myStrings so does not work in general.

    The rule is always access a property using dot notation, with the possible exception of a classes init and dealloc methods (this last bit is debated).

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

Sidebar

Related Questions

can somebody please explain what is the difference between the following mechanisms of passing
Can somebody please explain with examples (of code) what is the difference between deadlock
Can somebody please explain to me the difference between: Session.Add(name,txtName.text); and Session[name] = txtName.text;
I'm a little bit confused, can somebody please explain the main difference between those
can somebody please explain what is the difference between freeglut.h and glut.h
Can somebody please explain what is the main difference between visual studio and Qt?
Can somebody please explain (with example) the difference between context-independent and context-dependent overloading?
Can somebody please explain me the difference between the terms high memory and high
can somebody please explain difference between those two declarations in the properties of the
Can somebody please explain to me the meaning of this line of code? val

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.