textfield not updating with bindings - Whats wrong?

2008-08-23 Thread Kieren Eaton

Hi all

I have given up on doing anymore work on my current project until i  
get this sorted


ok simply i have an interface with 2 textfields, one for a number and  
one for a string.
Also there is a button which tells the controller to tell my class to  
update the model vars.


I am using Obj-C 2.0 and properties and from all i have read  
properties are fully KVO complient.


here is my app delegate.

#import Cocoa/Cocoa.h
@class someclass;
@interface bindingstestDelegate : NSObject{
someclass *fooClass;
}
- (IBAction)changeValues:(id)sender;
@end

#import someclass.h
@implementation bindingstestDelegate
- (id) init{
self = [super init];
if (self != nil) {
fooClass = [[someclass alloc] init];
}
return self;
}

- (IBAction)changeValues:(id)sender{
[fooClass updateValues];
}
@end

and the model class

@interface someclass : NSObject {
NSString *someString;
NSInteger someNumber;
}
@property (readwrite,retain) NSString *someString;
@property (readwrite) NSInteger someNumber;
- (void)updateValues;
@end
-
#import someclass.h
@implementation someclass
@synthesize someString, someNumber;
- (id) init{
self = [super init];
if (self != nil) {
self.someString = @ fred rocks;
self.someNumber = 6969;
}
return self;
}
- (void)updateValues
{
self.someString = [someString stringByAppendingString:@ YEP];
self.someNumber = self.someNumber + 5;
NSLog(@\n%d - %@,someNumber,someString);
}
@end

Right so in IB I have an object which is of class someClass and an  
object controller which has the content outlet set to the someclass  
object and the keys someString,someNumber.


The button calls the changeValues method in the delegate

The 2 textfields are bound to the controller with selection.someString  
and selection.someNumber respectively.
upon application start the text fields are set with their respective  
values as per the init of the model. which shows that the bindings are  
working.


BUT pressing the button yields no change from the textfields.  The  
nslog shows the model values are changing but this is not propogated  
to the UI.

Whats going on?
According to the Apple docs on troubleshooting bindings The model  
class has automatic key-value observing enabled or implements manual  
key-value observing for the property.  its obviously not manual so huh?


Help and clarification or discussion much appreciated.

Kieren

Olearia - Talking Books on the Mac
http://olearia.googlecode.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 [EMAIL PROTECTED]


Re: textfield not updating with bindings - Whats wrong?

2008-08-23 Thread Markus Spoettl

On Aug 23, 2008, at 12:41 AM, Kieren Eaton wrote:
Right so in IB I have an object which is of class someClass and an  
object controller which has the content outlet set to the  
someclass object and the keys someString,someNumber.


The button calls the changeValues method in the delegate

The 2 textfields are bound to the controller with  
selection.someString and selection.someNumber respectively.
upon application start the text fields are set with their respective  
values as per the init of the model. which shows that the bindings  
are working.


BUT pressing the button yields no change from the textfields.  The  
nslog shows the model values are changing but this is not propogated  
to the UI.

Whats going on?
According to the Apple docs on troubleshooting bindings The model  
class has automatic key-value observing enabled or implements manual  
key-value observing for the property.  its obviously not manual so  
huh?


Help and clarification or discussion much appreciated.



One thing that I can think of is that you're not changing the fooClass/ 
someclass instance you think your controls are bound to. That would  
explain the log being correct while the UI does not update.


How do you create the delegate and how do you create the fooClass/ 
someclass instance your object controller is bound to?


Regards
Markus
--
__
Markus Spoettl



smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Re: NSMenuItem - setHidden

2008-08-23 Thread Stuart Green
So I could use this method to enable/disable the menu item rather than  
hide it? That may look a bit more pleasing to the user.


Will give it a go.

Thanks.

Regards,

Stuart

Sent from my iPhone

On 23 Aug 2008, at 02:53, Jonathan Hess [EMAIL PROTECTED] wrote:



On Aug 22, 2008, at 6:15 PM, Graham Cox wrote:



On 23 Aug 2008, at 5:30 am, chaitanya pandit wrote:


   [itemToBeHidden setAutoEnablesItems:NO];
Don't call setAutoEnblesItems on the item you want to hide  
(NSMenuItem) call it on the menu to which the item belongs (or is  
gonna get added- NSMenu class)





-setAutoEnablesItems: doesn't affect visible/hidden, it affects  
checked/unchecked. So it's unlikely to bear on this problem.


I think you meant enabled/disabled, instead of checked/unchecked.

Jon Hess




hth,

Graham
___

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/jhess%40apple.com

This email sent to [EMAIL PROTECTED]


___

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/stuart%40sjgdigital.com

This email sent to [EMAIL PROTECTED]


___

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 [EMAIL PROTECTED]


Re: UTI Example

2008-08-23 Thread Jonathan Dann

Reposted due to 25KB size limit. Sorry.

On 23 Aug 2008, at 06:42, Adam Thorsen wrote:
Are there any examples of using the UTI API to determine the UTI  
given a path to a file?


Thanks,
-Adam


In my app I have a singleton UTI controller class that has an NSArray  
property of UTIs supported by my application.  There's also a  
dictionary that maps the Core Data entities that I use to represent  
each file type at runtime.  Here are the methods of my UTI controller,  
hope they help. I've replaced most of the string constants with  
external declarations already but a couple are still constant  
strings.  They show how to use -[NSWorkspace type:conformsToType:] and  
-[NSWorkspace typeOfFile:error:]


As for your info.plist file, and exported and imported declarations,  
there's a good article here:


http://developer.apple.com/documentation/Carbon/Conceptual/understanding_utis/understand_utis_conc/chapter_2_section_4.html

- (id)init;
{
if (![super init])
return nil;
	self.supportedUTIs = [NSArray arrayWithObjects:(NSString  
*)kUTTypePlainText 
,kUTTypeTex,kUTTypeTeXShopTex,kUTTypeBib,kUTTypeBibDeskBib,(NSString  
*)kUTTypePDF,(NSString *)kUTTypeImage,kUTTypeEPS,nil];
	self.utiEntityNameMap = [NSDictionary dictionaryWithObjects:[NSArray  
arrayWithObjects:ESTexFileEntityName 
,ESTexFileEntityName 
,ESTexFileEntityName 
,@BibTexFile 
,@BibTexFile 
,ESPDFFileEntityName,ESImageFileEntityName,@EPSFile,nil]  
forKeys:self.supportedUTIs];

return self;
}

- (NSString *)isSupportedUTI:(NSString *)uti error:(NSError  
**)errorPointer;

{
for (NSString *supportedUTI in self.supportedUTIs)
		if ([[NSWorkspace sharedWorkspace] type:uti  
conformsToType:supportedUTI])

return supportedUTI;
if (errorPointer != NULL)
		*errorPointer = [NSError errorWithDomain:ESScribblerErrorDomain  
code:ESUnsupportedUTIErrorCode userInfo:[NSDictionary  
dictionaryWithObjectsAndKeys:NSLocalizedString 
(@,@),NSLocalizedDescriptionKey 
,NSLocalizedString 
(@,@),NSLocalizedRecoverySuggestionErrorKey 
,uti,ESUnsupportedUTIErrorKey,nil]];

return nil;
}

- (NSString *)isSupportedFile:(NSString *)filepath error:(NSError  
**)errorPointer;

