• 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: initWithFrame fails
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: initWithFrame fails


  • Subject: Re: initWithFrame fails
  • From: N!K <email@hidden>
  • Date: Fri, 26 Dec 2014 11:54:49 -0800


On Dec 24, 2014, at 7:45 PM, Roland King <email@hidden> wrote:


On 25 Dec 2014, at 11:30, N!K <email@hidden> wrote:



Thank you all for explaining what’s going on. I looked up initWithCoder; it is not suitable for my usage. 

In what way is initWithCoder: not suitable for your usage?

See 4) below.

What is the code you had in initWithFrame: which you want called

See 2) below.

and why can you not put that code into initWithCoder:?

See 3) below.

Have you even implemented

This is a new area for me, so no, I did not know enough to try this.  initWithFrame has been working perfectly for me, based on examples in books and online. I was blindsided when it suddenly stopped and I had no idea where  or how to start debugging. I had never encountered initWithCoder.

I really appreciate all the help that’s offered today; it used to be a very hard struggle, working alone, before forums like this one became available.

a simple initWithCoder: method and checked that is the one being called during the NIB loading by the way -  before we go any further down this track. 

See 1) below.


My classes often end up looking something like this with the init code factored out into a separate method called from any of the initializers. 

-(void)My_Class_Internal_Init
{
.. init code ..
}

-(id)init
{
self = [ super init ];
if( self )
[ self My_Class_Internal_Init ];

return self;
}

-(id)initWithCoder:(NSCoder*)coder
{
self = [ super initWithCoder:coder ];

if( self )
[ self My_Class_Internal_Init ];

return self;
}

-(id)initWithFrame: … // etc etc 


 
1)  I added:

-(id)init
{
    self = [ super init ];
    if( self ){
         NSLog(@"\n\n init");   }
    return self;
}

-(id)initWithCoder:(NSCoder*)coder
{
    self = [ super initWithCoder:coder ];

    

    if( self )
     NSLog(@"\n\n initWithCoder");
    return self;
}

Only initWithCoder: is reached; NSLog outputs from there and a breakpoint stops  there.

init and initWithFrame: are not reached. No NSLog outputs. No breakpoint stops there.

—This raises  a new question: Why isn’t ’init’  reached at all?—


2) InitWithFrame: is unremarkable. For brevity, it contains:

_path = [[NSBezierPath alloc] init];
. . . generate random lines . . .
[_path closePath];
initialize a variable

I will gladly supply the whole thing if anyone wants to look at it.


3) Next I tried initWithCoder: by simple substitution, without knowing what I was doing. 

-(id)initWithCoder:(NSCoder*)coder{
        self = [ super initWithCoder:coder ];
//- (id)initWithFrame:(NSRect)frame {
//    self = [super initWithFrame:frame];

  

It worked! But this is not the way I want to program. I need to know why initWithFrame stopped working, how to use initWithCoder:  correctly, and what potential pitfalls are out there. There may be more than this one:

WANNABEGEEK:“ Identity Inspector - User Defined Runtime Attributes

In your implementation class you cannot use initWithCoder: otherwise your key-value path setting will not be picked up. You will have to do all your implementation within awakeFromNib.”

Clearly I have some studying to pursue, after this fine start you have given me.


4) Apparently initWith Coder: is suitable. It worked. But I don’t yet know why. I don’t even know what the “coder" argument refers to, or what it should be.
In looking up initWith Coder: I found it described in Stack Overflow as

The NSCoder class is used to archive/unarchive (marshal/unmarshal, serialize/deserialize) of objects.

This is a method to write objects on streams (like files, sockets) and being able to retrieve them later or in a different place.

I would suggest you to read Archiving

Since I didn’t plan to do any archiving at this point, I rejected it. Thanks for redirecting me.

Nick

 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: initWithFrame fails
      • From: Quincey Morris <email@hidden>
References: 
 >initWithFrame fails (From: N!K <email@hidden>)
 >Re: initWithFrame fails (From: Kyle Sluder <email@hidden>)
 >Re: initWithFrame fails (From: Roland King <email@hidden>)

  • Prev by Date: Re: initWithFrame fails
  • Next by Date: Re: initWithFrame fails
  • Previous by thread: Re: initWithFrame fails
  • Next by thread: Re: initWithFrame fails
  • Index(es):
    • Date
    • Thread