Custom NSCell and Bindings

2011-06-24 Thread Carter R. Harrison
It's a pretty typical situation.  I've got my model objects stored in an NSSet. 
 An NSArrayController that is bound to the NSSet.  And then an NSTableView with 
one NSTableColumn bound to the arrangedObjects.name property of the 
NSArrayController.  It works great.  Now I've introduced a custom NSCell object 
into the NSTableView.  The custom cell displays a title, a subtitle, and a 
status image - all of which I want to be able to bind to 3 separate properties 
of the model object.  How do I do this?  Right now with the 'value' binding 
bound to the arrangedObjects.name property, on the title of my custom cell 
updates when the model updates.  If the subtitle or status update in the model 
object the cell does not update.  Any help is greatly appreciated.
___

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


NSManagedObjected isInserted

2011-04-10 Thread Carter R. Harrison
Can anybody ever think of a scenario where [NSManagedObject isInserted] equals 
NO for an object that is initially fetched from the context?  And no the object 
has not been deleted from the context prior to calling isInserted.
___

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: NSManagedObjected isInserted

2011-04-10 Thread Carter R. Harrison

On Apr 10, 2011, at 1:29 PM, Quincey Morris wrote:

 On Apr 10, 2011, at 06:52, Carter R. Harrison wrote:
 
 Can anybody ever think of a scenario where [NSManagedObject isInserted] 
 equals NO for an object that is initially fetched from the context?  And no 
 the object has not been deleted from the context prior to calling isInserted.
 
 What do you mean by initially fetched? The object should return YES for 
 isInserted from the time it's inserted to the time the store is 
 committed/saved. It's not clear where in this timeline your initially is 
 pointing.
 

I'm creating and NSManagedObject with [NSManagedObject 
initWithEntity:insertIntoManagedObjectContext:] and for the context I'm passing 
nil.  Later I call [NSManagedObjectContext insertObject:] and pass in the same 
NSManagedObject that was initialized earlier.

On a subsequent run of my application I fetch the object from the store and 
call [NSManagedObject isInserted].  Without fail it always returns NO.



___

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: Two Applications Sharing Same Core Data Database

2011-04-08 Thread Carter R. Harrison

On Apr 7, 2011, at 7:04 PM, Carter R. Harrison wrote:

 
 On Apr 7, 2011, at 6:38 PM, Nick Zitzmann wrote:
 
 
 On Apr 7, 2011, at 4:24 PM, Carter R. Harrison wrote:
 
 I really appreciate all of your help.  I gave your suggestion a shot and 
 I've run into problems.  Here's what happens.
 
 1. I create a new NSManagedObject in my main application.  It gets inserted 
 into the context.
 2. I save the context.  I can see the persistent store update in a text 
 editor (its an XML store).
 3. I send a distributed notification with the NSManagedObject's ObjectID.
 4. My background application consumes the notification and uses the object 
 ID to get an NSManagedObject (using [NSManagedObjectContext objectWithID:]. 
  This produces an NSManagedObject that is a fault.
 5. I try to fire the fault by using [NSManagedObject valueForKey:].
 6. Step 5 results in an exception CoreData could not fulfill a fault for 
 '0x1001029e0 
 x-coredata://BB194166-B2FB-48ED-8177-E66F95B6CA3A/Alert/p118'
 
 I'm not sure I understand why this is happening.  If the object is truly a 
 fault then shouldn't Core Data go back to the persistent store to find the 
 object?
 
 I think I've seen this before... Try calling sync() at the top of your 
 notification handler. That will force external database changes to be 
 written to disk.
 
 If that doesn't work, then you may need to fetch the object from the context 
 using some identifier other than the object ID. We do this in our products 
 that share a database, and it works for us when a helper app receives a 
 notification from the master app that a record has been 
 added/updated/deleted.
 
 
 Well no dice with either option.  sync() doesn't do it and a fetch request 
 using a different identifier yields 0 objects.  Do your products use XML 
 stores?

Well I ended up changing my store to a sqlite store and it started working 
right away.  There are some options you can supply when creating the store to 
force the kernel to flush all changes to the store to disk in a synchronous 
manner which I applied the first time I tried.  Apple's Documentation says this 
is comparatively much slower but I'm not working with large sets of data and 
the I don't need to save too frequently.  I'm going to try backing off on some 
of these options to see if everything still works.

Nick - thanks so much for your help.


 Nick Zitzmann
 http://www.chronosnet.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: Two Applications Sharing Same Core Data Database

2011-04-07 Thread Carter R. Harrison

On Mar 30, 2011, at 4:09 PM, Nick Zitzmann wrote:

 
 On Mar 30, 2011, at 2:05 PM, Carter R. Harrison wrote:
 
 2. What is the best way to implement it?  
 
 Put your CoreData code into a framework shared by your applications. And 
 use distributed notifications to keep the applications in sync.
 
 So when one application saves the data store, then it sends a distributed 
 notification to tell the other application to reload its object graph?
 
 Something like that. Or you can send a notification containing the IDs of the 
 managed objects that were changed in the other app, and have your handler 
 re-fault its managed objects if necessary so that it'll have the latest 
 information when it un-faults them later.
 

I really appreciate all of your help.  I gave your suggestion a shot and I've 
run into problems.  Here's what happens.

1. I create a new NSManagedObject in my main application.  It gets inserted 
into the context.
2. I save the context.  I can see the persistent store update in a text editor 
(its an XML store).
3. I send a distributed notification with the NSManagedObject's ObjectID.
4. My background application consumes the notification and uses the object ID 
to get an NSManagedObject (using [NSManagedObjectContext objectWithID:].  This 
produces an NSManagedObject that is a fault.
5. I try to fire the fault by using [NSManagedObject valueForKey:].
6. Step 5 results in an exception CoreData could not fulfill a fault for 
'0x1001029e0 x-coredata://BB194166-B2FB-48ED-8177-E66F95B6CA3A/Alert/p118'

I'm not sure I understand why this is happening.  If the object is truly a 
fault then shouldn't Core Data go back to the persistent store to find the 
object?


 Nick Zitzmann
 http://www.chronosnet.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: Two Applications Sharing Same Core Data Database

2011-04-07 Thread Carter R. Harrison

On Apr 7, 2011, at 6:38 PM, Nick Zitzmann wrote:

 
 On Apr 7, 2011, at 4:24 PM, Carter R. Harrison wrote:
 
 I really appreciate all of your help.  I gave your suggestion a shot and 
 I've run into problems.  Here's what happens.
 
 1. I create a new NSManagedObject in my main application.  It gets inserted 
 into the context.
 2. I save the context.  I can see the persistent store update in a text 
 editor (its an XML store).
 3. I send a distributed notification with the NSManagedObject's ObjectID.
 4. My background application consumes the notification and uses the object 
 ID to get an NSManagedObject (using [NSManagedObjectContext objectWithID:].  
 This produces an NSManagedObject that is a fault.
 5. I try to fire the fault by using [NSManagedObject valueForKey:].
 6. Step 5 results in an exception CoreData could not fulfill a fault for 
 '0x1001029e0 x-coredata://BB194166-B2FB-48ED-8177-E66F95B6CA3A/Alert/p118'
 
 I'm not sure I understand why this is happening.  If the object is truly a 
 fault then shouldn't Core Data go back to the persistent store to find the 
 object?
 
 I think I've seen this before... Try calling sync() at the top of your 
 notification handler. That will force external database changes to be written 
 to disk.
 
 If that doesn't work, then you may need to fetch the object from the context 
 using some identifier other than the object ID. We do this in our products 
 that share a database, and it works for us when a helper app receives a 
 notification from the master app that a record has been added/updated/deleted.
 

Well no dice with either option.  sync() doesn't do it and a fetch request 
using a different identifier yields 0 objects.  Do your products use XML stores?


 Nick Zitzmann
 http://www.chronosnet.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


Dynamically Loading Code and Core Data Non-Standard Persistent Attributes

2011-04-05 Thread Carter R. Harrison
My Core Data application has a plugin architecture.  Plugins reside within 
their own bundles and of course are loaded dynamically at runtime.  I intend to 
encode instances of each plugin bundle's principal class just as Apple 
describes it in the section of the Core Data Programming Guide called 
Non-Standard Persistent Attributes.  In this section it explains that you 
should create an attribute of type Transformable within your entity.  This 
particular attribute is encoded and decoded using NSKeyedArchiving.  So the 
instances of my plugins archive correctly, but when I relaunch the application 
and Core Data tries to unarchive them I receive an exception like: 

*** -[NSKeyedUnarchiver decodeObjectForKey:]: cannot decode object of class 
(DiskSpaceAlert)

I can't tell exactly why this is happening.  My plugin class implements the 
NSCoding protocol.  I'm thinking that it's happening because at the time of 
unarchiving, my plugin's bundle has not been loaded and thus the 
NSKeyedArchiver can't find my class (DiskSpaceAlert in this case).  So I added 
code to dynamically load all of my plugin bundles prior to the point where they 
are unarchived but this hasn't fixed anything.

Can anybody help me out?  Thank you in advance.
___

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


Two Applications Sharing Same Core Data Database

2011-03-30 Thread Carter R. Harrison
I'm working on a Mac Application that will have a helper application that is 
always running in the background (even if the main application is not currently 
running).  Currently the main application uses Core Data to manage persistent 
objects.  I'd like to setup the helper application to be able to use the same 
persistent store.  I've read through the Core Data documentation, specifically 
the section on concurrency, but I feel as though my situation is different from 
what is discussed in that document and I'm still a little confused as to what 
the best approach is.
 
So my questions are:
1. Is it even possible to do this?
2. What is the best way to implement it?  
___

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: Two Applications Sharing Same Core Data Database

2011-03-30 Thread Carter R. Harrison

On Mar 30, 2011, at 4:03 PM, Nick Zitzmann wrote:

 
 On Mar 30, 2011, at 1:45 PM, Carter R. Harrison wrote:
 
 I'm working on a Mac Application that will have a helper application that is 
 always running in the background (even if the main application is not 
 currently running).  Currently the main application uses Core Data to manage 
 persistent objects.  I'd like to setup the helper application to be able to 
 use the same persistent store.  I've read through the Core Data 
 documentation, specifically the section on concurrency, but I feel as though 
 my situation is different from what is discussed in that document and I'm 
 still a little confused as to what the best approach is.
 
 So my questions are:
 1. Is it even possible to do this?
 
 Yes, as long as they're on the same computer.

Yes they will be on the same computer.

 
 2. What is the best way to implement it?  
 
 Put your CoreData code into a framework shared by your applications. And use 
 distributed notifications to keep the applications in sync.

So when one application saves the data store, then it sends a distributed 
notification to tell the other application to reload its object graph?


 
 Nick Zitzmann
 http://www.chronosnet.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


Drag Drop in an NSOutlineView

2011-03-14 Thread Carter R. Harrison
I'm having trouble getting drag and drop to work with an NSOutlineView.  What 
I've done is below.  The problem is that 
tableView:writeRowsWithIndexes:toPasteboard never gets called.  I found a few 
people with the same issue and it seems that the cause of the problem is that I 
am using a custom cell that is a subclass of NSTextFieldCell, however I haven't 
been able to find a solution that fixes my problem.

1. Set the NSOutlineView's delegate and datasource outlets.
2. In the datasource's awakeFromNib method I call registerForDraggedTypes: on 
the outline view.
3. I implemented the following methods in my datasource:

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet 
*)rowIndexes toPasteboard:(NSPasteBoard *)pboard
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id  
NSDraggingInfo )info item:(id)item
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id  
NSDraggingInfo )info proposedItem:(id)item proposedChildIndex:(NSInteger)index

