Re: Help with Basics (Was: help with bindings)

2010-11-21 Thread Rounak Jain
Thanks Jerry,
I have used the dictionaryWithObjectsAndKeys: method.
I have implemented your suggestions regarding convenience constructors and 
myKeys object. Regarding your comment about making everything mutable, I 
think, at the moment, it has to be that way. 
What's next?


#import Cocoa/Cocoa.h

@interface ComboscAppDelegate : NSObject NSApplicationDelegate {
IBOutlet NSComboBox *countryCombo;
NSMutableDictionary *theCountries;
NSMutableArray *myKeys;
IBOutlet NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
- (void)applicationWillFinishLaunching:(NSNotification *)notif;
@end



#import ComboscAppDelegate.h
@implementation ComboscAppDelegate

@synthesize window;
- (void)applicationWillFinishLaunching:(NSNotification *)notif {
theCountries = [NSMutableDictionary dictionaryWithObjectsAndKeys:
 [NSMutableArray 
arrayWithObjects:@AAABBB, @AABBB, @AAACCC, nil], @A,
 [NSMutableArray 
arrayWithObjects:@BBBAAA, @, @BBBCCC, nil], @B,
 [NSMutableArray 
arrayWithObjects:@CCCDDD, @CCFGGGFF, @CCCDDDFFF, nil], @C, nil];

myKeys = [NSMutableArray arrayWithObjects: [theCountries allKeys], nil];
}
@end

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Help with Basics (Was: help with bindings)

2010-11-21 Thread Ricky Sharp

On Nov 21, 2010, at 2:59 AM, Rounak Jain wrote:

 Thanks Jerry,
 I have used the dictionaryWithObjectsAndKeys: method.
 I have implemented your suggestions regarding convenience constructors and 
 myKeys object. Regarding your comment about making everything mutable, I 
 think, at the moment, it has to be that way. 
 What's next?

As Jerry pointed out, you need to learn the basics; please read up on the 
basics to include memory management.

The way you've now written things will cause your app to crash.  I'll leave the 
reason for the crash as an exercise for you to figure out.

 #import Cocoa/Cocoa.h
 
 @interface ComboscAppDelegate : NSObject NSApplicationDelegate {
   IBOutlet NSComboBox *countryCombo;
 NSMutableDictionary *theCountries;
   NSMutableArray *myKeys;
   IBOutlet NSWindow *window;
 }
 @property (assign) IBOutlet NSWindow *window;
 - (void)applicationWillFinishLaunching:(NSNotification *)notif;
 @end
 
 
 
 #import ComboscAppDelegate.h
 @implementation ComboscAppDelegate
 
 @synthesize window;
 - (void)applicationWillFinishLaunching:(NSNotification *)notif {
theCountries = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[NSMutableArray 
 arrayWithObjects:@AAABBB, @AABBB, @AAACCC, nil], @A,
[NSMutableArray 
 arrayWithObjects:@BBBAAA, @, @BBBCCC, nil], @B,
[NSMutableArray 
 arrayWithObjects:@CCCDDD, @CCFGGGFF, @CCCDDDFFF, nil], @C, nil];
 
   myKeys = [NSMutableArray arrayWithObjects: [theCountries allKeys], nil];
 }
 @end

___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.com



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: Help with Basics (Was: help with bindings)

2010-11-20 Thread Jerry Krinock

On 2010 Nov 20, at 20:00, Rounak Jain wrote:

 Please tell me the binding connections … I tried using NSArrayController but 
 could not get it right. Please guide me. 

Rounak, there are too many things wrong in your code.  The guidance I offer is 
that you need to set your project aside, study some of the basic Cocoa 
tutorials and documentation, and then after some days or weeks, depending on 
your prior experience, you will be ready to start using bindings.

 (Also, is there a way to reduce the four theCountries setValue: statements to 
 one?)

Since you asked, we'll start there.  Yes.  Use -[NSMutableDictionary 
dictionaryWithObjectsAndKeys:].

Next, it looks rather strange to be making all these collections mutable.  Now, 
it may be correct in your case, but it looks very weird, and more likely is the 
common beginner's mistake of making everything mutable.  Yes, it's convenient 
to be able to mutate away whenever you feel like it.  But it will lead to bugs 
when you start mutating the same object in different methods without copying it.

Another weird thing is your using alloc] init] instead of the so-called 
convenience constructors.  Unless you're using garbage collection, these are 
memory leaks, and even if you are using garbage collection (which I never 
have), I think it's more conventional to use the convenience constructors.

Finally, in these last two lines

 myKeys = [[NSArray alloc]init];
 myKeys = [theCountries allKeys];

The first line has no effect (other than to leak memory if you're not using 
garbage collection).  The object that you've alloc] init]ed is a different 
object than the one returned by -allKeys.

Study some of the basics so that you know all of the terms I used in this 
message.  Post your improved code next week, and *then* someone could help you 
with bindings or whatever.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com