{
	NSString *uti = [[NSWorkspace sharedWorkspace] typeOfFile:filepath  
error:errorPointer];

if (!uti)
return nil;
return [self isSupportedUTI:uti error:errorPointer];
}

- (NSString *)entityNameForFile:(NSString *)filepath error:(NSError  
**)errorPointer;

{
	NSString *supportedUTI = [self isSupportedFile:filepath  
error:errorPointer];

if (!supportedUTI)
return nil;
	return [self.utiEntityNameMap valueForKey:supportedUTI]; // leave  
this error as nil, if we've got this far then we can determine the UTI

}

/*
 Maps the UTIs for the files and create a dictionary of entity name  
values and filepath keys. All errros are put into an NSDictionary. It  
is guaranteed to return a dictionary, so clients must inspect both the  
errors dictionary and the count of the returned dictionary.
 This method can't reasonably return nil as the presence of errors  
does not preclude the presence of supported files. To return nil if  
there are errors is too simplistic.

 */
- (NSDictionary *)entityMapForFiles:(NSArray *)filepaths errors: 
(NSDictionary **)dictionaryPtr;

{   
	NSMutableDictionary *mutableErrorsDictionary = [NSMutableDictionary  
dictionary];
	NSMutableDictionary *mutableEntityMap = [NSMutableDictionary  
dictionary];

for (NSString *filepath in filepaths) {
NSError *entityError = nil;
		NSString *entityName = [self entityNameForFile:filepath  
error:entityError];

if (!entityName)
[mutableErrorsDictionary setObject:entityError 
forKey:filepath];
else
[mutableEntityMap setObject:entityName forKey:filepath];
}

if ([mutableErrorsDictionary count] != 0  dictionaryPtr != NULL)
*dictionaryPtr = [[mutableErrorsDictionary copy] autorelease];
return [[mutableEntityMap copy] autorelease];
}

Jonathan

http://espresso-served-here.com

smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Implementing isEqual: and hash

2008-08-23 Thread Graham Cox
I have a class for which equality can be defined as having the same  
internal string value (which happens to be a UUID-turned-string). I  
can easily implement isEqual: based on that but the docs say I also  
need to implement -hash. Any pointers on what is a good way to do  
that? Could I just safely defer to the -hash returned by the string in  
question?


tia,

Graham


___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Phil
On Sat, Aug 23, 2008 at 11:41 PM, Graham Cox [EMAIL PROTECTED] wrote:
 I have a class for which equality can be defined as having the same internal
 string value (which happens to be a UUID-turned-string). I can easily
 implement isEqual: based on that but the docs say I also need to implement
 -hash. Any pointers on what is a good way to do that? Could I just safely
 defer to the -hash returned by the string in question?


If you're deferring both -isEqual: and -hash to an NSString, you'll be
fine. Hash doesn't need to be anything complicated (although a good
distribution is nice), just as long as two objects that return YES for
-isEqual: return the same value for -hash (the inverse doesn't have to
be true).

Phil
___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Michael Ash
On Sat, Aug 23, 2008 at 7:41 AM, Graham Cox [EMAIL PROTECTED] wrote:
 I have a class for which equality can be defined as having the same internal
 string value (which happens to be a UUID-turned-string). I can easily
 implement isEqual: based on that but the docs say I also need to implement
 -hash. Any pointers on what is a good way to do that? Could I just safely
 defer to the -hash returned by the string in question?

The implementation of -hash should *always* match the implementation
of -isEqual:.

If you compare primitives in -isEqual:, you should combine them (using
xor or the like) in -hash. If you compare objects by calling -isEqual:
on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all. If you compare only one thing
for equality, return it (if it's a primitive) or its hash value (if
you call isEqual: on it).

Mike
___

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 [EMAIL PROTECTED]


Re: textfield not updating with bindings - Whats wrong?

2008-08-23 Thread Kieren Eaton

Right so in IB I have an object which is of class someClass and an
object controller which has the content outlet set to the
someclass object and the keys someString,someNumber.

The button calls the changeValues method in the delegate

The 2 textfields are bound to the controller with
selection.someString and selection.someNumber respectively.
upon application start the text fields are set with their respective
values as per the init of the model. which shows that the bindings
are working.

BUT pressing the button yields no change from the textfields.  The
nslog shows the model values are changing but this is not propogated
to the UI.
Whats going on?
According to the Apple docs on troubleshooting bindings The model
class has automatic key-value observing enabled or implements manual
key-value observing for the property.  its obviously not manual so
huh?

Help and clarification or discussion much appreciated.



One thing that I can think of is that you're not changing the fooClass/
someclass instance you think your controls are bound to. That would
explain the log being correct while the UI does not update.

How do you create the delegate and how do you create the fooClass/
someclass instance your object controller is bound to?

Regards
Markus
--

Thanks Markus

ok the delegate is set as an object in IB it is the delegate of Files  
owner and nsapplication (thats correct isnt it?) it has a class of  
bindtestdelegate which is where the button action is located.
The button calls the changeValues method in the delegate class which  
then calls the updateValues in the fooClass instance

of the someclass.

should my filesOwner in IB (Currently it is NSApplication) be  
something different?


the instance of someClass is just dragged straight out of the IB lib  
as a simple object and assigned the class someClass
I dont actually have a nsobjectcontroller subclass .h/.m  in my  
project but according to the apple docs I dont need one?


Some things are harder than others.

I can email you the entire project if you like if thats easier  for  
your perusal.  I would REALLY like to understand what I am not doing  
right?


Thanks

Kieren


___

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 [EMAIL PROTECTED]


Re: textfield not updating with bindings - Whats wrong?

2008-08-23 Thread Kieren Eaton

Right so in IB I have an object which is of class someClass and an
object controller which has the content outlet set to the
someclass object and the keys someString,someNumber.

The button calls the changeValues method in the delegate

The 2 textfields are bound to the controller with
selection.someString and selection.someNumber respectively.
upon application start the text fields are set with their respective
values as per the init of the model. which shows that the bindings
are working.

BUT pressing the button yields no change from the textfields.  The
nslog shows the model values are changing but this is not propogated
to the UI.
Whats going on?
According to the Apple docs on troubleshooting bindings The model
class has automatic key-value observing enabled or implements manual
key-value observing for the property.  its obviously not manual so
huh?

Help and clarification or discussion much appreciated.



One thing that I can think of is that you're not changing the fooClass/
someclass instance you think your controls are bound to. That would
explain the log being correct while the UI does not update.

How do you create the delegate and how do you create the fooClass/
someclass instance your object controller is bound to?

Regards
Markus
--

Thanks Markus

ok the delegate is set as an object in IB it is the delegate of Files  
owner and nsapplication (thats correct isnt it?) it has a class of  
bindtestdelegate which is where the button action is located.
The button calls the changeValues method in the delegate class which  
then calls the updateValues in the fooClass instance

of the someclass.

should my filesOwner in IB (Currently it is NSApplication) be  
something different?


the instance of someClass is just dragged straight out of the IB lib  
as a simple object and assigned the class someClass
I dont actually have a nsobjectcontroller subclass .h/.m  in my  
project but according to the apple docs I dont need one?


Some things are harder than others.

I can email you the entire project if you like if thats easier  for  
your perusal.  I would REALLY like to understand what I am not doing  
right?


Thanks

Kieren


___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Graham Cox