Any help is greatly appreciated!
___

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: Drag Drop in an NSOutlineView

2011-03-14 Thread Carter R. Harrison
The custom cell I'm using is a modification of ImageAndTextCell from the 
DragNDropOutlineView sample project.  In that class they have some comments 
that describe how hitTestForEvent:inRect:ofView: works.  It's my 
understanding that if I return anything other than NSCellHitTrackableArea a 
drag should be initiated.  Here is my implementation of that method and I'm 
still not having any luck:

- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame 
ofView:(NSView *)controlView 
{
return NSCellHitContentArea;
}


On Mar 14, 2011, at 3:25 PM, Corbin Dunn wrote:

 Your custom cell needs to properly implement:
 
 - (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame 
 ofView:(NSView *)controlView NS_AVAILABLE_MAC(10_5);
 
 See the header for details or the AnimatedTableView demo.
 
 --corbin
 
 On Mar 14, 2011, at 12:20 PM, Carter R. Harrison wrote:
 
 I'm having trouble getting drag and drop to work with an NSOutlineView.  
 What I've done is below.  The problem is that 
 tableView:writeRowsWithIndexes:toPasteboard never gets called.  I found a 
 few people with the same issue and it seems that the cause of the problem is 
 that I am using a custom cell that is a subclass of NSTextFieldCell, however 
 I haven't been able to find a solution that fixes my problem.
 
 1. Set the NSOutlineView's delegate and datasource outlets.
 2. In the datasource's awakeFromNib method I call registerForDraggedTypes: 
 on the outline view.
 3. I implemented the following methods in my datasource:
 
 - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet 
 *)rowIndexes toPasteboard:(NSPasteBoard *)pboard
 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id  
 NSDraggingInfo )info item:(id)item
 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id 
  NSDraggingInfo )info proposedItem:(id)item 
 proposedChildIndex:(NSInteger)index
 
 Any help is greatly appreciated!
 ___
 
 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/corbind%40apple.com
 
 This email sent to corb...@apple.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: Drag Drop in an NSOutlineView

2011-03-14 Thread Carter R. Harrison
Ack!  I can't believe I missed that.  The correct method to implement is:

- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items 
toPasteboard:(NSPasteboard *)pboard

Once I changed the method declaration and a few of the implementation details 
drag and drop is now working!  Thanks!


