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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:12:19+00:00 2026-06-13T11:12:19+00:00

I am following a tutorial from Ray Wenderlich site and i am trying to

  • 0

I am following a tutorial from Ray Wenderlich site and i am trying to understand this code where it has nsarray readonly and nsmutableble array with the same name but writable. Also what is the reason to use _(underscore)property vs setting a property and using self.x Here is the code:
this is from the site

MatchmakingServer.h

@interface MatchmakingServer : NSObject <GKSessionDelegate>

@property (nonatomic, assign) int maxClients;
@property (nonatomic, strong, readonly) NSArray *connectedClients;
@property (nonatomic, strong, readonly) GKSession *session;

- (void)startAcceptingConnectionsForSessionID:(NSString *)sessionID;

@end

MatchmakingServer.m

#import "MatchmakingServer.h"

@implementation MatchmakingServer
{
    NSMutableArray *_connectedClients;
}

@synthesize maxClients = _maxClients;
@synthesize session = _session;

- (void)startAcceptingConnectionsForSessionID:(NSString *)sessionID
{
    _connectedClients = [NSMutableArray arrayWithCapacity:self.maxClients];

    _session = [[GKSession alloc] initWithSessionID:sessionID displayName:nil sessionMode:GKSessionModeServer];
    _session.delegate = self;
    _session.available = YES;
}

I am doing something like this instead

matchmakingserver.h

@interface zvMatchMakingServer : NSObject <GKSessionDelegate>

@property (nonatomic, assign) int maxClients;
@property (nonatomic, strong, readonly) NSArray *connectedClients;
@property (nonatomic, strong, readonly) GKSession *session;

- (void)startAcceptingConnectionsForSessionID:(NSString *)sessionID;


@end

matchmakingserver.m

@interface zvMatchMakingServer()

@property (nonatomic,strong) NSMutableArray *connectedClients;
@property (nonatomic, strong) GKSession *session;

@end

@implementation zvMatchMakingServer


-(NSArray *)connectedClients
{
    return self.connectedClients;
}

-(void)startAcceptingConnectionsForSessionID:(NSString *)sessionID
{
    self.connectedClients = [[NSMutableArray alloc]initWithCapacity:self.maxClients];
    self.session = [[GKSession alloc]initWithSessionID:sessionID displayName:nil sessionMode:GKSessionModeServer];

}

Is what i am doing basically the same thing or it won’t work. Thank you!

  • 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-13T11:12:20+00:00Added an answer on June 13, 2026 at 11:12 am

    I’ll try to explain what happens in Ray’s code:

    He declares a property:

    @property (nonatomic, strong, readonly) NSArray *connectedClients;
    

    (I assume this was pre iOS 6, because in iOS 6 Apple changed the way properties generate iVars.)

    This property causes the compiler to automatically generate an iVar NSArray *connectedClients. This iVar is not used in the code. Instead he’s declaring a new (private) iVar named _connectedClients of type NSMutableArray. Note that he doesn’t synthesize the accessors for the property. He writes the accessor himself and instead of returning the iVar generated by the property (connectedClients), he’s returning his ‘own’ iVar (_connectedClients):

    - (NSArray *)connectedClients
    {
        return _connectedClients;
    }
    

    Since NSMutableArray is a subclass of NSArray there’s no problem doing that.

    What you’re doing is trying to redeclare the property @property (nonatomic,strong) NSMutableArray *connectedClients; as private property and that’s not allowed. Carefully compare your code to Ray’s, then you’ll see the difference.

    As for the underscore:

    That’s only a convention many people use to name their iVars. It has no semantical meaning.
    In fact Apple changed the names of ‘auto-generated’ iVars to also use the underscore.

    Pre iOS 6 a property

    @property (...) SomeClass *name;
    

    generated an iVar named name. In iOS 6 that same property generates an iVar named _name. Also in iOS 6 you don’t need to add the @synthesize line anymore.

    Prefixing names of iVars with an underscore was convenient because if you wanted to override an automatically generated accessor the autocompletion suggested this:

    - (void)setName:(SomeClass *)name
    

    if your iVar was also named name the parameter name would hide the iVar in the accessor implementation, so you had to change the name of the parameter. If you renamed your iVar by using @synthesize name = _name the parameter name did no longer hide it and you could use the autocompletion generated code for the accessor.

    - (void)setName:(SomeClass *)name
    {
        //maybe release the old value and retain the new one if you're not using ARC and weather it's a retained property or not. 
       _name = name;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this tutorial from MSDN. There's something I saw in the code
I've just try Jasper Report, I'm following tutorial from this site Also I downloaded
I managed to get authentication to work by following the tutorial from this page
I am learning GWT, so I am following this tutorial from Google GWT https://developers.google.com/web-toolkit/tools/gwtdesigner/tutorials/stockwatcher
I have been following the affableBean tutorial from the NetBeans site located here .
I'm new to NHibernate... I have been following this NHibernate Tutorial from Gabriel Schenker
I been following a tutorial for making my webpage css 100% height from this
I am using following a tutorial from here: http://www.shopdev.co.uk/blog/cookies-with-jquery-designing-collapsible-layouts/ This is the script I
I'm following this iPhone tutorial from Apple and I think I did everything correctly,
I am getting this error while following the tutorial from railstutorial.org. Model class :

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.