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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:48:09+00:00 2026-06-17T08:48:09+00:00

Can anyone tell me the functional difference between this code… for (int i =

  • 0

Can anyone tell me the functional difference between this code…

for (int i = 0; i < productsJSON.count; i++)
{
prod = [[Product alloc] init];

   prod.ItemID = [[productsJSON valueForKey:@"ItemID"] objectAtIndex:i];
   prod.Name = [[productsJSON valueForKey:@"Name"] objectAtIndex:i];

   [self.products addObject:prod];

}
[super viewDidLoad];

… and this code…

prod = [[Product alloc] init];
prod.ItemID = @”SB4UL”;
prod.Name = @”#4 Split Bolt- UL Approved”;
[self.products addObject:prod];

prod = [[Product alloc] init];
prod.ItemID = @”PVSC07GGUL”;
prod.Name = @”I Beam Grounding Clamp, UL”;
[self.products addObject:prod];

[super viewDidLoad];

… when prod.ItemID and prod.Name are NSString properties, and the values assigned in the “for” loop have — after exiting the loop — been visually confirmed to be the same as values assigned by the other block of code?

For all I can tell, both behave exactly the same until the moment I actually try to put the results to practical use in my app. The code appears in the viewDidLoad method of a UITableViewController. It gets passed to the cellForRowAtIndexPath method, where I can confirm that the values arrive intact. Then we step straight into the code block…

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”ProductCell”];
Product *product = [self.products objectAtIndex:indexPath.row];
cell.textLabel.text = product.Name;

If I’ve commented out the first block and run the second, the view displays flawlessly.

If I’ve commented out the second block and run the first, the program dies every time at “cell.textLabel.text = product.Name”, and it displays a seemingly random error message (e.g.: “Thread 1: EXEC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0)” or “Thread 1: signal SIGABRT” or “Thread 1:EXC_BAD_ACCESS(code=1, adress=0xf069996f”).

  • 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-06-17T08:48:09+00:00Added an answer on June 17, 2026 at 8:48 am

    @Joe was right — I just had to dig deeper to find it. The array is persistent, but the properties on the Product class were not.

    The productsJSON code is a variable specific to viewDidLoad. It died between methods, and the reference in the Product objects went bad.

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

Sidebar

Related Questions

Can anyone tell me why this code would not be working? $('body').on('test', function() {
Hey, I wanted to know if anyone can tell me what the difference between
For the UIApplicationMain function in main(), can anyone tell me the difference between specifying
Can anyone tell me why this function is not working ? for(var i=1;i<=12;i++) {
Can anyone tell me the cause of error ? Error is C:\web\template1.cpp||In function 'int
Can anyone tell me why the following code fails to submit the form into
Can any one tell me the difference between replace function & translate function of
Can anyone tell me how I close an opened SQL connection inside a Function?
can anyone tell me how to select data by date in MS.ACCESS database using
Can anyone tell me how I can correctly pass my application context to my

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.