On Mar 14, 2011, at 3:33 PM, Quincey Morris wrote:

 On Mar 14, 2011, at 12:20, Carter R. Harrison wrote:
 
 I'm having trouble getting drag and drop to work with an NSOutlineView.  
 What I've done is below.  The problem is that 
 tableView:writeRowsWithIndexes:toPasteboard never gets called.  I found a 
 few people with the same issue and it seems that the cause of the problem is 
 that I am using a custom cell that is a subclass of NSTextFieldCell, however 
 I haven't been able to find a solution that fixes my problem.
 
 1. Set the NSOutlineView's delegate and datasource outlets.
 2. In the datasource's awakeFromNib method I call registerForDraggedTypes: 
 on the outline view.
 3. I implemented the following methods in my datasource:
 
 - (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet 
 *)rowIndexes toPasteboard:(NSPasteBoard *)pboard
 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id  
 NSDraggingInfo )info item:(id)item
 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id 
  NSDraggingInfo )info proposedItem:(id)item 
 proposedChildIndex:(NSInteger)index
 
 Why are you (trying to) use tableView:writeRowsWithIndexes:toPasteboard:? Why 
 not outlineView:writeItems:toPasteboard:?
 
 

___

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


Handling Connection Timeouts with NSStream

2010-09-10 Thread Carter R. Harrison
Hey Folks,

I'm working on a app that establishes a network connection using NSStream.  I 
found though that the code does not behave very well when it is trying to 
connect to an unreachable IP address or an IP address that just isn't accepting 
connections on the port I have specified.  The code I'm using is below.  Does 
anybody have any good ideas on how to detect a connection timeout or a complete 
connection failure?  Apple's documentation indicates that if a connection 
cannot be established the NSInputStream and NSOutputStream returned will be 
nil, but for some reason my checks for that never seem to work.  Any help is 
appreciated and thanks in advance.

NSHost *host = [NSHost hostWithAddress:address];
[NSStream getStreamsToHost:host port:port inputStream:is outputStream:os];

