unrecognized selector sent to instance

Discussion in 'Mac Programming' started by Boneoh, Mar 18, 2009.

  1. macrumors 6502

    Boneoh

    Joined:
    Feb 27, 2009
    Location:
    So. Cal.
    #1
    I am getting the error "unrecognized selector sent to instance" but I can't seem to figure out the cause. :confused: I am new to Objective-c, and this seems to be something basic, but I'm not getting it. Why is setNodes not being recognized?

    Thanks in advance!

    [NetBuilder setNodes:]: unrecognized selector sent to instance 0x1b3e20

    NetBuilder.h

    Code:
    #import <Cocoa/Cocoa.h>
    
    @class Network;
    @class Node;
    
    @interface NetBuilder : NSObject {
    }
    
    -(id)init;
    -(void)dealloc;
    -(IBAction)buildNetwork;
    
    @property (retain) Network * network;
    @property (retain) NSMutableDictionary * nodes;
    
    @end
    
    NetBuilder.m
    Code:
    #import "NetBuilder.h"
    #import "Node.h"
    #import "Network.h"
    #import "Path.h"
    
    // private methods
    
    @interface NetBuilder ()
    
    -(void)buildNodePaths:(Node *)node minI:(int)i1 maxI:(int)i2 minJ:(int)j1 maxJ:(int)j2 minK:(int)k1 maxK:(int)k2;
    -(int)getDeltaIndex:(int)low startIndex:(int)start maxIndex:(int)max deltaIndex:(int)delta;
    -(int)getIndex:(int)i andJ:(int)j andK:(int)k; 
    -(void)assignNodes:(int)n forZ:(int)z;
    -(int)followPaths:(Node *)node;
    
    @end
    
    // actual implementation
    
    @implementation NetBuilder
    
    @dynamic  network;
    @dynamic  nodes;
    
    - (id)init
    {
    	if ( self = [super init] )
    	{		
    		[self setNodes:[[NSMutableDictionary alloc] init] ];
    	}
    	
    	NSLog(@"NetBuilder init");
    	
    	return self;
    }
    
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Instead of @dynamic use @synthesize.

    @dynamic is used if you are going to implement the accessor methods yourself. @synthesize is used when you want the compiler to do it for you.
     
  3. thread starter macrumors 6502

    Boneoh

    Joined:
    Feb 27, 2009
    Location:
    So. Cal.
    #3
    Thanks!

    Thanks a bunch, kainjow! That fixed the issue. Now I am on to finding the real bugs in my logic.

    By the way, your profile pic is great, it reminds me of myself when I find a nasty bug. The hand on the head, "what was I thinking when I wrote THAT?" :D
     

Share This Page