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 1024017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:43:01+00:00 2026-05-16T11:43:01+00:00

i have this array called favorites referenced in my app delegate. When i access

  • 0

i have this array called favorites referenced in my app delegate.
When i access it in the view controller i use this code

MultiViewAppDelegate *app = (MultiViewAppDelegate *)[[UIApplication sharedApplication] delegate];
    [app.favoritesArray addObject:@"one"];

And in the table thats supposed to display this information im trying to ask if the array contains a certain element and if it does to display that item using this code.

NSLog (@"2");
favoritesArray = [[NSMutableArray alloc]init];

didContain = [[NSMutableArray alloc]init];

NSLog (@"3");

if ([favoritesArray containsObject:@"one"])

{[didContain addObject:@"one"];
NSLog (@"4"); }

however the code isnt running after nslog 3…
can someone inform me why?

  • 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-16T11:43:01+00:00Added an answer on May 16, 2026 at 11:43 am

    Firstly,

    NSLog (@"2");
    favoritesArray = [[NSMutableArray alloc]init];
    

    The above line will reset your favoritesArray. It will also leak the old one.

    didContain = [[NSMutableArray alloc]init];
    
    NSLog (@"3");
    
    if ([favoritesArray containsObject:@"one"])
    

    Here, you’re simply asking an empty array if it contains something, which it obviously doesn’t.

    {[didContain addObject:@"one"];
    NSLog (@"4"); }
    

    Which is why none of the above ever happens.

    Instead of resetting it, make sure it’s set instead.

    if (favoritesArray != nil && 
        [favoritesArray containsObject:@"one"]) {
        NSLog(@"yay, it had one in it");
    } else {
        NSLog(@"it's nil or it didn't have one in it");
    }
    

    You probably don’t need favoritesArray != nil, but I put it in because you might have put your alloc-init stuff in because you sometimes get a nil value here. Unlikely though.

    if ([favoritesArray containsObject:@"one"]) {
        // contains "one"
    }
    

    That should probably do it.

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

Sidebar

Related Questions

I have an array called $array_all; This array will always have 3 possible values:
I'll try and explain this the best I can. I have an array called
I have an array called selectMe formed by a variable wich contains a string
I have a ListView that displays every item in an array called, Facts_Array. What
I have this app of mine that contains a section that will allow the
Hi I have this simple array inside my variable with some colors var clr
Hello i got a question, i have a session array called 'addToCart', in there
I have an array of type Person, which contains string objects: FirstName, LastName, login.
I have an array with a few elements: MSN = 34.3433423432434% Chrome = 12.4343434353534%
public class Main { public static void main(String args []){ long numberOfPrimes = 0;

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.