if (!is || !os)
{
NSLog(@This line doesn't execute, even with a bogus IP address);
}

buffer = [[NSMutableData alloc] initWithCapacity:0];
[is retain];
[os retain];

[is open];
[os open];
___

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


Main Thread Crashing in Multithreaded App

2010-08-06 Thread Carter R. Harrison
My Cocoa application's main thread is crashing with EXC_BAD_ACCESS when it 
becomes multithreaded.  The crash always occurs in the main thread when the 
call stack is:

0   objc_msgSend
1   __CFArrayReleaseValues
2   _CFRelease
3   _CFAutoReleasePoolPop
4   -[NSAutoReleasePool drain]
5   -[NSApplication run]
6   NSApplicationMain
7   main

The call I'm making to establish the 2nd thread is: 

[self performSelectorInBackground:@selector(executeQueryHelper:) 
withObject:[myMutableDictionary mutableCopy]];

That selector runs a whole lot of stuff that I know performs solidly when it 
runs by itself in the main thread, and that selector also cretes its own 
NSAutoReleasePool and then drains it at the end of the method.  I opted to make 
a mutable copy of the dictionary that is passed into the 2nd thread in hopes to 
reduce any concurrency problems with the shared variable but that didn't seem 
to make any difference.

Anybody have any solid ideas on what to try next?  Thanks in advance.

Carter
___

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


Socket Blocking Question

2010-01-20 Thread Carter R. Harrison
I need some folks experienced with cocoa and socket programming to weigh in for 
me on some design problems I've been having.  I'm designing an application that 
acts as a client in a client-server model.  The client communicates with the 
server over the network by issuing a request and then receiving a response.  
Requests can only be issued one at a time, meaning that a request cannot be 
sent until a response from any outstanding request is first received.  My 
application works in such a way that the it could request a handle to an object 
on the server and then use that handle in subsequent requests to retrieve 
additional information about the object.  I see two ways of modeling the 
application - I've tried both and I'm not particularly happy with either.

The first is to send a request, and then have the socket block until a response 
is received.  This benefit to this model is that it is so much easier to write 
the higher level application code.  The issue with this model is that over a 
slow network connection it can take a considerable amount of time for the 
response to come back from the server and while that is happening my CPU usage 
is through the roof b/c the thread is blocking.

The second way is to send a request and then let the NSInputStream call a 
delegate method when the response data is available.  The response data is then 
pushed up through my protocol stack and finally up to the higher level 
application code.  The benefit to this method is that CPU usage is minimal due 
to the fact that I'm no longer blocking, but the downside is that the higher 
level application code is so much more difficult to write because I have to 
write about a thousand methods to act as a callback for each request in a 
series of requests.

I've provided an example of how I see each working below.  My first question 
is, is there other ways to design an application around this client-server 
model that I'm not thinking about?  My 2nd question is, if there aren't other 
ways, how can I adapt either method that I have outlined to make it work a 
little bit better?

As an example let's say the server knows about the following objects:

1. VendingMachine
- An object that represents a vending machine.
- A vending machine contains Soft Drink objects.
2. SoftDrink
- Has the following properties: drink name, price, number of calories.

If I use the blocking model, I could write my code like this.  The code is 
simple to write but I'm forced to wait for the server to respond with 
information on pretty much every line of code.  If the vending machine had 
enough soft drinks it could take a long time to iterate over each one and have 
the server respond with the drink's name of each drink.

-(void)printDrinkNames
{
VendingMachine *machine = [server fetchVendingMachine];
NSArray *softDrinks = [machine getSoftDrinks];
for (int i = 0 ; i  softDrinks.count ; i++)
{
NSString *drinkName = [[softDrinks objectAtIndex:i] name];
NSLog(@Found a drink named %@, drinkName);
}
}

Likewise if I do the non-blocking approach I would have to have a method that 
gets called for each step in the process (see below).  This model drives me 
crazy b/c the higher level application code is long, has tons of methods, and 
is just difficult to read and maintain.  The example I have provided is simple 
enough to get the point across, but in reality some of the processes I'm trying 
to drive are much more complex and require numerous callback methods to pull 
off.

-(void)printDrinkNames
{
[server fetchVendingMachineWithCallBackObject:self 
selector:@selector(didFetchVendingMachine:)
}

-(void)didFetchVendingMachine:(VendingMachine *)machine
{
[machine fetchSoftDrinksWithCallBackObject:self 
selector:@selector(didFetchSoftDrinks:)];
}

-(void)didFetchSoftDrinks:(NSArray *)drinks
{
for (int i = 0 ; i  drinks.count ; i++)
{
SoftDrink *drink = [drinks objectAtIndex:i];
[drink fetchNameWithCallBackObject:self 
selector:@selector(didFetchDrinkName:)]
}
}

-(void)didFetchDrinkName:(NSString *)name
{
NSLog(@Drink name is %@, name);
}

___

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: Bindings Problem

2010-01-20 Thread Carter R. Harrison

On Jan 18, 2010, at 4:55 PM, Ken Thomases wrote:

 On Jan 18, 2010, at 11:01 AM, Jeffrey Oleander wrote:
 
 http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Collections/Articles/Sets.html
 
 Set Fundamentals: Note that if mutable objects are stored in a set, either 
 the hash method of the objects shouldn’t depend on the internal state of the 
 mutable objects or the mutable objects shouldn’t be modified while they’re 
 in the set (note that it can be difficult to know whether or not a given 
 object is in a collection).
 
 So, you can use your own hash function to determine where in the set each 
 item is stored.  In this case, each item stored in the set is an 
 NSMutableDictionary.
 
 And... you can't change the hash function used by NSMutableDictionary.  So, 
 for a custom class, you can implement a custom -hash method.  But for 
 NSMutableDictionary, you can't.  And, if you do implement a custom -hash 
 method for your custom class which is insensitive to the contents (whatever 
 that might be) of its instances, then that's a _very_ different equality 
 semantic than NSDictionary provides.
 
 
 http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html
 
 Internally, a dictionary uses a hash table to organize its storage and to 
 provide rapid access to a value given the corresponding key. However, the 
 methods defined in this cluster insulate you from the complexities of 
 working with hash tables, hashing functions, or the hashed value of keys. 
 The methods described below take keys directly, not their hashed form.
 
 So, you may use your own hash function to create your keys... or not, as you 
 wish.
 
 Um, the keys are not typically the output of a hash function.  Well, you can 
 use such for keys, but that's irrelevant to the hash of the dictionary 
 object, itself.
 
 But then the NSDictionary and NSMutableDictionary will hash the keys you 
 pass to their methods using their own, internal, hash function, to determine 
 where objects are stored in the dictionary.
 
 Right.  So, if you mutate the dictionary while it's in the set, you will 
 break things.  That's why a set of mutable dictionaries (as opposed to 
 immutable dictionaries, or some other data structure entirely) raises a huge 
 red flag.
 
 As I previously cited, from the documentation of -[NSObject hash]:
 http://developer.apple.com/mac/library/documentation/cocoa/Reference/Foundation/Protocols/NSObject_Protocol/Reference/NSObject.html
 
 If a mutable object is added to a collection that uses hash values to 
 determine the object’s position in the collection, the value returned by the 
 hash method of the object must not change while the object is in the 
 collection. Therefore, either the hash method must not rely on any of the 
 object’s internal state information or you must make sure the object’s 
 internal state information does not change while the object is in the 
 collection. Thus, for example, a mutable dictionary can be put in a hash 
 table but you must not change it while it is in there. (Note that it can be 
 difficult to know whether or not a given object is in a collection.)
 
 Note that this case of mutable dictionaries in a collection is explicitly 
 warned about.
 
 
 But my primary point was to ask the original poster to think about why he is 
 using this arrangement of instances of NSMutableDictionary stored in an 
 NSMutableSet.
 
 Yes, and that was my point, too.

Thanks for the insight guys - you have convinced me to re-think my data model.  
I never even began to conceive of some of the issues you have put on the table.


 
 -Ken
 

___

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: Socket Blocking Question

2010-01-20 Thread Carter R. Harrison

On Jan 20, 2010, at 1:40 PM, Steven Degutis wrote:

 Recently I had the same issue you were having, sort of. And I came up with a 
 solution I really liked.
 
 When I was playing with Distributed Objects, I fell in love with the abstract 
 simplicity. However, it blocks and that's bad. It's even worse when the 
 server stops responding, because you could potentially have a 60 second 
 timeout before the single method will return. It's a potential disaster.
 
 So, I wrote an elegant compromise. Code is still written inline, no callbacks 
 or delegate messages needed. But, it requires Blocks (and thus 10.6) to work.

Steven - this is a really interesting approach.  I can see how this basically 
achieves the same thing as all the callback methods, but does allow the code to 
be written somewhat inline.  Unfortunately I need to at least support OS X 10.5 
at this point.  I definitely need to read-up on blocks b/c I can see how they 
can be used to work around some tricky design problems.

 
 Essentially, I wrote some code on top of AsyncSocket (which is a brilliant 
 framework by the way) that allows me to wrap up ObjC messages as NSData, send 
 it across the server, and unpack it on the other side. The other side then 
 responds to the ObjC message as if it was called right inside the 
 application. (All this is thanks to NSInvocation's ability to introspect an 
 ObjC message, by the way).
 
 The problem came when I had to return values. As long as the return value was 
 void, this worked like a charm. But once I wanted to return an array of 
 strings or a number, I had to define a method in the sender's protocol to 
 receive such information. This is akin to your thousands of delegate 
 messages you would have to implement, as you stated.
 
 So, using Blocks and NSInvocation and AsyncSocket, I ended up writing code 
 that allows me to write code like this:
 
 
 // protocol.h
 
 @protocol ServerProtocol
 
 - (NSNumber*) calculatePiAndKillTime:(NSNumber*)shouldKillTime;
 
 @end
 
 
 // client.m
 
 - (void) someMethod {
 id ServerProtocol server;
 NSNumber *sure = [NSNumber numberWithBool:YES];
 [[server calculatePiAndKillTime: sure]
  returnedValue:^(id value) {
 // this will be called later on at some point
 NSLog(@pi = %@, value);
 }]
 }
 
 
 // server.m
 
 - (NSNumber*) calculatePiAndKillTime:(NSNumber*)shouldKillTime {
 if ([shouldKillTime boolValue])
 // synchronously watch some film
 [self goWatchTheNewStarTrekFilmFrom2009];
 
 return [NSNumber numberWithFloat: 3.14];
 }
 
 
 
 All methods sent to a destination's proxy are sent asynchronously. And, as 
 you can see, the return value of the method -calculatePiAndKillTime: is not 
 actually an NSNumber, but rather a proxy that waits for a response from the 
 destination. When the destination responds to the source with a return value, 
 the method -returnedValue: is called with the value.
 
 But that's only half of the coolness.
 
 The other half is that methods can simply return the value they want right 
 inside the method, no hacks necessary or anything by the programmer. In this 
 case, we just use this line of code: return [NSNumber numberWithFloat: 3.14]; 
 and then the NSNumber object is packaged up and sent back to the source 
 through the proxy, all automagically.
 
 The main downfall of this is that every argument and return value must be an 
 ObjC type, no scalars or structs or anything else will work with this system. 
 (Mike Ash explains pretty well on this blog why trying to support those 
 things can lead to some unfixable trickiness, which I just wanted to avoid 
 altogether.)
 
 If you can't support 10.6, then, this won't work. But hopefully you can soon 
 ;)
 
 Good luck.
 
 -Steven
 
 
 
 On Wed, Jan 20, 2010 at 11:39 AM, Carter R. Harrison carterharri...@mac.com 
 wrote:
 I need some folks experienced with cocoa and socket programming to weigh in 
 for me on some design problems I've been having.  I'm designing an 
 application that acts as a client in a client-server model.  The client 
 communicates with the server over the network by issuing a request and then 
 receiving a response.  Requests can only be issued one at a time, meaning 
 that a request cannot be sent until a response from any outstanding request 
 is first received.  My application works in such a way that the it could 
 request a handle to an object on the server and then use that handle in 
 subsequent requests to retrieve additional information about the object.  I 
 see two ways of modeling the application - I've tried both and I'm not 
 particularly happy with either.
 
 The first is to send a request, and then have the socket block until a 
 response is received.  This benefit to this model is that it is so much 
 easier to write the higher level application code.  The issue with this model 
 is that over a slow network connection

