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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:45:38+00:00 2026-05-26T22:45:38+00:00

I try to understand how to work simple init funcion and I don’t know

  • 0

I try to understand how to work simple init funcion and I don’t know where I have made a mistake. Can somebody assist?

Rectangle.h

@interface Rectangle : NSObject
{
    int width;
    int height;
}
-(id)initObject;
@end

Rectangle.m

@implementation Rectangle

-(id)initObject{
    if (self = [super init]) {
        height = 5;
        width = 7;
    }
    return self;
}    

@end

And in ViewController.h i import Rectangle.h, declare *rect object and in .m i execute(? run?) initObject.

ViewController.h

#import <UIKit/UIKit.h>
#import "Rectangle.h"
@interface ViewController : UIViewController
{
    Rectangle *rect;
}
@end

ViewController.m

-(void)viewDidLoad
{
    rect = [[Rectangle alloc] initObject];
    NSLog(@"%@", rect);

    [super viewDidLoad];

}

initObject return me:

 2011-11-21 09:43:02.625 initializers[43693:f803] <Rectangle: 0x6ab1660>
  • 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-26T22:45:39+00:00Added an answer on May 26, 2026 at 10:45 pm

    The only problem with your code that I can see is you called your initializer -initObject for no good reason. It’s not taking any parameters at all, so you really should just call it -init like every other parameterless initializer in the system.

    As for the log output, I imagine your confusion lies in the fact that it says <Rectangle: 0x6ab1660>. This is perfectly normal. The default implementation of -description (the method that returns this output) is the name of the class of the object followed by the object’s address. In other words, -[NSObject description] is likely to be implemented something like the following:

    - (NSString *)description {
        return [NSString stringWithFormat:@"<%@: %p>",
                                          NSStringFromClass([self class]),
                                          self];
    }
    

    This means that instance variables of your object are not going to be printed. A number of built-in classes do print their instance variables when logged, but this was implemented specifically for that class and is not a generic mechanism. If you want to verify that your Rectangle object is correct, you could implement -description like so:

    - (NSString *)description {
        return [NSString stringWithFormat:@"<%@: %p width=%d, height=%d>",
                                          NSStringFromClass([self class]),
                                          self,
                                          width,
                                          height];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very simple test case I am using to try to understand
I can fix the below exception with a try-catch loop but I cannot understand
there is one think, i can't understand anyway:((( when i try to set cookie(it
Consider the code below. I don't understand why my GCC compiler does not try
I did a simple test to understand how transactions work in .net Sample code
I'm trying to understand how threads work, and I wrote a simple example where
I have made a simple program with : working with files(read write) end class
So lately I have been working on writing a simple compiler to better understand
I try to get duplicate address for a object but i don't understand why
I try to understand the memory management in ObjectiveC and still some things are

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.