• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Crash when calling custom methods in custom subclass.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Crash when calling custom methods in custom subclass.


  • Subject: Re: Crash when calling custom methods in custom subclass.
  • From: Charilaos Skiadas <email@hidden>
  • Date: Thu, 28 Jul 2005 22:14:01 -0500

On Jul 28, 2005, at 9:34 PM, Adam Raney wrote:


ACRQuizProblemRowElement.h :

#import <Cocoa/Cocoa.h>


@interface ACRQuizProblemRowElement : NSObject { NSString * format; NSString * content; NSArray * answers; // to be filled with NSStrings bool isHeader; }

- (void) setFormat: (NSString *)newFormat;
- (void) setContent: (NSString *)newContent;
- (void) setAnswers: (NSArray *)newAnswers;
- (void) setIsHeader: (bool)newIsHeader;

@end

---------

ACRQuizProblemRowElement.m

...

- (void) setFormat: (NSString *)newFormat
{
    format = [NSString stringWithString: newFormat];
}


All your accessors are wrong. Read up on setters and getters, and the correct way to write them, and also on memory management. In this particular case, stringWithString returns an autoreleased object, which will be deallocated in all likelihood soon after the method exits, and then "format" will point to garbage. Same goes for all the other methods.


I would suggest, if you haven't done so yet, going through a book on Cocoa programming, and getting the basics of Obj-C down right. My personal favorite, and a lot of people will agree on that, is Aaron Hillegass's book. It will make things immensely easier and more clear.
- (void) setContent: (NSString *)newContent
{
    content = [NSString stringWithString: newContent];
}

- (void) setAnswers: (NSArray *)newAnswers
{
    answers = [NSArray arrayWithArray: newAnswers];
}

- (void) setIsHeader: (bool)newIsHeader
{
    isHeader = newIsHeader;
}


Haris


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Crash when calling custom methods in custom subclass.
      • From: Adam Raney <email@hidden>
References: 
 >Crash when calling custom methods in custom subclass. (From: Adam Raney <email@hidden>)

  • Prev by Date: Re: Capturing mousedown in WebFrameView
  • Next by Date: [Core Data - Newbie] Custom validation method called twice.
  • Previous by thread: Crash when calling custom methods in custom subclass.
  • Next by thread: Re: Crash when calling custom methods in custom subclass.
  • Index(es):
    • Date
    • Thread