Re: Socket Blocking Question

2010-01-20 Thread Carter R. Harrison

On Jan 20, 2010, at 2:23 PM, Ken Thomases wrote:

 On Jan 20, 2010, at 11:39 AM, Carter R. Harrison wrote:
 
 I need some folks experienced with cocoa and socket programming to weigh in 
 for me on some design problems I've been having.  I'm designing an 
 application that acts as a client in a client-server model.  The client 
 communicates with the server over the network by issuing a request and then 
 receiving a response.  Requests can only be issued one at a time, meaning 
 that a request cannot be sent until a response from any outstanding request 
 is first received.  My application works in such a way that the it could 
 request a handle to an object on the server and then use that handle in 
 subsequent requests to retrieve additional information about the object.  I 
 see two ways of modeling the application - I've tried both and I'm not 
 particularly happy with either.
 
 The first is to send a request, and then have the socket block until a 
 response is received.  This benefit to this model is that it is so much 
 easier to write the higher level application code.  The issue with this 
 model is that over a slow network connection it can take a considerable 
 amount of time for the response to come back from the server and while that 
 is happening my CPU usage is through the roof b/c the thread is blocking.
 
 If you're using lots of CPU time, then you're not blocking, you're spinning.  
 When a thread is blocked, it does nothing and consumes no CPU time.
 
 Now, blocking is bad in the main thread of a GUI app, but if you're writing 
 non-GUI code, it can be a perfectly sensible design approach.  However, you 
 have to actually implement blocking!

Ken - thanks for the info.  I had thought the same thing when I wrote the code 
so I must be doing something wrong as you said.  Here's my method that sends 
data and then waits for the response back from the server.  I've paired my code 
down so it is a bit simpler than it actually is, but the gist of it is the 
same.  Here the request is sent to the server and the method does not return 
until 1024 bytes of data has been returned.  I'm basically calling 
[NSInputStream hasBytesAvailable] and if it returns NO then I am using the 
sleep() method to sleep the thread for 100ms.  Over a fast connection the CPU 
usage is very very low ( 2%), but on a slower connection where the server 
could take a couple hundred milliseconds to return the CPU usage hovers around 
25 or 30% - way too high for regular use.  In the code, is is an 
NSInputStream and os is an NSOutputStream.  I would greatly appreciate your 
insight on this.

-(NSData *)sendDataReturningResponse:(NSData *)data error:(NSError **)error
{
//Write the data to the output stream.
int retval = [os write:[data bytes] maxLength:[data length]];

//retval will be -1 if an error has occurred.
if (retval == -1)
{
*error = os.streamError;
NSLog(@%@, [os.streamError localizedDescription]);
return nil;
}
else
*error = nil;

NSMutableData *response = [[NSMutableData alloc] initWithCapacity:0];

//Wait for response to come back.
while (response.length  1024)
{
if ([is hasBytesAvailable])
{
uint8_t buf[MAX_RECV_SIZE];
unsigned int maxlen = 0;
maxlen = [is read:buf maxLength:MAX_RECV_SIZE];
[response appendBytes:(const void *)buf length:maxlen];
}
else 
{
sleep(.1);  //No data available on the input 
buffer.  Sleep for 100ms and we'll try again.
}
}
return [response autorelease];
}



 
 Cheers,
 Ken
 

___

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


Bindings Problem

2010-01-14 Thread Carter R. Harrison
I'm sure what I'm trying to do is not that difficult but I've been pulling my 
hair out for a while now on this problem.

I have an application whose model could be updated without the user directly 
doing anything.  So bindings seems like the perfect fit b/c the interface will 
reflect these sorts of changes when they occur.  But I can't seem to get 
updates in my model to appear in the interface.  My model is an NSMutableSet 
that contains NSMutableDictionaries.  I then have a NSTableView with several 
columns.  I want each column in the table to display a value from each 
NSMutableDictionary.

@interface MyController : NSObject 
{
NSMutableSet *myset;
}

//I initialize the NSMutableSet in this method.
- (void)awakeFromNib;

//Setter and Getter to ensure KVC compliance.
- (void)setMyset:(NSMutableSet *)set;
- (NSMutableSet *)myset;

//This method is here for testing.  A button in the UI is connected to the 
method.
//When executed this method creates a new NSMutableDictionary.  Adds some 
key/value
//pairs to it then adds the NSMutableDictionary to the NSMutableSet (myset).
- (IBAction)addValueToSet:(id)sender;


In Interface Builder I have dragged out an NSObject and set its type to be 
MyController.  I then dragged out an NSObjectController and set its Content 
connection to the MyController object.  I then dragged out an NSArrayController 
and bound its Content Array binding to the Object Controller with a Controller 
Key of selection and a Model Key Path of myset.  I also set the 
NSArrayController's Class Name to NSMutableDictionary since that is what is 
held by my NSMutableSet.  I setup a NSTableView in my application's window and 
then bound its first table column's Value binding to the NSArrayController 
using arrangedObjects as the Controller Key and Caption as the Model Key 
Path.  Caption is the key to a key/value pair in the NSMutableDictionary that 
is held by the NSMutableSet (myset).

In the addValueToSet: method I have the following code:

- (IBAction)addValueToSet:(id)sender
{
NSString *newString = @New Value;
NSMutableDictionary *dict = [[[NSMutableDictionary alloc] 
initWithCapacity:1] autorelease];
[dict setValue:newString forKey:@Caption];
[myset addObject:dict];
}

When I click the button in my interface nothing happens.  I know the 
addValueToSet: method is being called however I would expect the interface to 
update based upon my updating the model.  Can anybody tell me what I'm doing 
wrong?
___

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


NSRuleEditor rows binding

2009-12-04 Thread Carter R. Harrison
Apple's documentation for NSRuleEditor indicates that it exposes a binding 
named rows.  When I drag an NSRuleEditor onto my NSWindow in IB, I flip over 
to the Bindings tab of the inspector and I don't see any bindings named rows. 
 Anybody else manage to setup an NSRuleEditor with bindings?

Thanks
Carter
___

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


Question Regarding the Memory Address of Objects

2008-12-18 Thread Carter R. Harrison

Ok, hopefully this is an easy one.

I have a Nib file setup with an NSView and some NSButton's as subviews  
of that view.  I have IBOutlets for each of the NSButton's in my  
NSView subclass.


In the awakeFromNib: method of my NSView subclass I do the following:

- (void)awakeFromNib
{   
//Initialize NSMutableDictionary instance variable
	dict = [[NSMutableDictionary alloc] initWithCapacity:1];		// dict  
is an NSMutableDictionary instance variable


	//Set the value button1 into the dictionary and make it's key the  
string representation of button1's memory address.
	[dict setValue:@button1 forKey:[NSString stringWithFormat:@%x,  
button1]];		// button1 is one of my IBOutlets.

}