On 23 Aug 2008, at 10:13 pm, Michael Ash wrote:

On Sat, Aug 23, 2008 at 7:41 AM, Graham Cox [EMAIL PROTECTED]  
wrote:
I have a class for which equality can be defined as having the same  
internal

string value (which happens to be a UUID-turned-string). I can easily
implement isEqual: based on that but the docs say I also need to  
implement
-hash. Any pointers on what is a good way to do that? Could I just  
safely

defer to the -hash returned by the string in question?


The implementation of -hash should *always* match the implementation
of -isEqual:.

If you compare primitives in -isEqual:, you should combine them (using
xor or the like) in -hash. If you compare objects by calling -isEqual:
on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all. If you compare only one thing
for equality, return it (if it's a primitive) or its hash value (if
you call isEqual: on it).




Thanks guys - works fine.


cheers, Graham
___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Jean-Daniel Dupas


Le 23 août 08 à 13:41, Graham Cox a écrit :

I have a class for which equality can be defined as having the same  
internal string value (which happens to be a UUID-turned-string). I  
can easily implement isEqual: based on that but the docs say I also  
need to implement -hash. Any pointers on what is a good way to do  
that? Could I just safely defer to the -hash returned by the string  
in question?




Yes, that the way to do it.

To understand what an hash is and how it is used, I suggest you read  
the hash table article in wikipedia.


http://en.wikipedia.org/wiki/Hash_table

Hash tables are used in Cocoa in NSDictionary, NSSet, NSHashTable,  
NSHashMap and maybe more. When you understand how it works, choosing  
the implementation should be obvious.




___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Graham Cox


On 23 Aug 2008, at 9:52 pm, Jean-Daniel Dupas wrote:



Le 23 août 08 à 13:41, Graham Cox a écrit :

I have a class for which equality can be defined as having the same  
internal string value (which happens to be a UUID-turned-string). I  
can easily implement isEqual: based on that but the docs say I also  
need to implement -hash. Any pointers on what is a good way to do  
that? Could I just safely defer to the -hash returned by the string  
in question?




Yes, that the way to do it.

To understand what an hash is and how it is used, I suggest you read  
the hash table article in wikipedia.


http://en.wikipedia.org/wiki/Hash_table

Hash tables are used in Cocoa in NSDictionary, NSSet, NSHashTable,  
NSHashMap and maybe more. When you understand how it works, choosing  
the implementation should be obvious.



Thanks for that. I'm pretty familiar with hash tables in general (and  
in quite a bit of theory too) but I wasn't able to find out what Cocoa  
uses for its hashing function or how good this needed to be to work  
well with the built-in classes. However, by deferring to the string I  
can avoid the issue altogether.


For curiosity's sake, I would be interested to know what sort of  
hashing functions Cocoa does use. I haven't come across the need to  
generate one for any of my custom classes before so it's not something  
I need right now, but every bit of knowledge is worth having.


For example, here's a very crude hash function I used in a very simple  
symbol table implementation from a long while ago. I imagine most hash  
functions in Cocoa would be more sophisticated.


unsigned long   ZHashTable::Hash( const char* name )
{
register unsigned long  h = 1;
register char*  p = (char*) name;
register char   c;

while(( c = *p++ ) != 0 )
h *= (unsigned long) c;

return h % kHashTableSize;
}



cheers, Graham___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Jean-Daniel Dupas


Le 23 août 08 à 15:39, Graham Cox a écrit :



On 23 Aug 2008, at 9:52 pm, Jean-Daniel Dupas wrote:



Le 23 août 08 à 13:41, Graham Cox a écrit :

I have a class for which equality can be defined as having the  
same internal string value (which happens to be a UUID-turned- 
string). I can easily implement isEqual: based on that but the  
docs say I also need to implement -hash. Any pointers on what is a  
good way to do that? Could I just safely defer to the -hash  
returned by the string in question?




Yes, that the way to do it.

To understand what an hash is and how it is used, I suggest you  
read the hash table article in wikipedia.


http://en.wikipedia.org/wiki/Hash_table

Hash tables are used in Cocoa in NSDictionary, NSSet, NSHashTable,  
NSHashMap and maybe more. When you understand how it works,  
choosing the implementation should be obvious.



Thanks for that. I'm pretty familiar with hash tables in general  
(and in quite a bit of theory too) but I wasn't able to find out  
what Cocoa uses for its hashing function or how good this needed  
to be to work well with the built-in classes. However, by deferring  
to the string I can avoid the issue altogether.


For curiosity's sake, I would be interested to know what sort of  
hashing functions Cocoa does use. I haven't come across the need to  
generate one for any of my custom classes before so it's not  
something I need right now, but every bit of knowledge is worth  
having.


For example, here's a very crude hash function I used in a very  
simple symbol table implementation from a long while ago. I imagine  
most hash functions in Cocoa would be more sophisticated.


unsigned long   ZHashTable::Hash( const char* name )
{
register unsigned long  h = 1;
register char*  p = (char*) name;
register char   c;

while(( c = *p++ ) != 0 )
h *= (unsigned long) c;

return h % kHashTableSize;
}


Look into the CoreFoundation sources. as Cocoa primitive are tool free  
bridged, they use the same hash functions. They is even a special case  
for NSString into the CFString.c file.


http://www.opensource.apple.com/darwinsource/10.5.4/CF-476.14/

You can find Integer and double hash function into ForFoundationOnly.h.
And there is another generic hash function into CFData.c

According to the Leopard release notes, we can guess that thoses  
function have been updated into Leopard:


Order of values in hashing-based collections

The CoreFoundation and Foundation framework-provided implementations  
of hashing-based collections such as dictionaries have changed how  
they store elements, so elements may be retrieved in a different order  
than in previous releases. The order of elements in hashing-based  
collections is undefined and can change at any time, so developers  
must never rely on the order that elements are enumerated, or returned  
from a function like CFDictionaryGetKeysAndValues(). This is true even  
for cases where a developer may be trying to manipulate the hash codes  
of the objects in order to achieve some particular ordering.






___

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 [EMAIL PROTECTED]


Re: Incorrect instance of custom view loading after unarchiving

2008-08-23 Thread Sam Krishna

Hi all,

Thanks to Quincey's note and some back-referencing to one of the  
earlier RaiseMan projects, I was finally able to solve this.


(as usual) The solution actually  was simpler than I thought. I had to  
*effectively* override these two methods:


- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError;
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error: 
(NSError **)outError;


I was doing *too much work* by making MyDocument conform to NSCoding.  
These two methods were doing the equivalent work of NSCoding for me. I  
just had to create a cleaner object model separation by only  
archiving my NSMutableArray to store my NSBezierPaths.


This was a GINORMOUS breakthrough for me! I'd been afraid of doing  
graphical programming in Cocoa *FOREVER* (almost 10 years). Now I see  
how easy it is, esp. w/ all the new stuff in Leopard, and it's amazing.


Thank you all!

Live Playfully,

Sam

On Aug 23, 2008, at 12:12 AM, Quincey Morris wrote:


On Aug 22, 2008, at 20:45, Sam Krishna wrote:

OK, I've read all the email from the past month about Aaron's  
challenge in Ch. 18 of Cocoa Programming. I've got a custom view  
(OvalView) where the magic happens. I've got Undo working, but I  
can't get the app to load a saved document b/c it keeps loading the  
wrong instance of OvalView on unarchiving.


