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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:30:04+00:00 2026-05-31T17:30:04+00:00

i have a MyObject. when my program runs, i create a new MyObject self.myObject

  • 0

i have a MyObject. when my program runs, i create a new MyObject

self.myObject = [[MyObject alloc] initWithStuff:stuff];

later in my code, i need to create a new MyObject.

my question is, do i need to create a new MyObject with an “init” method?

.h
#import <UIKit/UIKit.h>

@interface MyObject : NSObject
{}

-(id)initWithStuff:(NSString *)stuff;
-(id)initWithNewStuff:(NSString *)newStuff;

-(id)newObjectWithStuff:(NSString *)newStuff;

@end

.m

-(id)initWithStuff:(NSString *)stuff;
{
    if (self = [super init])
    {
        self.myStuff = stuff;
    }
    return self;
}

-(id)initWithNewStuff:(NSString *)newStuff;{
    if (self = [super init])
    {
        self.myStuff = newStuff;
    }
    return self;
}

-(id)newObjectWithStuff:(NSString *)newStuff;
{
    self.myStuff = newStuff;

    return self;
}

or can i use a non-init method to create it?

in my code:

self.myObject = [[MyObject alloc] initWithNewStuff:newStuff];

or

self.myObject = [self.myObject newObjectWithStuff:newStuff];

i guess my question boils down to: what does

if (self = [super init])

do?

working with other objects such as dictionaries, i know “NSDictionary *myDict = myOtherDict” is perfect valid.

  • 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-31T17:30:05+00:00Added an answer on May 31, 2026 at 5:30 pm

    You can name your custom initializers as you want, but there’s a convention to start your initializer method with “init”.

    In examples you wrote, the objects are a subclass of NSObject the the root class of all hierarchies. The keyword super refers to the class above in the hierarchy (your class’s superclass), so basically, you’re calling the init method of NSObject which creates and initializes an object right after memory has been allocated for it (that’s what alloc method does). Then, you check if the method returned an object and initialize your own properties.

    Take a look at this guide and make sure you understand everything what is in there https://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectivec/introduction/introobjectivec.html .

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

Sidebar

Related Questions

I have a method -(void)myMethod:(MyObject*)obj And I am detaching a new thread [NSThread detachNewThreadSelector:@selector(myMethod)
I have the following code: require 'spreadsheet' class MyObject def initialize @workbook = Spreadsheet::open('foo.xls',
Let's say I have a MyObject instance which is not initialized: var a:MyObject =
I have a C++ class MyObject and I want to be able to feed
I have a List (Of MyObject) binding to a GridView in the Page_Load event.
I have a class class ObjFactory { MyObject getObject() {...} void returnObject() {...} }
I have a class class ObjPool { MyObject getObject() {...} void returnObject() {...} int
I have this function in C++: struct MyObject { } testAlgorithm(array<String^>^ algorithms, MyObject^ myObject)
Imagine I have an entity: public class MyObject { public string Name { get;
I have come across a class that has an immutable property: MyObject[] allObjs The

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.