When a user clicks the button the following method fires and promptly  
crashes my app.


- (void)buttonClicked:(id)sender
{
// Print out the value for the button pressed.  THIS LINE CRASHES
	NSString *value = [dict valueForKey:[NSString stringWithFormat:@%x,  
sender]];


//This next line crashes app - EXC_BAD_ACCESS
NSLog(@Value is: %@, value);
}

It seems like the memory address of the sender is different than what  
it should be.  I did some debugging and the address of the sender is  
always bfffe2e8 which really shouldn't be possible at all.


Any ideas?  As always, thanks in advance.


___

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: Question Regarding the Memory Address of Objects

2008-12-18 Thread Carter R. Harrison


On Dec 18, 2008, at 3:44 PM, David Duncan wrote:


On Dec 18, 2008, at 11:57 AM, Carter R. Harrison wrote:

	[dict setValue:@button1 forKey:[NSString stringWithFormat:@%x,  
button1]];		// button1 is one of my IBOutlets.
	NSString *value = [dict valueForKey:[NSString  
stringWithFormat:@%x, sender]];


It seems like the memory address of the sender is different than  
what it should be.  I did some debugging and the address of the  
sender is always bfffe2e8 which really shouldn't be possible at all.



Your confusing the pointer with the object itself. button1 is a  
pointer to a button. sender is a pointer to the object that sent the  
message. When you take the address of either pointer, you get the  
location of that pointer in memory - not the location of the object.  
The pointer itself contains the location of the object in memory.

--
David Duncan
Apple DTS Animation and Printing



David,

Once again you have saved me from pulling my hair out.  Thank you once  
again for your assistance.  For the rest of the folks on the thread  
the solution was to remove the  from the front of all my pointers.


Regards,
Carter
___

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


Storing values in dictionary with their address as the key

2008-07-28 Thread Carter R. Harrison

Hey Everybody,

If I wanted to store an object in a dictionary and set its key as the  
object's memory address - how would I go about doing this?


Right now I'm doing this:

int i;
for (i = 0 ; i   10 ; i++)
{
NSObject *myObject = [[NSObject alloc] init];
[dictionary setValue:myObject forKey:[NSString stringWithFormat:@%x,  
myObject]];

}

The above does seem to work, but the memory address that I get always  
seems to be the same.


Any ideas?
___

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: Event-Driven XML Parsing and Entity References

2008-07-28 Thread Carter R. Harrison


On Jul 27, 2008, at 5:13 PM, Nathan Kinsinger wrote:



On Jul 27, 2008, at 12:52 PM, Carter R. Harrison wrote:

There's been some discussion on this topic previously, but I  
haven't been able to find the solution that I'm looking for.  I'm  
using the event-driven XML parser (CFXMLParser).  Apparently it  
does not support the replacement of entity references (amp, lt,  
gt, etc..).

So assume I'm trying to parse the following XML tag:

titlePlanes, Trains, amp Automobiles/title

When the parser enters the title node, it calls the  
createStructure callback function three times.  Each time it has  
the following data within the node that is passed in:


Call #1: Planes, Trains, 
Call #2: amp
Call #3:  Automobiles

A similar thing happens in the addChild callback function.

I understand that I need to do manual replacement of the amp with  
a  in this case, but I still don't understand how I'm supposed  
to maintain the state in between the three calls to createStructure  
and addChild so that I can successfully concatenate all three text  
segments together to form the original string (which is what I want  
to store).  I hope this makes sense - it's terribly frustrating.


As always, thanks in advance.


I haven't used CFXMLParser, but generally in event xml parsing you  
keep adding to the string until the end of the element. Parsers may  
break the element up into several parts and give them to you one at  
a time.


Ya, I finally got fed up with the Core Foundation parser and switched  
to the Cocoa Event Driven parser.  The cocoa parser works like you  
have just mentioned, but after going through all the Docs on the Core  
Foundation parser it appears to be different.  I don't know why I  
didn't go with Cocoa in the first place.  As soon as I decided to use  
the cocoa parser I had everything working perfectly within 3 minutes!   
Thanks for the help.





In this case in either your addChild or createStructure functions  
you would add the new parsed string to the child nodes existing  
string.


You may find more people with experience using CFXMLParser on the  
Carbon dev list:

http://lists.apple.com/mailman/listinfo/carbon-dev

That said, this is the Cocoa dev list, have you looked at NSXMLParser?
http://developer.apple.com/documentation/Cocoa/Conceptual/XMLParsing/XMLParsing.html

--Nathan




___

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: Storing values in dictionary with their address as the key

2008-07-28 Thread Carter R. Harrison


On Jul 28, 2008, at 3:24 PM, David Wilson wrote:


On Mon, Jul 28, 2008 at 2:13 PM, Carter R. Harrison
[EMAIL PROTECTED] wrote:

Hey Everybody,

If I wanted to store an object in a dictionary and set its key as the
object's memory address - how would I go about doing this?

Right now I'm doing this:

int i;
for (i = 0 ; i   10 ; i++)
{
NSObject *myObject = [[NSObject alloc] init];
[dictionary setValue:myObject forKey:[NSString  
stringWithFormat:@%x,

myObject]];
}



Use:

int i;
for (i=0;i10;i++)
{
NSObject *myObject = [[NSObject alloc] init];
NSValue *val = [NSValue valueWithPointer:myObject];
[dictionary setValue:myObject forKey:val];
}

Or [NSNumber numberWithInt:(int)myObject] instead of the NSValue.



Interesting.. thanks for the solution.  Naturally almost immediately  
after I sent my original question to the list I figured out what was  
wrong with my solution.  The issue was with the format string..  
Instead of a %x, I needed a %qx.  The %qx displays a 64 bit address  
whereas the %x displays a 32 bit address.  When you give %x, only the  
least significant 32 bits are printed and those happen to always be  
the same (at least in my case).




--
- David T. Wilson
[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: Storing values in dictionary with their address as the key

2008-07-28 Thread Carter R. Harrison


On Jul 28, 2008, at 3:24 PM, David Wilson wrote:


On Mon, Jul 28, 2008 at 2:13 PM, Carter R. Harrison
[EMAIL PROTECTED] wrote:

Hey Everybody,

If I wanted to store an object in a dictionary and set its key as the
object's memory address - how would I go about doing this?

Right now I'm doing this:

int i;
for (i = 0 ; i   10 ; i++)
{
NSObject *myObject = [[NSObject alloc] init];
[dictionary setValue:myObject forKey:[NSString  
stringWithFormat:@%x,

myObject]];
}



Use:

int i;
for (i=0;i10;i++)
{
NSObject *myObject = [[NSObject alloc] init];
NSValue *val = [NSValue valueWithPointer:myObject];
[dictionary setValue:myObject forKey:val];
}

Or [NSNumber numberWithInt:(int)myObject] instead of the NSValue.



Actually now that I'm looking at this more closely, NSDictionary is  
expecting an NSString for the key when inserting a value.  Your  
example uses an NSValue for the key - the compiler is throwing a  
warning for this one..




--
- David T. Wilson
[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]


Compiler doesn't see instance variable

2008-07-27 Thread Carter R. Harrison
I'm having an interesting problem today.  I'm working with the event- 
driven XML parser in Core Foundation.  For those of you who aren't  
familiar with that parser, you have to implement at least 3 callback  
methods:


void *createStructure(CFXMLParserRef parser, CFXMLNodeRef node, void  
*info)
void addChild(CFXMLParserRef parser, void *parent, void *child, void  
*info)

void endStructure(CFXMLParserRef parser, void *xmlType, void *info)

Inside the addChild method, I attempt to access an instance variable  
that is defined within the header file for the source file in which  
the callback methods are defined.  For some reason the compiler is  
unable to see my instance variables when referenced from these  
methods.  The compiler gives me a error: 'parseArray' undeclared  
(first use in this function).


Any ideas as to what I'm doing wrong?  Thanks in advance.
___

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]


