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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:00:01+00:00 2026-05-25T20:00:01+00:00

I would like to access the the _news items in a loop. But don’t

  • 0

I would like to access the the _news items in a loop. But don’t know how to get this done.

Hierarchy of my Game-News structure

My Game.m looks like

#import "Game.h"

@implementation Game

@synthesize homename = _homename;
@synthesize guestname = _guestname;
@synthesize date = _date;
@synthesize gametype = _gametype;
@synthesize news = _news;
@synthesize gameId = _gameId;

-(NSString*)description{
    return [NSString stringWithFormat:@"%@ gegen %@ (%@)", self.homename, self.guestname,     self.gametype];
}

@end

My Game.h looks like

#import <Foundation/Foundation.h>
#import <RestKit/RestKit.h>
#import "News.h"

@interface Game : NSObject {
NSString* _homename;
NSString* _guestname;
NSString* _date;
NSString* _gametype;
NSNumber* _gameId;
//    News* news;
@public
    NSArray* _news;  
}

@property (nonatomic, retain) NSString* homename;
@property (nonatomic, retain) NSString* guestname;
@property (nonatomic, retain) NSString* date;
@property (nonatomic, retain) NSString* gametype;
//@property (nonatomic, retain) News* news;
@property (nonatomic, retain) NSArray* news;
@property (nonatomic, retain) NSNumber* gameId;

@end

My News.h looks like

    #import <Foundation/Foundation.h>
    #import <RestKit/RestKit.h>
@interface News : NSObject {
    NSString* _minute;
NSString* _title;
    NSString* _bodytext;
    NSString* _player;
}

@property (nonatomic, retain) NSString* minute;
@property (nonatomic, retain) NSString* title;
@property (nonatomic, retain) NSString* bodytext;
@property (nonatomic, retain) NSString* player;


@end

My news.m looks like

#import "News.h"

@implementation News

@synthesize player = _player;
@synthesize title = _title;
@synthesize bodytext = _bodytext;
@synthesize minute = _minute;

@end

And the code where I want to access the variable looks like:

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
    NSLog(@"Loaded statuses: %@", objects);  
    HeaderText.text = [NSString stringWithFormat:@"%@", objects ];

//  for(News* n in _news) NSLog([n _bodytext]);
//    for (id object in objects) {        
//            NSLog(@"News = %@", object );
//   }
}

The NSLog with objects looks good for the game. The next thing is that I want to do something like (above is more pseudo code than real code because I don’t know how to do it right):

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
NSLog(@"Loaded statuses: %@", objects);  
  HeaderText.text = [NSString stringWithFormat:@"%@", objects ];

  // loop all 
  for (id object in objects) {    
      news = objects.news;
      for (id mynews in news) {        
             NSLog(@"News minute = %@", news.minute );
             NSLog(@"News title = %@", news.title );
             NSLog(@"News bodytext = %@", news.bodytext );
             NSLog(@"News player = %@", news.player );

      }
  }
}

How to do the getter/setter methods right (so that I can use it here)?

Sorry for the surely stupid question but I don’t get the point with it.

  • 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-25T20:00:02+00:00Added an answer on May 25, 2026 at 8:00 pm

    Two things:

    1stly, is the _news object a private variable, without having a property declaration (getters and setters for e.g.)? The ‘_variableName’ format is usually used to denote private variables.

    2ndly, if it is not a private variable, do all the items within the _news array belong to the same class?

    If so, you can do a

    for (NewsObject *theNewsObject in _news)
        { 
          //code here
        }
    

    The for(id randomObject in array) is useful when you don’t know what type of object is in the array or if the objects contained in the array are of different types.

    Now, again, all the objects inside the NewsObject ought to be public properties that can be accessed by other classes (they should have getters and setters).

    Hope this helps. 🙂

    EDIT FOR UPDATED QUESTION

    So, if I’m getting your question correctly, you have a Game object, which has an array of News object inside it.

    So, in your Game.h

    NSString* _homename;
    NSString* _guestname;
    NSString* _date;
    NSString* _gametype;
    NSNumber* _gameId;
    NSArray * _newsObjects; //declare it as NSMutableArray if you need to mutate it
    

    Now, where you declare your properties;

    @property(nonatomic, retain)NSArray *newsObjects
    

    Synthesize it like you normally would in the Game.m file

    You are creating the getters/setters automatically by using the @synthesize directive. It creates the getters and setters for you.

    Again, from your code, it looks like the NSArray of objects that are passed through the method

    - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
    

    consist of Game objects.

    So, to access the News object from within the array of Game objects, import News.h and Game.h in the class where this method is being executed, and do the following:

    - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
        NSLog(@"Loaded statuses: %@", objects);  
    
        // loop all 
        for (Game *gameObject in objects) {    
          NSArray *newsObjectArray = [gameObject newsObjects] //or gameObject.newsObject
          for (News *mynews in newsObjectArray) {        
             NSLog(@"News minute = %@", mynews.minute );
             NSLog(@"News title = %@", mynews.title );
             NSLog(@"News bodytext = %@", mynews.bodytext );
             NSLog(@"News player = %@", mynews.player );
    
          }
        }
     }
    

    What I found in your code that there was code that was being executed which was not declared in any part of the example that you posted.
    What the code above will do is it will look through the Game object array (called objects).
    Then, for each gameObject within that array, it will loop through the array of newsObject for that gameObject.

    Hope this helps. 🙂

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

Sidebar

Related Questions

I would like to access class variables with for loop, here is my simple
I have a class in my asp.net proj, I would like to get access
I know about the real-time API, but I don't believe it has access to
I would like to access the work items in our TFS programmatically. Shouldn't there
I would like to access a MySQL database using PHP. Can someone please explain
I've got a website hosted on my IIS and I would like to access
I have an IEnumerable object. I would like to access based on index for
I would like to have access to the Seconds_Behind_Master field, (as returned by SHOW
I would like to define access right to Collabnet Subversion Directory with LDAP domain
We have a project (Web/PHP) where we would like users to access their files,

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.