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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:56:49+00:00 2026-06-14T00:56:49+00:00

I’m not sure if I used the correct terms, please understand I just started

  • 0

I’m not sure if I used the correct terms, please understand I just started experimenting with objective yesterday and I came from a c# background so I might use some c# terms.

With that said. I have two classes. 1 main class which uses the other class as a property:

@class Fighter;
@interface Match : NSObject{
    int Id;
    Fighter *Fighter;
    int FScore;
}
@property int Id, FScore;
@property Fighter *Fighter;

@end

*implementation:

@implementation Match
@synthesize Id, FScore, Fighter;    
@end

This is the class referenced:

@interface Fighter : NSObject{
    int Id;
    NSString *Name;
}
@property int Id;
@property NSString *Name;
@end


@implementation Fighter
@synthesize Id, Name;
@end

Now this is how I would create an instance of the object

@autoreleasepool {

        // insert code here...
        NSLog(@"Hello, World!");

        Match *match = [[Match alloc]init];
        match.Id = 1;
        match.Fighter = [[Fighter alloc]init];
        match.Fighter.Id = 9;
        match.Fighter.Name = @"womp";
    }

Now, I was wondering if there’s like a shortcut in assigning the values for the Fighter instance. As in c# you can do something like so:

match.Fighter = new Fighter{ Id = 9, Name = "womp" };

Wanted to know just in case I may add several more properties to that class or to any other class.

PS.

Is it better to use [[Class alloc] init] than [Class new]??

Thanks!!!

  • 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-14T00:56:50+00:00Added an answer on June 14, 2026 at 12:56 am

    The typical way to do this in Objective-C is to create a custom -init method with arguments for properties to be initialized. So you might have a -[Fighter initWithID:name:] method:

    - (id)initWithID:(NSInteger)id name:(NSString *)name
    {
        self = [self init];
        if (self) {
            self.ID = id;
            self.name = name;
        }
        return self;
    }
    

    Then you create your fighter object with:

    match.fighter = [[Fighter alloc] initWithID:9 name:@"womp"];
    

    A couple comments on your code. In Objective-C it is convention to begin property names with a lowercase letter. The exception is if the name of the property is an acronym like ‘ID’ or ‘URL’, in which case you make it all uppercase. This same is true of method and variable names. Capitalized names are reserved for types including class names (e.g. ‘Fighter’).

    Regarding your P.S. question, +new just calls alloc then init and returns the result, so they’re exactly equivalent. That said, +new is not really commonly used among Objective-C programmers, and you’ll see alloc/init used much more frequently.

    Finally, assuming you’re deploying to a target using the modern Objective-C runtime (10.6+ and 64-bit) you don’t need to explicitly declare instance variables to back your @properties, because the compiler will synthesize (create) them for you. With recent versions of Xcode (4.4 and higher), you don’t even need the @synthesize statements, because the compiler will insert those for you too. The @property statement is all you need.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT

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.