Event-Driven XML Parsing and Entity References

2008-07-27 Thread Carter R. Harrison
There's been some discussion on this topic previously, but I haven't  
been able to find the solution that I'm looking for.  I'm using the  
event-driven XML parser (CFXMLParser).  Apparently it does not support  
the replacement of entity references (amp, lt, gt, etc..).

So assume I'm trying to parse the following XML tag:

titlePlanes, Trains, amp Automobiles/title

When the parser enters the title node, it calls the createStructure  
callback function three times.  Each time it has the following data  
within the node that is passed in:


Call #1: Planes, Trains, 
Call #2: amp
Call #3:  Automobiles

A similar thing happens in the addChild callback function.

I understand that I need to do manual replacement of the amp with a  
 in this case, but I still don't understand how I'm supposed to  
maintain the state in between the three calls to createStructure and  
addChild so that I can successfully concatenate all three text  
segments together to form the original string (which is what I want to  
store).  I hope this makes sense - it's terribly frustrating.


As always, thanks in advance.
___

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]


#define and #ifdef statements for different build configs

2008-07-11 Thread Carter R. Harrison
I have an app that uses different frameworks and method calls based  
upon the currently selected build configuration.


How can I easily setup an #ifdef statement that will only execute if  
I've chosen the Release build configuraiton?


Thanks in advance.
___

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]


Weird Problem With CGImage

2008-04-25 Thread Carter R. Harrison
This bug in my code has been driving me nuts for days, but I have  
finally isolated the issue - only problem now is I don't understand  
what I'm doing wrong.


I have a CGImage that I want to get the raw data bytes for.  My code  
is below:


CGImageRef sectionToCache = CGImageCreateWithImageInRect(backingStore,  
CGRectMake(x, y, cx, cy));
NSLog(@CGImage to cache has dimensions %d x %d and %d bytes per row,  
CGImageGetWidth(sectionToCache), CGImageGetHeight(sectionToCache),  
CGImageGetBytesPerRow(sectionToCache));
CFDataRef dataRef =  
CGDataProviderCopyData(CGImageGetDataProvider(sectionToCache));

NSLog(@Length of cachedImage data: %d, CFDataGetLength(dataRef));

When the code runs, the log spits out the following:

CGImage to cache has dimensions 417 x 234 and 1668 bytes per row
Length of cachedImage data: 6672

What is killing me here is that the CGImage has dimensions 417x234 and  
1668 bytes per row.  That to me means that the CFDataRef that I am  
obtaining should be 390,312 bytes (234 x 1668).  But the CFDataRef is  
only 6,672 bytes which is nowhere close to what I think I should be  
getting.  So I must be doing something wrong in trying to get the  
bitmap data, but I'm not sure what else to do and I even found some  
Apple docs with an example doing the exact same thing that I am  
doing.  Can anybody provide some insight on this?  Thanks everybody.

___

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: Weird Problem With CGImage

2008-04-25 Thread Carter R. Harrison


On Apr 25, 2008, at 12:12 PM, David Duncan wrote:


On Apr 25, 2008, at 7:51 AM, Carter R. Harrison wrote:

This bug in my code has been driving me nuts for days, but I have  
finally isolated the issue - only problem now is I don't understand  
what I'm doing wrong.


I have a CGImage that I want to get the raw data bytes for.  My  
code is below:


CGImageRef sectionToCache =  
CGImageCreateWithImageInRect(backingStore, CGRectMake(x, y, cx, cy));
NSLog(@CGImage to cache has dimensions %d x %d and %d bytes per  
row, CGImageGetWidth(sectionToCache),  
CGImageGetHeight(sectionToCache),  
CGImageGetBytesPerRow(sectionToCache));
CFDataRef dataRef =  
CGDataProviderCopyData(CGImageGetDataProvider(sectionToCache));

NSLog(@Length of cachedImage data: %d, CFDataGetLength(dataRef));

When the code runs, the log spits out the following:

CGImage to cache has dimensions 417 x 234 and 1668 bytes per row
Length of cachedImage data: 6672

What is killing me here is that the CGImage has dimensions 417x234  
and 1668 bytes per row.  That to me means that the CFDataRef that I  
am obtaining should be 390,312 bytes (234 x 1668).  But the  
CFDataRef is only 6,672 bytes which is nowhere close to what I  
think I should be getting.  So I must be doing something wrong in  
trying to get the bitmap data, but I'm not sure what else to do and  
I even found some Apple docs with an example doing the exact same  
thing that I am doing.  Can anybody provide some insight on this?   
Thanks everybody.


This seems to be related to the CGImageCreateWithImageInRect() call,  
but I can't imagine why. CGDataProviderCopyData() seems to work  
perfectly with an original image in my limited testing, so please  
file a bug (and let me know what the bug number is).


	Thanks David.  The bug number is 5889934.  For the time being I will  
use the workaround provided by an earlier poster.


--
David Duncan
Apple DTS Animation and Printing
[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]


Bitmap data from CGImageRef

2008-04-18 Thread Carter R. Harrison

Hey everybody,

Is it possible to obtain the raw bitmap data from a CGImageRef?  Thanks.

Regards,
Carter
___

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: Bitmap data from CGImageRef

2008-04-18 Thread Carter R. Harrison
Thanks Adam..  For some reason I cannot seem to find  
CGDataProviderCopyData in the Apple docs.  I can search for it at the  
ADC, and it returns the page for CGDataProvider as the first hit, but  
once you go to that page, there is absolutely no reference to  
CGDataProviderCopyData.  Strange.



On Apr 18, 2008, at 2:49 PM, Adam R. Maxwell wrote:



On Friday, April 18, 2008, at 11:40AM, Adam R. Maxwell [EMAIL PROTECTED] 
 wrote:


On Friday, April 18, 2008, at 11:32AM, Carter R. Harrison [EMAIL PROTECTED] 
 wrote:

Hey everybody,

Is it possible to obtain the raw bitmap data from a CGImageRef?   
Thanks.


CGImageGetDataProvider and CGImageProviderCopyData should do what  
you want.


That second call should of course be CGDataProviderCopyData...  sorry.

--
adam


___

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: Bitmap data from CGImageRef

