• 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: Does retain not work on ids?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Does retain not work on ids?


  • Subject: Re: Does retain not work on ids?
  • From: Ken Tozier <email@hidden>
  • Date: Mon, 23 May 2005 22:27:22 -0400

Here's the code pared down to the bare essentials:


Struct definition:

typedef struct UIObjectProperties
{
    id                    data;

    /* lots of scalar fields here */
}UIObjectProperties;

NSDictionary category:
(convenience methods for extracting specific fields from a dictionary)

- (id) data
{
    return [self objectForKey: @"data"];
}


Convenience function for extracting all relevant properties for a particular UI object (ie: views, checkboxes, text fields tec...) from a predefined dictionary:


UIObjectProperties UIObjectPropertiesFromDescription(NSView *inSuperView, NSDictionary *inDescription)
{
UIObjectProperties result = {};


    // get retainable properties
    result.data                = [inDescription data];

    /* additional getter methods here */

    return result;
}

Class factory method:

+ (id) objectWithDescription:(NSDictionary *) inDescription
            superview:(id) inSuperview
{
    return [[[UILayoutView alloc]
                initLayoutViewWithDescription: inDescription
                superview: inSuperview]
                autorelease];
}


Instance initialization:

- (id) initLayoutViewWithDescription:(NSDictionary *) inDescription
superview:(id) inSuperview
{
// extract properties from dictionary using convenience method
UIObjectProperties tempProps = UIObjectPropertiesFromDescription(inSuperview, inDescription);


// generate a frame from tempProps using class method
NSRect tempFrame = [UILayoutView frameWithProperties: tempProps
superview: inSuperview];


    // init the object
    self = [super initWithFrame: tempFrame];
    if (self == nil)
    return nil;

// tried just leaving it like this (ie: no retain on properties.data)
properties = tempProps;


    // tried retaining like this
    properties.data            = [tempProps.data retain];

    // this
    [properties.data retain];

// and this (bypassing the NSDictionary catagory method)
properties.data = [[inDescription objectForKey: @"data"] retain];



// NSLogs here indicate properties.data exists and is valid.

    subviewsInitialized        = NO;

    return self;
}


- (void) drawRect:(NSRect) inRect { // by the time it gets to here, properties data = nil // NSLogs in dealloc don't show up in run log

    NSLog(@"properties.data: %@", [properties.data description]);
}



_______________________________________________
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: Does retain not work on ids?
      • From: Pandaa <email@hidden>
    • Re: Does retain not work on ids?
      • From: Andy Lee <email@hidden>
References: 
 >Does retain not work on ids? (From: Ken Tozier <email@hidden>)
 >Re: Does retain not work on ids? (From: Pandaa <email@hidden>)

  • Prev by Date: Re: Text Formatting (NSAttributedString?)
  • Next by Date: Re: Does retain not work on ids?
  • Previous by thread: Re: Does retain not work on ids?
  • Next by thread: Re: Does retain not work on ids?
  • Index(es):
    • Date
    • Thread