[snip]

Here's my Q: What do I need to do to fix it? Is there some simple  
IB3 gestalt that I'm missing? Some NSCoding voodoo that's  
completely obvious? what gives?


Well, if it was completely obvious, you wouldn't have missed it. ;)

What you're doing wrong is archiving your view (something that  
*draws* an oval). What you really need to do is archive your data  
model (something that *describes* an oval). That means you should  
keep the oval description separate from the view, and let the view  
refer to the separate description for the parameters it needs to  
draw the oval.


Write on the blackboard 100 times:

MVC
MVC
MVC
...

___

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/infinity%40mac.com

This email sent to [EMAIL PROTECTED]


___

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 [EMAIL PROTECTED]


Re: Two questions about CoreData migration

2008-08-23 Thread Timothy Larkin

On Aug 22, 2008, at 12:14, Timothy Larkin wrote:

The first question is a simple one. After migration, the old  
persistent store is renamed sourceURL~.xml, and the document is  
supposed to open with a new persistent store with the old url,  
sourceURL.xml,. However, the document window that appears after  
migration has the title sourceURL~.xml, and saving this replaces  
the original, unmigrated document. Why doesn't the document open  
with sourceURL? I have examined the document at various stages  
during the open document process, and it consistently reports the  
URL without the tilde. And that is how the window initially  
appears. However, it switches to the form with the tilde as soon as  
the window is activated.




I went so far as to subclass NSDocumentController, overriding  
openDocumentWithContentsOfURL:absoluteURL display:error:. I tried many  
ideas, including closing the document and having NSRunLoop send a  
message to reopen the document after openDocument had returned. Even  
with this desperate approach, the document opened as sourceURL~.xml,  
which was very perplexing.


The resolution is quite strange. I had been setting a break point in  
the over-ride function, so that I could examine the state of the  
document after I called super openDocument. I discovered, quite by  
accident, that if I removed the breakpoint, the document opened as  
sourceURL, as expected. With the break point: sourceURL~.xml; without  
the break point: sourceURL.xml. This makes absolutely no sense to me,  
but it is certainly the case.


--
Timothy Larkin
Abstract Tools
Caroline, NY



PGP.sig
Description: This is a digitally signed message part
___

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 [EMAIL PROTECTED]

Re: Implementing isEqual: and hash

2008-08-23 Thread Jim Correia

On Aug 23, 2008, at 7:41 AM, Graham Cox wrote:

I have a class for which equality can be defined as having the same  
internal string value (which happens to be a UUID-turned-string). I  
can easily implement isEqual: based on that but the docs say I also  
need to implement -hash. Any pointers on what is a good way to do  
that? Could I just safely defer to the -hash returned by the string  
in question?


Graham,

Is your object mutable? (That is, is any attribute of the attribute  
which affects equality or hash mutable? In this case that sounds like  
the internal string value which is a UUID.)


If so, that opens up another can of worms to consider.

Jim

___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Jeff Johnson

On Aug 23, 2008, at 8:57 AM, Jean-Daniel Dupas wrote:

Look into the CoreFoundation sources. as Cocoa primitive are tool  
free bridged, they use the same hash functions. They is even a  
special case for NSString into the CFString.c file.


http://www.opensource.apple.com/darwinsource/10.5.4/CF-476.14/



Those are not the sources for CoreFoundation. Those are the sources  
for 'CFLite', which is a dumbed-down version of CoreFoundation used  
by IOKit. The real CoreFoundation is not open source. There is no  
guarantee that CFLite and CoreFoundation are the same. In fact, there  
are known differences.


-Jeff

___

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 [EMAIL PROTECTED]


NSApplication _doOpenUntitled raises exception under Leopard, not Tiger

2008-08-23 Thread Todd Blanchard
I have a document based app that does the right thing under Tiger.   
Works great.


Under Leopard, NSApplication _doOpenUntitled is raising [NSCFArray  
objectAtIndex:]: index (0) beyond bounds (0)


during the application opening sequence.  There isn't a single routine  
that is mine on the stack.  So what array is _doOpenUntitled trying to  
iterate on Leopard that it didn't on Tiger?


More clues:

I have a custom DocumentController that overrides newDocument: as

- (IBAction)newDocument:(id)sender
{
[self closeAllDocumentsWithDelegate:self  
didCloseAllSelector 
:@selector(documentController:didCloseAll:contextInfo:) contextInfo:0];

[super newDocument: sender];
}

because I only support one document open at a time.  Oddly enough, if  
I ignore the exception, this gets called twice during the opening  
sequence on Leopard.


Anybody know what changed about the opening sequence or why this  
should stop working on Leopard?


-Todd Blanchard



















___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Adam R. Maxwell


On Aug 23, 2008, at 5:13 AM, Michael Ash wrote:

On Sat, Aug 23, 2008 at 7:41 AM, Graham Cox [EMAIL PROTECTED]  
wrote:
I have a class for which equality can be defined as having the same  
internal

string value (which happens to be a UUID-turned-string). I can easily
implement isEqual: based on that but the docs say I also need to  
implement
-hash. Any pointers on what is a good way to do that? Could I just  
safely

defer to the -hash returned by the string in question?


The implementation of -hash should *always* match the implementation
of -isEqual:.


And as Jim alluded, -hash must not depend on mutable properties; if  
the hash changes while the object is in a hashing collection, you'll  
end up with random crashes.



If you compare primitives in -isEqual:, you should combine them (using
xor or the like) in -hash. If you compare objects by calling -isEqual:
on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all.


What's the motivation for combining hashes in this case?  I've  
wondered what is the best thing to do when isEqual: is based on  
comparing multiple ivars; I typically just use one of them for the hash.


thanks,
Adam

smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Re: Two questions about CoreData migration

2008-08-23 Thread Quincey Morris

On Aug 23, 2008, at 08:00, Timothy Larkin wrote:

I went so far as to subclass NSDocumentController, overriding  
openDocumentWithContentsOfURL:absoluteURL display:error:. I tried  
many ideas, including closing the document and having NSRunLoop send  
a message to reopen the document after openDocument had returned.  
Even with this desperate approach, the document opened as  
sourceURL~.xml, which was very perplexing.


The resolution is quite strange. I had been setting a break point in  
the over-ride function, so that I could examine the state of the  
document after I called super openDocument. I discovered, quite by  
accident, that if I removed the breakpoint, the document opened as  
sourceURL, as expected. With the break point: sourceURL~.xml;  
without the break point: sourceURL.xml. This makes absolutely no  
sense to me, but it is certainly the case.




If you can demonstrate this in a simple project, it would be a good  
candidate for a bug report to Apple. You actually have 3 things to  
report:


1. The above problem.

2. Your original problem, where the wrong file gets opened.

3. A documentation problem, where migration in a NSPersistentDocument  
context apparently requires some extra code that isn't documented.



___

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 [EMAIL PROTECTED]


Re: textfield not updating with bindings - Whats wrong?

2008-08-23 Thread Markus Spoettl

On Aug 23, 2008, at 5:16 AM, Kieren Eaton wrote:
ok the delegate is set as an object in IB it is the delegate of  
Files owner and nsapplication (thats correct isnt it?) it has a  
class of bindtestdelegate which is where the button action is located.
The button calls the changeValues method in the delegate class which  
then calls the updateValues in the fooClass instance

