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

  • Home
  • SEARCH
  • 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 5983081
In Process

The Archive Base Latest Questions

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

UPDATE: I realized that the initWithFrame method is never called, so I placed my

  • 0

UPDATE: I realized that the “initWithFrame” method is never called, so I placed my array’s init elsewhere. Thanks for reading. (for anyone, what’s the point of initWithFrame if it is not called?”

I’ve been staring at this code for about an hour and am probably missing a simple and obvious issue. I’m merely trying to keep an array of touched points. My UIView’s init says this:

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
self.drawn=[[NSMutableArray alloc] init ];
return self;
}

Then I have this in another method:

CGPoint point=[[touches anyObject] locationInView:self];
NSLog(@"touched point: %f, %f",point.x,point.y);
[self.drawn addObject:[NSValue valueWithCGPoint:point]];

The NSLog confirms that “point” exists and contains x and y data.

Why then does my “drawn” array never get anything? I have read the NSValue tutorials and I seem to be doing this correctly. An NSLog of [self.drawn count] always shows 0 despite that this code has triggered.

And of course “drawn” is also an ivar of my custom UIView, properly synthesized also.

  • 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-22T22:10:46+00:00Added an answer on May 22, 2026 at 10:10 pm

    Your initWithFrame: never gets called,* and drawn is never created. From the Resource Management Guide:

    In iOS, any object that conforms to the NSCoding protocol is initialized using the initWithCoder: method. This includes all subclasses of UIView[…] Custom views in iOS do not use the initWithFrame: method for initialization.

    The value at drawn is therefore nil, and calling [nil count] gives 0; [nil addObject:] similarly does nothing.

    That said, your initWithFrame: also has two memory problems. Your assignment to the property over-retains the array, and you should be doing that assignment inside the if block.

    When you create an NSMutableArray using alloc/init, you own that array. When you then assign it using a property which is defined as retaining, you have an extra claim on that object, which can eventually cause a leak.

    Second: if, for whatever reason, the call to [super initWithFrame:frame] fails, self will be invalid (nil), and using one of its properties will likewise be incorrect. That’s the purpose of if(self).
    You should do this instead:

    if(self){
        self.drawn = [NSMutableArray array];
    }
    

    This creates an autoreleased NSMutableArray which your view then properly retains.


    *I wish I knew why too. It does get used in OS X.

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

Sidebar

Related Questions

Update: i just realized that, how about dont allow any special characters instead of
UPDATE: Thanks to everyone for the responses. I didn't realize document.write() was deprecated. Add
Update: Now that it's 2016 I'd use PowerShell for this unless there's a really
Update: Thanks for the suggestions guys. After further research, I’ve reformulated the question here:
I recently realized that I add some form of row creation timestamp and possibly
I have a handler that receives a message on every location update, every 5
I would like to have a stored procedure that will update values in a
I would like to update my SQL lite database with the native update-method of
During a recent backup/restore cycle I've realized that I managed to omit the 'tmp'
While trying to use Facebook's mobile authentication, I realized that they don't set any

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.