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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:44:15+00:00 2026-05-16T19:44:15+00:00

I have just jumped into Objective-C and I got stuck pretty early on. I

  • 0

I have just jumped into Objective-C and I got stuck pretty early on. I will post code with my question but to keep it readable i’ll get rid of some of the crap, let me know if you want more code posted!

I have created a new object called ‘Phrase’ (subclassed from NSObject), and am reading items from JSON into these ‘Phrase’ objects and adding them to an array. Here’s the first lot of code:

Example JSON:

    {
    "phrases": [
        {
            "title": "Title of my Phrase",
         "definition" : "A way to look at some words",
   "location" : "Irish Proverb"
        }   
    ]
    }

Script I’m reading it in with:

    - (void)viewDidLoad {
    [super viewDidLoad];

 self.phraseDictionary = [[NSMutableArray alloc] initWithObjects:nil];

 NSString *filePath = [[NSBundle mainBundle] pathForResource:@"phrase" ofType:@"json"];  
 NSString *myRawJSON = [[NSString alloc] initWithContentsOfFile:filePath];

 NSData *jsonData = [myRawJSON dataUsingEncoding:NSUTF32BigEndianStringEncoding];
 NSDictionary *entries = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:nil];


 for (id key in entries) {

  NSObject *phrases = [entries objectForKey:key];

  for (id phrase in phrases) {

   Phrase *pushArrayToPhrase = [[Phrase alloc] initWithText:[phrase objectForKey:@"title"] definition:[phrase objectForKey:@"definition"] location:[phrase objectForKey:@"location"]];
   [self.phraseDictionary addObject:pushArrayToPhrase];

  }

    }
    }

Phrase m file:

#import "Phrase.h"


@implementation Phrase

@synthesize title;
@synthesize definition;
@synthesize location;

- (id)init {
 self = [super init];
 if (self != nil) {
  title = @"";
  definition = @"";
  location = @"";
 }
 return self;
}

- (id)initWithTitle:(NSString *)tit definition:(NSString *)def location:(NSString *)loc {
 self = [super init];
 if (self != nil) {
  title = tit;
  definition = def;
  location = loc;
 } 
 return self;
}


@end

From here I loop through the objects and add them to a list in my splitview:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

 static NSString *CellIdentifier = @"CellIdentifier";

 // Dequeue or create a cell of the appropriate type.
 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    Phrase *cellPhrase = [self.phraseDictionary objectAtIndex:indexPath.row];
 cell.textLabel.text = cellPhrase.title;
 return cell;
}

But when I click an item, and ask for a phrase based on the indexPath.row of the one clicked, I can only ever access the property used in the cell.textLabel.text. Any other attempt from here on in to access a property from the Phrase object exits the simulator.

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

 Phrase *cellPhrase = [self.phraseDictionary objectAtIndex:indexPath.row];
 detailViewController.detailItem = cellPhrase;
 //If i attempt 'cellPhrase.definition' here, the app will close without an error

}

Hope that’s easy to follow, let me know if it’s not and i’ll try again!

  • 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-16T19:44:15+00:00Added an answer on May 16, 2026 at 7:44 pm

    In the initWithTitle method you are assigning the variables but not retaining them. If they are not retained anywhere they will be released and when you try to access them your app will crash. If you are not getting any error messages make sure you turn debugging on.

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

Sidebar

Related Questions

I have just jumped into the Blackberry development arena... I am trying one example
I have just started to learn how to code iOS apps. I have made
I am very used to javascript and php programing, and I just jumped into
Before I delve into it, I'm very new to Android and I have just
Have just started converting an existing job tracking system into an ASP.NET MVC application.
Have just got a surprise and would appreciate some suggestions. The simple query below
C folks, I am a newbiew who just jumped into Obj-C for days. I
This just jumped into my head and I can't figure it out. If I
I have just created this table: create table dbo.OrderTypes ( ID smallint primary key
we have just started using a git account of our Django website project so

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.