of the someclass.

should my filesOwner in IB (Currently it is NSApplication) be  
something different?


Well, that depends, in most cases it's good to have a  
NSWindowController or NSViewController as file owner since those take  
care of memory management of the nib file. But I believe it's  
irrelevant to the problem at hand.


the instance of someClass is just dragged straight out of the IB lib  
as a simple object and assigned the class someClass
I dont actually have a nsobjectcontroller subclass .h/.m  in my  
project but according to the apple docs I dont need one?


No, you don't, you just mentioned you used one.

As far as I can tell from your explanation, you have 1  
bindingstestDelegate object (the file's owner) and one extra someClass  
object. The problem is that your delegate class creates its own  
someClass instance and when you press the button that instance get  
changed, not the other instance you created in the nib file.


I would change the code so that the bindingstestDelegate class exposes  
a readonly property named fooClass. You then remove the extra  
someClass object from your nib and bind the NSTextFields to the file's  
owner fooClass.someString and fooClass.someNumber keys.


I would also suggest you change the naming slightly, using uppercase  
first characters for class names. This makes it easier to distinguish  
classes from instances, methods and properties. More details here:


http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_12.html#/ 
/apple_ref/doc/uid/TP30001163-CH3-TPXREF108


Markus
--
__
Markus Spoettl



smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Re: NSApplication _doOpenUntitled raises exception under Leopard, not Tiger

2008-08-23 Thread Bill Bumgarner

On Aug 23, 2008, at 9:26 AM, Todd Blanchard wrote:

- (IBAction)newDocument:(id)sender
{
   [self closeAllDocumentsWithDelegate:self  
didCloseAllSelector 
:@selector(documentController:didCloseAll:contextInfo:) contextInfo: 
0];

   [super newDocument: sender];
}

because I only support one document open at a time.  Oddly enough,  
if I ignore the exception, this gets called twice during the opening  
sequence on Leopard.


Anybody know what changed about the opening sequence or why this  
should stop working on Leopard?


No idea, but it seems really odd to be closing all other documents  
when a new document is being opened.


It sounds like what might be happening is:

- app launches
- app requests untitled document
- untitled document is opened
- newDocument: is invoked
- newDocument: closes the freshly opened untitled document
- something a-splodes in super's newDocument: because it was doing  
something funky w/the untitled document


Do you need an untitled document? If not, kill it.

Otherwise, I'd need more context to understand the issue.

- what is the backtrace when the exception is tossed?

- what are the backtraces when -newDocument: is invoked twice?

... etc ...

b.bum



smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Re: Implementing isEqual: and hash

2008-08-23 Thread Jeff Johnson

On Aug 23, 2008, at 11:38 AM, Adam R. Maxwell wrote:


On Aug 23, 2008, at 5:13 AM, Michael Ash wrote:

On Sat, Aug 23, 2008 at 7:41 AM, Graham Cox  
[EMAIL PROTECTED] wrote:
I have a class for which equality can be defined as having the  
same internal
string value (which happens to be a UUID-turned-string). I can  
easily
implement isEqual: based on that but the docs say I also need to  
implement
-hash. Any pointers on what is a good way to do that? Could I  
just safely

defer to the -hash returned by the string in question?


The implementation of -hash should *always* match the implementation
of -isEqual:.


And as Jim alluded, -hash must not depend on mutable properties; if  
the hash changes while the object is in a hashing collection,  
you'll end up with random crashes.


Right. Thus, it's a bad idea to use mutable properties in isEqual:.  
If you find yourself tempted to do that, impement an  
isEqualToMyClass: method rather than isEqual:.


If you compare primitives in -isEqual:, you should combine them  
(using
xor or the like) in -hash. If you compare objects by calling - 
isEqual:

on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all.


What's the motivation for combining hashes in this case?  I've  
wondered what is the best thing to do when isEqual: is based on  
comparing multiple ivars; I typically just use one of them for the  
hash.


It's a documented requirement of the isEqual: and hash methods that  
the hash must be the same when isEqual: returns YES. Thus, whatever  
logic that returns YES in isEqual: must have some kind of match in hash.


-Jeff

___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Jeff Johnson

On Aug 23, 2008, at 12:26 PM, Jeff Johnson wrote:

If you compare primitives in -isEqual:, you should combine them  
(using
xor or the like) in -hash. If you compare objects by calling - 
isEqual:

on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all.


What's the motivation for combining hashes in this case?  I've  
wondered what is the best thing to do when isEqual: is based on  
comparing multiple ivars; I typically just use one of them for the  
hash.


It's a documented requirement of the isEqual: and hash methods that  
the hash must be the same when isEqual: returns YES. Thus, whatever  
logic that returns YES in isEqual: must have some kind of match in  
hash.


-Jeff


Also, you're probably less likely to have collisions by combining.

___

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 [EMAIL PROTECTED]


error codes

2008-08-23 Thread Roland Silver
Is there a convenience function (or method) foo() with int arg and  
NSString* value for converting an error code to a string?

For example, given error code errcode = 560227702 = 0x21646576,
foo(errcode) =  @!idev?
--RS



___

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 [EMAIL PROTECTED]


Re: error codes

2008-08-23 Thread Kyle Sluder
On Sat, Aug 23, 2008 at 2:09 PM, Roland Silver [EMAIL PROTECTED] wrote:
 Is there a convenience function (or method) foo() with int arg and NSString*
 value for converting an error code to a string?

This program:
#include stdio.h

int main(int argc, char **argv)
{
int a = 560227702;
char *b = (char*)(a);
printf(%c%c%c%c%c, b[0], b[1], b[2], b[3], b[4]);
return 0;
}

Produces this output:
$ ./a.out
ved!?

It's close... dunno what magic is going on, but it shouldn't be that
hard to do yourself.  What bothers me is that you have a five
character error code (!idev) whereas an int is only 4 bytes wide.  I
wrote my code with 5 characters, but it's an obvious out-of-bounds
access.

--Kyle Sluder
___

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 [EMAIL PROTECTED]


Re: error codes

2008-08-23 Thread Bill Bumgarner

On Aug 23, 2008, at 11:44 AM, Kyle Sluder wrote:
On Sat, Aug 23, 2008 at 2:09 PM, Roland Silver  
[EMAIL PROTECTED] wrote:
Is there a convenience function (or method) foo() with int arg and  
NSString*

value for converting an error code to a string?


This program:
#include stdio.h

int main(int argc, char **argv)
{
   int a = 560227702;
   char *b = (char*)(a);
   printf(%c%c%c%c%c, b[0], b[1], b[2], b[3], b[4]);
   return 0;
}

Produces this output:
$ ./a.out
ved!?

It's close... dunno what magic is going on, but it shouldn't be that
hard to do yourself.  What bothers me is that you have a five
character error code (!idev) whereas an int is only 4 bytes wide.  I
wrote my code with 5 characters, but it's an obvious out-of-bounds
access.


Huh?   There is no reason why accessing b[4] should crash.  Produce a  
random value? Sure, but not crash.  You are just accessing one byte  
past a stack based array and, thus, reading a random byte off the stack.


If you want to crash, try:

((char *)0x1) = 'a';

Or the like.

Is there a convenience function (or method) foo() with int arg and  
NSString* value for converting an error code to a string?

For example, given error code errcode = 560227702 = 0x21646576,
foo(errcode) = @!idev?


Actually, I'm not even sure what the OP is asking for.   Where did the  
error code come from and why do you think converting it to the string  
'!idev' is going to be useful?


Ahh... it is kAudioHardwareBadDeviceError from Core Audio.  That is,  
there is a constant defined and you can do comparisons to see which  
error you have.  Converting to the four+ character gobbledy-gook  
really isn't going to help much.   A quick search reveals this bit of  
code which might be quite helpful:


http://www.martux.org/qemu_old/qemu-0.8.2-solaris__20061010x11/audio/coreaudio.c

b.bum



smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Re: Implementing isEqual: and hash

2008-08-23 Thread Adam R. Maxwell


On Aug 23, 2008, at 10:26 AM, Jeff Johnson wrote:


On Aug 23, 2008, at 11:38 AM, Adam R. Maxwell wrote:


On Aug 23, 2008, at 5:13 AM, Michael Ash wrote:

On Sat, Aug 23, 2008 at 7:41 AM, Graham Cox  
[EMAIL PROTECTED] wrote:
I have a class for which equality can be defined as having the  
same internal
string value (which happens to be a UUID-turned-string). I can  
easily
implement isEqual: based on that but the docs say I also need to  
implement
-hash. Any pointers on what is a good way to do that? Could I  
just safely

defer to the -hash returned by the string in question?


The implementation of -hash should *always* match the implementation
of -isEqual:.


And as Jim alluded, -hash must not depend on mutable properties; if  
the hash changes while the object is in a hashing collection,  
you'll end up with random crashes.


Right. Thus, it's a bad idea to use mutable properties in isEqual:.  
If you find yourself tempted to do that, impement an  
isEqualToMyClass: method rather than isEqual:.


CF collection callbacks are also handy in cases like this, since you  
can use equality functions that may not be correct for the general  
case of isEqual:.


If you compare primitives in -isEqual:, you should combine them  
(using
xor or the like) in -hash. If you compare objects by calling - 
isEqual:

on them, you should combine their hashes (using xor or the like). If
you do some of each, combine them all.


What's the motivation for combining hashes in this case?  I've  
wondered what is the best thing to do when isEqual: is based on  
comparing multiple ivars; I typically just use one of them for the  
hash.


It's a documented requirement of the isEqual: and hash methods that  
the hash must be the same when isEqual: returns YES. Thus, whatever  
logic that returns YES in isEqual: must have some kind of match in  
hash.


If I have

@interface Test : NSObject
{
  id ivar1;
  id ivar2;
}
@end

@implementation Test

- (BOOL)isEqual:(id)other
{
  if ([other isKindOfClass:[self class]] == NO) return NO;
  return ([ivar1 isEqual:(Test *)other-ivar1]  [ivar2 isEqual: 
(Test *)other-ivar2]);

}

- (unsigned)hash { return [ivar1 hash]; }

@end

I believe it's sufficient to use [ivar1 hash], since the object is  
only equal if ivar1 is equal in both objects.  I was just curious to  
know what you gain by using ([ivar1 hash] ^ [ivar2 hash]); is it  
possible to know in general if it reduces collisions?  Presumably that  
depends on the hash table implementation as well.


--
Adam

smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

How to read pixel values of monochrome images

2008-08-23 Thread Eduardo Areitio
I'm trying to read individual pixel values in a monochrome image using  
NSReadPixel, but I haven't  been able to.


 I would much appreciate anyone's help


___

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 [EMAIL PROTECTED]


Re: error codes

2008-08-23 Thread Kyle Sluder
On Sat, Aug 23, 2008 at 2:54 PM, Bill Bumgarner [EMAIL PROTECTED] wrote:
 Huh?   There is no reason why accessing b[4] should crash.  Produce a random
 value? Sure, but not crash.  You are just accessing one byte past a stack
 based array and, thus, reading a random byte off the stack.

I'm not looking for a crash.  The OP presented an error string
!idev, which has five characters.  An int is only four bytes wide,
so I was concerned about how the OP had gotten the !idev ==
560227702 relationship in the first place.  I thought it was perhaps a
typo, especially given the OS's history of FourCC's.

--Kyle Sluder
___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Jeff Johnson

On Aug 23, 2008, at 2:05 PM, Adam R. Maxwell wrote:


If I have

@interface Test : NSObject
{
  id ivar1;
  id ivar2;
}
@end

@implementation Test

- (BOOL)isEqual:(id)other
{
  if ([other isKindOfClass:[self class]] == NO) return NO;
  return ([ivar1 isEqual:(Test *)other-ivar1]  [ivar2 isEqual: 
(Test *)other-ivar2]);

}

- (unsigned)hash { return [ivar1 hash]; }

@end

I believe it's sufficient to use [ivar1 hash], since the object is  
only equal if ivar1 is equal in both objects.  I was just curious  
to know what you gain by using ([ivar1 hash] ^ [ivar2 hash]); is it  
possible to know in general if it reduces collisions?  Presumably  
that depends on the hash table implementation as well.


--
Adam


Right, it depends on the hash table implementation, which we don't  
know. Theoretically, it seems likely to reduce collisions. This could  
only be confirmed by real-world performance tests, though.


-Jeff

___

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 [EMAIL PROTECTED]


Re: NSApplication _doOpenUntitled raises exception under Leopard, not Tiger

2008-08-23 Thread Todd Blanchard
I found it.  CoreAudio being flakey again while being initialized.   
Changed order of initialization a bit and it stopped giving me the no  
such property error.  It is different in Tiger and Leopard despite  
sticking to the 10.4 api.


Is it me or is the debugger becoming progressively more useless?  I  
often find that it can't show me variables in the current scope and  
setting a breakpoint on NSException raise doesn't really reveal the  
point of error like it used to (lots of stack frames are omitted -  
even when they're mine).


Anyhow, thanks for noticing me.
-Todd Blanchard


On Aug 23, 2008, at 10:08 AM, Bill Bumgarner wrote:


On Aug 23, 2008, at 9:26 AM, Todd Blanchard wrote:

- (IBAction)newDocument:(id)sender
{
  [self closeAllDocumentsWithDelegate:self  
didCloseAllSelector 
:@selector(documentController:didCloseAll:contextInfo:) contextInfo: 
0];

  [super newDocument: sender];
}

because I only support one document open at a time.  Oddly enough,  
if I ignore the exception, this gets called twice during the  
opening sequence on Leopard.


Anybody know what changed about the opening sequence or why this  
should stop working on Leopard?


No idea, but it seems really odd to be closing all other documents  
when a new document is being opened.


It sounds like what might be happening is:

- app launches
- app requests untitled document
- untitled document is opened
- newDocument: is invoked
- newDocument: closes the freshly opened untitled document
- something a-splodes in super's newDocument: because it was doing  
something funky w/the untitled document


Do you need an untitled document? If not, kill it.

Otherwise, I'd need more context to understand the issue.

- what is the backtrace when the exception is tossed?

- what are the backtraces when -newDocument: is invoked twice?

... etc ...

b.bum



___

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 [EMAIL PROTECTED]


Re: NSApplication _doOpenUntitled raises exception under Leopard, not Tiger

2008-08-23 Thread Kyle Sluder
On Sat, Aug 23, 2008 at 4:40 PM, Todd Blanchard [EMAIL PROTECTED] wrote:
 Is it me or is the debugger becoming progressively more useless?  I often
 find that it can't show me variables in the current scope and setting a
 breakpoint on NSException raise doesn't really reveal the point of error
 like it used to (lots of stack frames are omitted - even when they're mine).

On Leopard, you should be breaking on objc_exception_throw.  Use
+[NSException raise] for Tiger exception debugging.

--Kyle Sluder
___

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 [EMAIL PROTECTED]


Re: NSApplication _doOpenUntitled raises exception under Leopard, not Tiger

2008-08-23 Thread Kyle Sluder
On Sat, Aug 23, 2008 at 4:55 PM, Todd Blanchard [EMAIL PROTECTED] wrote:
 I had no idea - I'm still catering to the Tiger world mostly.  Is there a
 good document that just tells me what is new?

The Leopard release notes are a great start:
http://developer.apple.com/releasenotes/Cocoa/Foundation.html

By the way, I was mistaken in suggesting breaking on +[NSException
raise].  No such method exists.  You want to break on -[NSException
raise] instead.

--Kyle Sluder
___

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 [EMAIL PROTECTED]


Re: How to read pixel values of monochrome images

2008-08-23 Thread Shawn Erickson
On Fri, Aug 22, 2008 at 2:54 AM, Eduardo Areitio [EMAIL PROTECTED] wrote:
 I'm trying to read individual pixel values in a monochrome image using
 NSReadPixel, but I haven't  been able to.

  I would much appreciate anyone's help

It is usually best to post some code or better explain what you tried
and what is going wrong otherwise we have to guess at the difficulty
you are having.

Anyway...

http://developer.apple.com/samplecode/Color_Sampler/listing5.html

-Shawn
___

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 [EMAIL PROTECTED]


Basic Window Management

2008-08-23 Thread Andrew Zahra
I am trying to add a log window to an otherwise single window application
and have come across a couple of basic window management issues.
Firstly, if the log window is closed by clicking the close button and then I
subsequently call makeKeyAndOrderFront then I get a crash. I presume there
is a window life cycle issue here I don't understand. How do I correctly
bring back a closed window?

Secondly, since this is a log window I want to write log info whenever I
have some. I also get a crash if I attempt to write to the textView when the
window has been closed. Can I keep the window alive, even if not on screen,
so I can continue to write to the textView?

thanks,
Andrew
___

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 [EMAIL PROTECTED]


Re: Basic Window Management

2008-08-23 Thread Charles Steinman



--- On Sat, 8/23/08, Andrew Zahra [EMAIL PROTECTED] wrote:

 I am trying to add a log window to an otherwise single
 window application
 and have come across a couple of basic window management
 issues.
 Firstly, if the log window is closed by clicking the close
 button and then I
 subsequently call makeKeyAndOrderFront then I get a crash.
 I presume there
 is a window life cycle issue here I don't understand.
 How do I correctly
 bring back a closed window?

The window is being released. Uncheck Release when closed in Interface 
Builder if you want it to stick around.

Cheers,
Chuck


  
___

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 [EMAIL PROTECTED]


renaming a project

2008-08-23 Thread Angelo Chen
hi,

I have a project which has MyTest as the project name, so the executable has 
the same name, now I'd like to rename it to MyProg, I renamed the Xoce's 
project file to MyProg, but the executable still has the previous name, any 
idea how to rename ? thanks

Angelo


  為了不斷提升Yahoo! 
Mail,雅虎香港誠邀你參與意見調查。請前往http://surveylink.yahoo.com/wix/p5429076.aspx 發表你的意見!
___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Pierre Sandboge


On Aug 23, 2008, at 9:43 PM, Jeff Johnson wrote:


On Aug 23, 2008, at 2:05 PM, Adam R. Maxwell wrote:


If I have

@interface Test : NSObject
{
 id ivar1;
 id ivar2;
}
@end

@implementation Test

- (BOOL)isEqual:(id)other
{
 if ([other isKindOfClass:[self class]] == NO) return NO;
 return ([ivar1 isEqual:(Test *)other-ivar1]  [ivar2 isEqual: 
(Test *)other-ivar2]);

}

- (unsigned)hash { return [ivar1 hash]; }

@end

I believe it's sufficient to use [ivar1 hash], since the object is  
only equal if ivar1 is equal in both objects.  I was just curious  
to know what you gain by using ([ivar1 hash] ^ [ivar2 hash]); is it  
possible to know in general if it reduces collisions?  Presumably  
that depends on the hash table implementation as well.


--
Adam


Right, it depends on the hash table implementation, which we don't  
know. Theoretically, it seems likely to reduce collisions. This  
could only be confirmed by real-world performance tests, though.


-Jeff

___

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/cocoa-dev 
%40standin.se


This email sent to [EMAIL PROTECTED]




I think theoretically, it seems likely to increase collisions. If  
ivar1 and ivar2 aren't independent of each other, xor can cluster  
different values  causing lots of collisions. Consider what happens if  
ivars are laid out serially say 0x0100 and 0x0200, xor and you  
get 0x300, and let's say that another completely different object's  
ivars  are 0xff000600 and 0xff000700, and you still get 0x300,  
collision.


The hash table implementation has nothing to do with this, the problem  
occurs before the hash table has any chance to make it even worse. (If  
you always return the same hash value, the hash table has nothing to  
work with in spreading the stored objects.)


/Pierre
___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Peter Duniho

Date: Sat, 23 Aug 2008 12:05:44 -0700
From: Adam R. Maxwell [EMAIL PROTECTED]

[...]
- (BOOL)isEqual:(id)other
{
   if ([other isKindOfClass:[self class]] == NO) return NO;
   return ([ivar1 isEqual:(Test *)other-ivar1]  [ivar2 isEqual:
(Test *)other-ivar2]);
}

- (unsigned)hash { return [ivar1 hash]; }

@end

I believe it's sufficient to use [ivar1 hash], since the object is
only equal if ivar1 is equal in both objects.  I was just curious to
know what you gain by using ([ivar1 hash] ^ [ivar2 hash]); is it
possible to know in general if it reduces collisions?


If you combine the hash values correctly, it will reduce collisions.   
Note that the previously mentioned xor technique is not generally  
considered correct and can in fact lead to increased collisions,  
not fewer.


One reasonably common technique for combining hash values into a new  
hash value is to multiply and accumulate using a prime number.   
There's probably some good math theory as to what a nice prime number  
to pick might be, but I've seen enough examples that use 37 that  
that's what I usually use.  :)


For example:

- (unsigned) hash
{
unsigned ret = 0;

ret += ret * 37 + [ivar1 hash];
ret += ret * 37 + [ivar2 hash];

return ret;
}

Note the redundant multiply and add in the first line.  Writing the  
code that way makes it easy to add/remove members if for some reason  
the data structure should change in the future.  But it would be just  
as correct to simply initialize ret to the first hash value, of course.



Presumably that
depends on the hash table implementation as well.


Well, if your hash values collide, they collide regardless of the  
hash table.  As long as you've got a well-distributed hash function,  
any collisions generated by the hash table implementation should be  
well-distributed as well.


Pete
___

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 [EMAIL PROTECTED]


specify a NSPredicate for jpeg file names?

2008-08-23 Thread Angelo Chen
Hi,

I'd like to filter an array to return only jpeg file names like DSC0001.jpg, 
DSC0002.jpg, etc. could anybody help me modify the jpegPredicate for that 
mater? thanks

NSPredicate *jpegPredicate = [NSPredicate predicateWithFormat:@SELF [c] 'b'];
NSArray *lst = [[[NSFileManager defaultManager] directoryContentsAtPath:aDir] 
filteredArrayUsingPredicate:jpegPredicate];




  為了不斷提升Yahoo! 
Mail,雅虎香港誠邀你參與意見調查。請前往http://surveylink.yahoo.com/wix/p5429076.aspx 發表你的意見!
___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Adam R. Maxwell


On Aug 23, 2008, at 5:20 PM, Peter Duniho wrote:


Date: Sat, 23 Aug 2008 12:05:44 -0700
From: Adam R. Maxwell [EMAIL PROTECTED]




[...]

Note the redundant multiply and add in the first line.  Writing the  
code that way makes it easy to add/remove members if for some reason  
the data structure should change in the future.  But it would be  
just as correct to simply initialize ret to the first hash value, of  
course.


Thanks for the example...I need to find time to do some profiling with  
this.



Presumably that
depends on the hash table implementation as well.


Well, if your hash values collide, they collide regardless of the  
hash table.  As long as you've got a well-distributed hash function,  
any collisions generated by the hash table implementation should be  
well-distributed as well.


My understanding was that the table might not use all bits of the hash  
value, so even differing hash values could be placed in the same  
bucket; that may be a misinterpretation of [1].  I find CFSet/CFBag/ 
CFDictionary to be one of the more confusing implementations in CF-Lite.


thanks,
Adam

[1] http://www.mulle-kybernetik.com/artikel/Optimization/opti-7.html

smime.p7s
Description: S/MIME cryptographic signature
___

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 [EMAIL PROTECTED]

Re: textfield not updating with bindings - Whats wrong?

2008-08-23 Thread Kieren Eaton


On Aug 23, 2008, at 5:16 AM, Kieren Eaton wrote:

ok the delegate is set as an object in IB it is the delegate of
Files owner and nsapplication (thats correct isnt it?) it has a
class of bindtestdelegate which is where the button action is  
located.

The button calls the changeValues method in the delegate class which
then calls the updateValues in the fooClass instance
of the someclass.

should my filesOwner in IB (Currently it is NSApplication) be
something different?


Well, that depends, in most cases it's good to have a
NSWindowController or NSViewController as file owner since those take
care of memory management of the nib file. But I believe it's
irrelevant to the problem at hand.


the instance of someClass is just dragged straight out of the IB lib
as a simple object and assigned the class someClass
I dont actually have a nsobjectcontroller subclass .h/.m  in my
project but according to the apple docs I dont need one?


No, you don't, you just mentioned you used one.

As far as I can tell from your explanation, you have 1
bindingstestDelegate object (the file's owner) and one extra someClass
object. The problem is that your delegate class creates its own
someClass instance and when you press the button that instance get
changed, not the other instance you created in the nib file.


Thats correct. I was not realising that the instance created in code  
and the one from the nib were not the same.



I would change the code so that the bindingstestDelegate class exposes
a readonly property named fooClass. You then remove the extra
someClass object from your nib and bind the NSTextFields to the file's
owner fooClass.someString and fooClass.someNumber keys.



I did that and it worked!   thanks very much. This has increased my  
comprehension of bindings a lot.


just for my own benefit i also tried adding an instance on an object  
controller to the nib and set its content outlet to the  
bindingstestDelegate.  Then I bound  one of the textfields to the  
object controller with

controller Key = selection
model Key = fooClass.someString

this also worked. YAyY :)

I have one minor question now that I am understanding bindings more.
Is is good policy to add an object controller instead of just binding  
directly to the class?



I would also suggest you change the naming slightly, using uppercase
first characters for class names. This makes it easier to distinguish
classes from instances, methods and properties. More details here:

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_12.html#/
/apple_ref/doc/uid/TP30001163-CH3-TPXREF108

Thanks and I do always use these conventions, except in this case  
where I just wanted a quick and dirty test case for my own learning.   
I did not expect to be posting it on this list, so apologies for the  
bad form on class and instance names etc.


Thanks very much for your help.

Now its onto much bigger things.

Kieren
___

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 [EMAIL PROTECTED]


Re: How to read pixel values of monochrome images

2008-08-23 Thread John C. Randolph


On Aug 23, 2008, at 2:51 PM, Shawn Erickson wrote:


On Fri, Aug 22, 2008 at 2:54 AM, Eduardo Areitio [EMAIL PROTECTED] wrote:
I'm trying to read individual pixel values in a monochrome image  
using

NSReadPixel, but I haven't  been able to.

I would much appreciate anyone's help


It is usually best to post some code or better explain what you tried
and what is going wrong otherwise we have to guess at the difficulty
you are having.

Anyway...

http://developer.apple.com/samplecode/Color_Sampler/listing5.html


You'll notice from the comments in that sample, that NSReadPixel()  
gets a value from the graphics context that has the current drawing  
focus.  If you're trying to read a value from an image, you've got to  
have somewhere to draw it first.


-jcr

___

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 [EMAIL PROTECTED]


Re: ObjC 2.0, properties, KVC, special _ hacks etc.

2008-08-23 Thread John C. Randolph


On Aug 21, 2008, at 7:59 PM, Thomas Engelmeier wrote:



Am 22.08.2008 um 00:59 schrieb Dave MacLachlan:

Also, are the _ in front of member variables for Apple only (so we  
don't stomp on each other with member var names) or are they using  
them for the readability reason mentioned above? There is  
documentation where they have claimed _ at the beginning of method  
names as being Apple only, but nothing about method vars, and the  
KVC compliance docs seem to imply that it is fine to do.


Officially it is Apple only, but everybody and his dog uses it - in  
consistency to quite some Apple-provided samples.


Please file bugs when you see a sample that does so.  A single leading  
underscore is an Apple internal coding convention, which should not be  
used for code samples.  I  did what I could to get those kinds of  
things fixed when I was there, but someone's got to file a bug for it  
to get noticed.


-jcr


___

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 [EMAIL PROTECTED]


Re: Implementing isEqual: and hash

2008-08-23 Thread Peter Duniho

Date: Sat, 23 Aug 2008 17:52:21 -0700
From: Adam R. Maxwell [EMAIL PROTECTED]


Well, if your hash values collide, they collide regardless of the
hash table.  As long as you've got a well-distributed hash function,
any collisions generated by the hash table implementation should be
well-distributed as well.


My understanding was that the table might not use all bits of the hash
value, so even differing hash values could be placed in the same
bucket; [...]


Sure.  Unless you've got a table that has as many entries as can be  
indexed by the full size of your hash value, it _has_ throw some sort  
of information away.  With a 32-bit hash value, you'd need a 4  
billion entry table, which obviously doesn't happen in practice.


I don't know the Cocoa hash table implementations, so I can't speak  
for how they work.  And any hash table implementation will have some  
particular worst-case input that could lead to pathological cases.   
But, it seems likely that the Cocoa hash table implementations  
perform reasonably well given reasonable, well-distributed hash value  
inputs.


Basically, don't worry about it until it's actually a problem.  Just  
make sure you're generating well-distributed hash values, and let  
Cocoa worry about how to apply those values with respect to its own  
hash table implementations.


Pete

___

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 [EMAIL PROTECTED]