2008-04-18 Thread Carter R. Harrison
Surprisingly, if you go to Xcode Documentation you can find the method  
that Adam first mentioned, but it is not on the ADC website.


Thanks Scott.


On Apr 18, 2008, at 3:05 PM, Scott Thompson wrote:



On Apr 18, 2008, at 1:54 PM, Carter R. Harrison wrote:

Thanks Adam..  For some reason I cannot seem to find  
CGDataProviderCopyData in the Apple docs.  I can search for it at  
the ADC, and it returns the page for CGDataProvider as the first  
hit, but once you go to that page, there is absolutely no reference  
to CGDataProviderCopyData.  Strange.


There was another thread on quartz-dev that noted that.  Someone at  
Apple said they would look into it. FWIW.


Scott



___

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]


CGBitmapRef and User Space Coordinates

2008-04-15 Thread Carter R. Harrison

Hi All,

I have a CGBitmapRef that I am using as a backing store for my NSView  
subclass.  The CGBitmapRef has the same dimensions as my NSView.  Each  
time I draw to the backing store, I call my view's  
setNeedsDisplayInRect: method to invalidate the area in which I have  
drawn.  Is it necessary to convert the rectangle to which I have drawn  
into user space coordinates before feeding them into  
setNeedsDisplayInRect:?  It seems like I can get away without doing  
this because my view is the same size as the backing store, but I'm  
getting some weird behavior (things drawing correctly but in the wrong  
area).  Thanks in advance.


-Carter
___

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: EXC_BAD_ACCESS when calling CGContextDrawLayerInRect

2008-04-14 Thread Carter R. Harrison
cgback is a CGLayerRef instance variable that I setup when the view is  
inited.  I use the following line:


cgback = CGLayerCreateWithContext(context, CGSizeMake([self  
bounds].size.width, [self bounds].size.height), NULL);


It's my understanding that I do not need to retain cgback with  
CFRetain(), but I do need to release cgback in my dealloc() method -  
which I'm doing.



On Apr 14, 2008, at 12:02 PM, Nathan Vander Wilt wrote:


On Apr 13, 2008, at 7:15 AM, Carter R. Harrison wrote:
CGContextRef context = [[NSGraphicsContext currentContext]  
graphicsPort];
CGContextDrawLayerInRect(context, CGRectMake([self frame].origin.x,  
[self frame].origin.y, [self frame].size.width, [self  
frame].size.height), cgback);


cgback is a instance variable pointing to a CGLayer.

So my code works, the correct things are being drawn to my view  
(more or less), but what happens is that after several seconds of  
use, the app crashes and I get an EXC_BAD_ACCESS error.



Can you post more information regarding your cgback variable? How is  
it being allocated? That parameter seems to be the most likely  
culprit.


-nvw


___

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: EXC_BAD_ACCESS when calling CGContextDrawLayerInRect

2008-04-14 Thread Carter R. Harrison

Hi David,

I'm getting the reference to the context by using:

CGContextRef context = [[NSGraphicsContext currentContext]  
graphicsPort];


in my view's initWithFrame: method.  Based upon what you said, how  
would you recommend I draw to a CGLayer prior to the first invocation  
of drawRect: (at which point I could initialize a CGContextRef  
instance variable)?


Thanks for your help!

Regards,
Carter

On Apr 14, 2008, at 3:30 PM, David Duncan wrote:


On Apr 14, 2008, at 11:56 AM, Carter R. Harrison wrote:

cgback is a CGLayerRef instance variable that I setup when the view  
is inited.  I use the following line:


cgback = CGLayerCreateWithContext(context, CGSizeMake([self  
bounds].size.width, [self bounds].size.height), NULL);


It's my understanding that I do not need to retain cgback with  
CFRetain(), but I do need to release cgback in my dealloc() method  
- which I'm doing.



Where is context coming from? CGLayers are made relative to an  
example context that they optimize themselves for, but at -init your  
view hasn't been drawn yet, so there is no context. I suspect that  
your getting something you very much do not expect.


In general if you want to use layers with views, you should create  
the layer on the first -drawRect: call rather than trying to have  
them around from -init forward.

--
David Duncan
Apple DTS Animation and Printing
[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]


EXC_BAD_ACCESS when calling CGContextDrawLayerInRect

2008-04-13 Thread Carter R. Harrison

Hi Everybody,

I'm delving into Quartz 2D programming for the first time so this is  
probably a newb issue, but either way I'm stumped.  I have a  
controller that is calling several custom drawing methods in my custom  
view.  The drawing methods call Quartz and tell it to draw various  
things to a CGLayer reference.  My drawRect: method of the custom view  
is responsible for taking the CGLayer and drawing it to the view.  To  
do this I'm using the CGContextDrawLayerInRect method of CGLayer:


CGContextRef context = [[NSGraphicsContext currentContext]  
graphicsPort];
CGContextDrawLayerInRect(context, CGRectMake([self frame].origin.x,  
[self frame].origin.y, [self frame].size.width, [self  
frame].size.height), cgback);


cgback is a instance variable pointing to a CGLayer.

So my code works, the correct things are being drawn to my view (more  
or less), but what happens is that after several seconds of use, the  
app crashes and I get an EXC_BAD_ACCESS error.  I know that this means  
somewhere a variable was freed and I'm still trying to access it, but  
the error is occurring within CGContextDrawLayerInRect and I have no  
way of knowing exactly what variable this is since I don't have the  
source.  I'm not explicitly freeing any of the variables that are  
being passed into CGContextDrawLayerInRect.  So I'm really at a loss.   
Has anybody experienced anything like this before?  Here is my stack  
trace.  Thanks everybody!


#0  0x08a0 in __memcpy
#1  0x924aacdf in CGAccessSessionGetBytes
#2  0x925141dc in partial_get_bytes
#3  0x92513f8f in CGAccessSessionGetChunks
#4  0x924b8759 in img_raw_read
#5  0x92471481 in img_data_lock
#6  0x9246f529 in CGSImageDataLock
#7  0x92b085ef in ripc_AcquireImage
#8  0x92af6d4f in ripc_DrawImage
#9  0x92890ce4 in dle_ExecuteDisplayList
#10 0x92892511 in dle_Execute
#11 0x92892a2d in CGDisplayListDelegateDrawDisplayList
#12 0x928932c6 in dlr_DrawLayer
#13 0x92515204 in CGContextDrawLayerInRect
#14 0x00036f89 in -[RDCView drawRect:] at RDCView.m:129



___

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]


NSCompositeSourceOver equivalent in Quartz 2D?

2008-04-13 Thread Carter R. Harrison
I'm trying to do some drawing in Quartz 2D.  I'm trying to set the  
blending mode of my CGContextRef to the equivalent of  
NSCompositeSourceOver from NSGraphicsContext.  It doesn't look like  
there is such a blending mode for a CGContext.  Am I mistaken in this,  
or is there another way of accomplishing this?  It seems funny to me  
that this blending mode doesn't exist in Quartz given that  
NSGraphicsContext should be a wrapper class around CGContextRef.


Thanks in advance.
___

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]