Re: Arg, lmao question - (int)getters/setters.

2008-12-22 Thread Roland King
it looks as if you your class variable someInt declared as (int*), why? 
If you want an int, someInt should be declared as an int.


aaron smith wrote:


Sorry for the total newb here. What's the right way to create
getters/setters for int's? Without the compiler warning about them?

I've been trying:

-(void)setSomeInt:(int)theInt
{
   someInt=theInt;
}

-(int)someInt
{
   return someInt;
}

Then calling it..
[myObj setSomeInt:1];

Usually I get two warnings:
"warning: assignment makes pointer from integer without cast"
"warning: return makes integer from pointer without cast"


From those two warnings, I was thinking these updates do the trick:


-(void)setSomeInt:(int)theInt
{
   someInt=(int *)theInt;
}

-(int)someInt
{
   return (int)someInt;
}

Calling it:
[myObj setSomeInt:(int *)1];

Is this the correct way?
Thanks all..
___

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/rols%40rols.org

This email sent to r...@rols.org
 



___

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


Arg, lmao question - (int)getters/setters.

2008-12-22 Thread aaron smith
Sorry for the total newb here. What's the right way to create
getters/setters for int's? Without the compiler warning about them?

I've been trying:

-(void)setSomeInt:(int)theInt
{
someInt=theInt;
}

-(int)someInt
{
return someInt;
}

Then calling it..
[myObj setSomeInt:1];

Usually I get two warnings:
"warning: assignment makes pointer from integer without cast"
"warning: return makes integer from pointer without cast"

>From those two warnings, I was thinking these updates do the trick:

-(void)setSomeInt:(int)theInt
{
someInt=(int *)theInt;
}

-(int)someInt
{
return (int)someInt;
}

Calling it:
[myObj setSomeInt:(int *)1];

Is this the correct way?
Thanks all..
___

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: Saving the project

2008-12-22 Thread Mahaboob

Thanks for the help,
Now it is working well with the menu item's action. I also need to perform
the same thing when I'm clicking the close button of the window. I gone
through the NSWindow documentation but, I'm unable to figure it out to
perform close event of the window. How can I fire close event?

On 12/22/08 5:36 PM, "Mike Abdullah"  wrote:

> Either NSWindow or NSWindowController have a -setDocumentEdited:
> method that will do what you want.
> 
> On 22 Dec 2008, at 11:39, Mahaboob wrote:
> 
>> In my app I used NSTextView as editor and saves my project along
>> with the
>> contents of editor by using archiving and also I can open the saved
>> project.
>> Now I need to show a bubble in the close button when I'm making any
>> changes
>> in the editor. How can I show the bubble? How can I notify when the
>> editor
>> get edited?
>> 
>> Thanks in advance
>> mahaboob
>> 
>> 
>> ___
>> 
>> 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/cocoadev%40mikeabdullah.net
>> 
>> This email sent to cocoa...@mikeabdullah.net
> 


___

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: iTunes Plug-in

2008-12-22 Thread Andrew Farmer

On 22 Dec 08, at 15:05, Neil wrote:

Is there a way to make a plug-in for iTunes that adds another "tab" to
the sidebar?  (ie. where the Music, Movies, Podcasts, and all the
playlists are...)

If so, does anyone have some pointers to some documentation on it?
I've spent the last 1.5 hours hunting around for something like that,
and haven't been able to find neither an app that does it nor any
docs...  (The closest I found were some apps that added
"visualizations" which weren't really visualizations...)


No. iTunes currently only uses plugins for additional visualizers;  
there is no provision for extending it in other ways.

___

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: observeValueForKeyPath and how to do it right

2008-12-22 Thread Ken Thomases

On Dec 22, 2008, at 10:19 PM, Chris Idou wrote:


--- On Mon, 22/12/08, Ken Thomases  wrote:


On Dec 22, 2008, at 8:19 PM, Chris Idou wrote:

I've got a NSTableView controlled by a NSArrayController using  
content set binding. One of the columns is a checkbox, and I need  
to take some action when the user changes the value, but I don't  
want to put the code in the actual object, because it would be  
beyond the concerns of this object to deal with all that.


So what is the right way to go about this?


Sometimes the old ways are best.

Use target-action.  Control drag from the cell to your
controller and hook it up to an action method.


How do I then find out which object was clicked?


The argument passed to the action method will be the table view.  You  
can invoke -clickedRow on it to figure out what row's checkbox was  
clicked.  Then, you can use that to index into the array controller's  
arrangedObjects.


Regards,
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: NSSpeechSynthesizer rate

2008-12-22 Thread Ron Fleckner


On 23/12/2008, at 5:26 AM, Reema Sardana wrote:

Is there any range within which the values returned by the method  
rate() of
the class NSSpeechSynthesizer lie? I see that the volume is always  
between

0.0 and 1.0.

--
Reema
http://www1.reemasardana.com/


Hmm... I see that the values for rate aren't in the new docs for  
NSSpeechSynthesizer in Leopard.  The ability to set the rate wasn't  
present in this API until Leopard.  In the Carbon docs it says:


soRate
Get or set a speech channel’s speech rate. The speechInfo parameter is  
a pointer to a variable of type Fixed. The possible range of speech  
rates is from 0.000 to 65535.65535. The range of supported rates is  
not predefined by the Speech Synthesis Manager; each speech  
synthesizer provides its own range of speech rates. Average human  
speech occurs at a rate of 180 to 220 words per minute.


This selector works with both the GetSpeechInfo and SetSpeechInfo  
functions and does not move memory.


Available in Mac OS X v10.0 and later.



I used the Carbon framework in my app.

Hope that helps.

Ron___

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


Notification when NSPersistentDocument done loading model

2008-12-22 Thread PHILIP GRANDINETTI
I'm using a Core Data model and letting NSPersistentDocument manage the task of 
finding and loading the application's model.   My model contains data that I am 
displaying in a graph (SM2DGraphView)   A problem I'm having is that once the 
model data is done loading I want to send a refresh message to the graph. 
So, I put the refresh message at the end of the document's  initWithType:error: 
 but this seems to be too early in the process and when the refresh asks the 
NSArrayController bound to the data, it says it is empty, that is, canRemove 
returns false.

I tried getting a notification with 
NSManagedObjectContextObjectsDidChangeNotification but this didn't seem to 
work.   I can post the code in case this should have worked, but first I wanted 
to ask if there might be a simpler approach?

Thanks,

Philip

___

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


iTunes Plug-in

2008-12-22 Thread Neil
Is there a way to make a plug-in for iTunes that adds another "tab" to
the sidebar?  (ie. where the Music, Movies, Podcasts, and all the
playlists are...)

If so, does anyone have some pointers to some documentation on it?
I've spent the last 1.5 hours hunting around for something like that,
and haven't been able to find neither an app that does it nor any
docs...  (The closest I found were some apps that added
"visualizations" which weren't really visualizations...)

Thanks,
Neil.
___

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


NSSpeechSynthesizer rate

2008-12-22 Thread Reema Sardana
Is there any range within which the values returned by the method rate() of
the class NSSpeechSynthesizer lie? I see that the volume is always between
0.0 and 1.0.

-- 
Reema
http://www1.reemasardana.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


Exception on dealloc of NSConcreteProtocolChecker

2008-12-22 Thread yoni shalom
I have two applications communicating via NSConnection and a specific
protocol defined between them.

I'm getting the following exception in the server app randomally and I can't
seem to place a finger why, since the only relation from the exception stack
to my code is the RunLoop run message... (seems like this occurs when a the
client-side is shutting down) :


 NSProtocolChecker: target protocol does not recognize selector:
isKindOfClass: *

**

* __raiseError (in CoreFoundation) + 331*

*objc_exception_throw (in libobjc.A.dylib) + 40*

*+[NSException raise:format:arguments:] (in CoreFoundation) + 155*

*+[NSException raise:format:] (in CoreFoundation) + 58*

*-[NSProtocolChecker doesNotRecognizeSelector:] (in Foundation) + 79*

*___forwarding___ (in CoreFoundation) + 892*

*_CF_forwarding_prep_0 (in CoreFoundation) + 50*

*-[NSProxy isKindOfClass:] (in Foundation) + 160*

*345508823*

*375368454*

*375367910*

*375367836*

*44858610*

*-[NSConcreteProtocolChecker dealloc] (in Foundation) + 75*

*NSPopAutoreleasePool (in Foundation) + 431*

*-[NSConnection handlePortCoder:] (in Foundation) + 1178*

*-[NSConcretePortCoder dispatch] (in Foundation) + 142*

*__NSFireMachPort (in Foundation) + 339*

*__CFMachPortPerform (in CoreFoundation) + 117*

*CFRunLoopRunSpecific (in CoreFoundation) + 3896*

*CFRunLoopRunInMode (in CoreFoundation) + 88*

*-[NSRunLoop(NSRunLoop) runMode:beforeDate:] (in Foundation) + 213*

*-[NSRunLoop(NSRunLoop) run] (in Foundation) + 84*

*-[XXX threadMain:] (in mplayer) (XXX.m:73)*

*-[NSThread main] (in Foundation) + 45*

*__NSThread__main__ (in Foundation) + 308*

*_pthread_start (in libSystem.B.dylib) + 321*

*thread_start (in libSystem.B.dylib) + 34*
___

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


Setting Caps Lock state from the application

2008-12-22 Thread Girish Kolari

Hi All

We have an application in which we post keyboard events using the API
CGError CGPostKeyboardEvent (CGCharCode keyChar, CGKeyCode virtualKey,  
boolean_t keyDown);


API works fine for all the events.

However, we are facing an issue with Caps Lock key.

When we post a synthetic event from our application, the event gets  
posted properly.
However for Capslock, the key state (On/Off state) is not getting set  
to the keyboard.
Hence an inconsistency is observed in the capslock state when a  
synthetic capslock event  intervenes

with the hardware event(manually pressing capslock key).

Is there any way to set the state of the capslock key to the keyboard  
from the application?


Any help would be greatly appreciated.
Thanks in advance.

Please let me know If I have to post this query in a different mailing  
list.


Regards,
Girish Kolari
___

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: os x gui scripting

2008-12-22 Thread Luca Cioria
If you say so.. but for example how would you click at specified coordinates
in applescript? or get a pixel color?
Of course, if an app is scriptable I use appscpt or automator, but in many
case, even websites, I have to follow this path.
thanks

Luca

On Mon, Dec 22, 2008 at 8:53 AM, Andrew Farmer  wrote:

> On 21 Dec 08, at 06:47, Luca Cioria wrote:
>
>> First, I know little of os x programming since I bought my mac 2 weeks
>> ago.
>>
>> I'd like to develop a set of command line tools that do gui scripting
>> stuff.
>> Some examples:
>>
>> click --> clicks the mouse at x y coordinates, optionally relative to
>> current window, can be single click, double click, right, middle,
>> mouse-down
>> only (no releasing) etc. etc.
>> getPixel --> get the color of a pixel on the screen at x y coordinates,
>> optionally relative to current window.
>> send --> sends keystrokes
>> winActivare --> activate a specified window
>>
>
> What you're looking for here is AppleScript. The AppleScript component "GUI
> Scripting" has most of the low-level gunk you're looking for, as well as a
> lot of higher-level functionality (clicking specified buttons or views).
> Scriptable applications can be manipulated in much better ways - TextEdit,
> for example, will let you do stuff like
>
>tell application "TextEdit"
>set word 3 of paragraph 1 of text of document of front window to
> "know"
>end tell
>
> Although most of this functionality *is* accessible through Cocoa, it's a
> lot more awkward to get at that way, and there's no real advantage to doing
> so. If all you're after is an equivalent to AHK, AppleScript is the way to
> go.
> ___
>
> 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/l.cioria%40gmail.com
>
> This email sent to l.cio...@gmail.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: Xcode Question

2008-12-22 Thread Marcelo Cicconet
Hi.These are those I use frequently:

COMMAND+SHIFT+Y: view debugger
COMMAND+0: view Xcode main window
COMMAND+ENTER: build and go
COMMAND+OPTION+A: add to project
OPTION-[DOUBLE CLICK] over a word: find the word in xcode documentation
COMMAND-[DOUBLE CLICK] over a word: find the word in header file or class
implementation

Marcelo C.

On Sun, Dec 21, 2008 at 11:27 PM, Boon Chew  wrote:

> Hi all, I am starting to develop heavily in XCode, and would like to find
> out what keyboard shortcuts you use most frequently (or you find to be most
> useful to know)?
>
> Also, is there a way to jump quickly between matching [ ]? (so I can easily
> nest more messages when I need to)
>
> Thanks.
>
> - boon
>
>
>
>
>
> ___
>
> 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/cicconet%40gmail.com
>
> This email sent to cicco...@gmail.com
>



-- 
KEEP WORKING
___

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: observeValueForKeyPath and how to do it right

2008-12-22 Thread Chris Idou


--- On Mon, 22/12/08, Ken Thomases  wrote:

> From: Ken Thomases 
> Subject: Re: observeValueForKeyPath and how to do it right
> To: "Chris Idou" 
> Cc: cocoa-dev@lists.apple.com
> Received: Monday, 22 December, 2008, 6:36 PM
> On Dec 22, 2008, at 8:19 PM, Chris
> Idou wrote:
> 
> > I've got a NSTableView controlled by a
> NSArrayController using content set binding. One of the
> columns is a checkbox, and I need to take some action when
> the user changes the value, but I don't want to put the code
> in the actual object, because it would be beyond the
> concerns of this object to deal with all that.
> > 
> > So what is the right way to go about this?
> 
> Sometimes the old ways are best.
> 
> Use target-action.  Control drag from the cell to your
> controller and hook it up to an action method.

How do I then find out which object was clicked?


 


  Stay connected to the people that matter most with a smarter inbox. Take 
a look http://au.docs.yahoo.com/mail/smarterinbox
___

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: Configuring NSNumberFormatter non-programmatically

2008-12-22 Thread Nathan Kinsinger

On Dec 22, 2008, at 9:11 AM, Avery Nickelby wrote:


I've looked through the archives and the documentation; most of the
information is related to using NSNumberFormatter programatically. I  
am

looking for a good explanation for using 10.4 style data formatters in
Interface Builder; when I configure a number data formatter I can  
only get
one of two behaviors (I've tried different permutations of the  
switches in

IB):
1) User MUST type in a currency symbol before the field accepts  
input. The

information is displayed as $123.45.
2) The user doesn't type in a currency symbol. The information is just
displayed in decimal format (123.45)

I want: The user types in a number. The formatter looks up the  
appropriate

currency symbol tied to the user-defined default locale and displays a
locale-specific format.

How do I get this behavior? Do I need to revert to the old style  
(which I

can get to work)?

Thanks

Avery


Unfortunately, the 10.4 formatter will not do what you want using IB  
only.


If you put the following method in your controller and set it as the  
delegate of the NSTextField, it will add the currency symbol when the  
user tab/enter/return/clicks out of the field. Basically, it tells the  
formatter to format the number in the NSTextField's string (why it  
can't do that itself I'm not sure), but only if the currency symbol is  
not already there.


- (BOOL)control:(NSControl *)control didFailToFormatString:(NSString  
*)string errorDescription:(NSString *)error

{   
if ([[control formatter] isKindOfClass:[NSNumberFormatter class]])
{
NSNumberFormatter *formatter = [control formatter];

		if ([formatter numberStyle] == NSNumberFormatterCurrencyStyle && ! 
[string hasPrefix:[formatter currencySymbol]])

{
			[control setStringValue:[formatter stringFromNumber:[NSNumber  
numberWithDouble:[string doubleValue;

}
}

return YES;
}

-- 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 arch...@mail-archive.com


Re: NSString property: copy or retain?

2008-12-22 Thread Clark Cox
On Mon, Dec 22, 2008 at 5:41 PM, Ricky Sharp  wrote:
>
> On Dec 22, 2008, at 4:04 PM, Debajit Adhikary wrote:
>
>> Let's say I have a class called SomeClass with a string property name:
>>
>> @interface SomeClass : NSObject{
>>   NSString* name;
>> }
>>
>> @property (nonatomic, retain) NSString* name;
>>
>> @end
>>
>> I understand that name may be assigned a NSMutableString in which case
>> this
>> will may to errant behavior.
>>
>> (1) For strings in general, is it *always* a good idea to use the "copy"
>> attribute instead of "retain"?
>
> No.  This isn't a "one way or another" situation.  It's really up to what
> you need.  Having said that, there are good guidelines as to why you'd want
> to use one over the other.  Look at the memory-management guidelines or
> search the archives.

There is rarely a reason to define an NSString accessor as retain
instead of copy. I would argue that, unless you have an especially
good reason, NSString attributes (as well as NSData, NSDictionary,
NSArray, and any other foundation class that has a mutable counterpart
and implements the NSCopying protocol) should be declared as "copy",
not "retain".

>> (2) Is a "copied" attribute in any way less efficient than such a
>> "retain-ed" attribute?
>
> Definitely.  It will cost more cycles to copy the object vs. retain it.
>  And, will use more memory.  However, the performance and memory costs may
> not have any noticeable impact on your code.  A profiler can tell you for
> sure.

This is not true. For objects like NSString, -copy and -retain are
100% equivalent, and when an NSMutableString instance is passed in,
copy is almost always the right thing to use (as it maintains proper
encapsulation).

-- 
Clark S. Cox III
clarkc...@gmail.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: Core DataTableView Column Sort at launch with bindings?

2008-12-22 Thread vince
I got this working:
I placed the following in my windowControllerDidLoadNib method:

NSSortDescriptor * sorter = [[NSSortDescriptor alloc] initWithKey:@"nameColumn"
ascending:YES];

[myArrayController setSortDescriptors:[NSArray arrayWithObject:sorter]];


I set the table sorting properties to:

Ascending

Sort Key: nameColumn

Selector: caseInsensitiveCompare:


Now the column Header is selected when the application starts up and the
nameColumn remains sorted in ascending order.

-v.







On Mon, Dec 22, 2008 at 4:12 PM, vince  wrote:

> Thanks for the help ...
> Is it possible to set up my Core Data doc application's Bindings so that
> upon launch my mainColumn header is selected and the column is pre-sorted
> (ascending) without implementing code?
>
> thanks again.
>
> vince.
>
>
>
>
>
>
___

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: observeValueForKeyPath and how to do it right

2008-12-22 Thread Ken Thomases

On Dec 22, 2008, at 8:19 PM, Chris Idou wrote:

I've got a NSTableView controlled by a NSArrayController using  
content set binding. One of the columns is a checkbox, and I need to  
take some action when the user changes the value, but I don't want  
to put the code in the actual object, because it would be beyond the  
concerns of this object to deal with all that.


So what is the right way to go about this?


Sometimes the old ways are best.

Use target-action.  Control drag from the cell to your controller and  
hook it up to an action method.


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


observeValueForKeyPath and how to do it right

2008-12-22 Thread Chris Idou
I've got a NSTableView controlled by a NSArrayController using content set 
binding. One of the columns is a checkbox, and I need to take some action when 
the user changes the value, but I don't want to put the code in the actual 
object, because it would be beyond the concerns of this object to deal with all 
that.

So what is the right way to go about this? Do I need to use 
observeValueForKeyPath on every individual object in the NSArrayController? If 
so, where should I put the code? Should I bind to the contentSet of the object 
whose contentSet the ArrayController is bound to, so I get updated when the 
ArrayController is updated? Or should I also override the add: and remove: 
methods of the ArrayController to add and remove observers individually? If I 
put it in the former, do I need to make sure I'm not observing the same object 
more than once?





  Stay connected to the people that matter most with a smarter inbox. Take 
a look http://au.docs.yahoo.com/mail/smarterinbox
___

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: Replacing objects

2008-12-22 Thread Ken Thomases

On Dec 22, 2008, at 6:55 PM, Mike Abdullah wrote:

No, the whole point is that although the proxy descends from a  
different hierarchy, no-one outside the proxy need know this. All  
other code treats it as though it were a non-proxy object of the  
expected class. Whenever one of the class's methods gets called, the  
proxy object receives a -methodSignatureForSelector: call, followed  
by -forwardInvocation:


Just so everybody knows: for code which will be running on Leopard or  
later, and when you're building a plain forwarding proxy, it is better  
(and simpler) to provide an implementation of the following method  
rather than using -methodSignatureForSelector: and -forwardInvocation:  
for forwarding:


- (id)forwardingTargetForSelector:(SEL)sel;

See the note "New forwarding fast path" in the Foundation release  
notes .


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


Re: Replacing objects

2008-12-22 Thread WT

On Dec 23, 2008, at 1:55 AM, Mike Abdullah wrote:


On 23 Dec 2008, at 00:30, WT wrote:


On Dec 23, 2008, at 1:04 AM, Kyle Sluder wrote:


On Mon, Dec 22, 2008 at 6:03 PM, WT  wrote:

Of course,
the proxy object's class has to share the same interface as the  
class of the
objects it represents so that your code doesn't need to know  
whether it's

dealing with a proxy or with the real thing.


This isn't true in Objective-C.  Take a look at NSProxy, the  
canonical
implementation of the very pattern you're describing.  To state  
this

is to completely miss the characteristics that define Objective-C.


One is not obligated to use NSProxy to implement the Proxy  
pattern. I must admit not being all that familiar with NSProxy,  
but having the proxy and the object it stands for share the same  
public API (by being instances of subclasses of the same abstract  
class) seems to me to be a good thing since the object and its  
proxy can be transparently swapped in code. If I understand  
NSProxy correctly, you lose that transparency when you use it,  
because NSProxy and NSObject are in different inheritance trees.


No, the whole point is that although the proxy descends from a  
different hierarchy, no-one outside the proxy need know this. All  
other code treats it as though it were a non-proxy object of the  
expected class. Whenever one of the class's methods gets called, the  
proxy object receives a -methodSignatureForSelector: call, followed  
by -forwardInvocation:


This saves you having to re-implement and keep up-to-date the entire  
API of your custom class from within the proxy.


Ahh... ok. I see the value in NSProxy now. And I now also understand  
more clearly what Kyle meant by "missing the characteristics that  
define Obj-C".


___

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: Replacing objects

2008-12-22 Thread Shawn Erickson
On Mon, Dec 22, 2008 at 4:30 PM, WT  wrote:

> One is not obligated to use NSProxy to implement the Proxy pattern. I must
> admit not being all that familiar with NSProxy, but having the proxy and the
> object it stands for share the same public API (by being instances of
> subclasses of the same abstract class) seems to me to be a good thing since
> the object and its proxy can be transparently swapped in code. If I
> understand NSProxy correctly, you lose that transparency when you use it,
> because NSProxy and NSObject are in different inheritance trees.

In objective-c any object instance "could" stand in for any other
object as long as it supported the set of messages that would be sent
to it at runtime. No inheritance is needed in this regard.

Also objective-c supports protocols (much like interfaces in Java)
that classes can state they implement ("conforms to"). This allows
disjoint class hierarchies to support the same set of messages with
compile time verification.

An NSProxy sub-class (NSObject for that matter) could be used as a
stand in for any other object instance by leveraging forward
invocation, etc. NSProxy does implement the NSObject protocol so it it
known to act as an NSObject at its core behavior.

-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 arch...@mail-archive.com


Re: Replacing objects

2008-12-22 Thread Mike Abdullah


On 23 Dec 2008, at 00:30, WT wrote:


On Dec 23, 2008, at 1:04 AM, Kyle Sluder wrote:


On Mon, Dec 22, 2008 at 6:03 PM, WT  wrote:

Of course,
the proxy object's class has to share the same interface as the  
class of the
objects it represents so that your code doesn't need to know  
whether it's

dealing with a proxy or with the real thing.


This isn't true in Objective-C.  Take a look at NSProxy, the  
canonical

implementation of the very pattern you're describing.  To state this
is to completely miss the characteristics that define Objective-C.


One is not obligated to use NSProxy to implement the Proxy pattern.  
I must admit not being all that familiar with NSProxy, but having  
the proxy and the object it stands for share the same public API (by  
being instances of subclasses of the same abstract class) seems to  
me to be a good thing since the object and its proxy can be  
transparently swapped in code. If I understand NSProxy correctly,  
you lose that transparency when you use it, because NSProxy and  
NSObject are in different inheritance trees.


No, the whole point is that although the proxy descends from a  
different hierarchy, no-one outside the proxy need know this. All  
other code treats it as though it were a non-proxy object of the  
expected class. Whenever one of the class's methods gets called, the  
proxy object receives a -methodSignatureForSelector: call, followed by  
-forwardInvocation:


This saves you having to re-implement and keep up-to-date the entire  
API of your custom class from within the proxy.


Mike.

P.S. Again, I think this is generally a terrible plan for what the  
O.P. really wants, but is a valuable technique for when you do need a  
proxy object.


___

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: C++ instance variables not destructed if NSZombieEnabled

2008-12-22 Thread Klaus Backert


On 22.12.2008, at 22:54, Greg Parker wrote:


On Dec 22, 2008, at 6:49 AM, Klaus Backert wrote:
In an application of mine I have some Objective-C classes with C++  
instance variables (the Objective-C things own the C++ things). I  
build with the option GCC_OBJC_CALL_CXX_CDTORS = YES, i.e. run non- 
trivial default constructors and destructors on C++ instance  
variables of Objective-C classes.


As long as I do *not* set the environment variable NSZombieEnabled  
to YES, everything works like this: Constructors of C++ instance  
variables have been called when returning from NSObject's init, and  
destructors have been called when returning from NSObject's dealloc.


But if I do set NSZombieEnabled to YES, then the destructors are  
*not* called anymore (by the way, setting NSDeallocateZombies to  
YES or NO does not make a difference).


It's a loophole in the implementation of NSZombie. Sorry. You might  
be able to use Guard Malloc instead (man libgmalloc); it doesn't  
have that destructor problem.


Thank you for this very useful information.

When debugging with Guard Malloc – and without zombies enabled –, the C 
++ destructors are called again indeed. I'm glad.


But, because the slowdown is remarkable – which I expected, because  
man libgmalloc tells about it –, I will not use this all the time  
during debugging, as I did with zombies enabled previously.


Kind regards
Klaus

___

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: Debugging memory smashers with GC

2008-12-22 Thread Rob Keniger


On 23/12/2008, at 10:24 AM, Bill Bumgarner wrote:


Not necessarily.   Any number of things can cause crashes like this:

- trashing memory
- thread mis-synchronization
- something goes awry in the malloc zone

That it never happens under Instruments indicates that it might be a  
threading issue.  Instruments employs some fairly intrusive  
interrogation methods and, thus, causes scheduling to be quite a bit  
different in a running application being interrogated by Instruments.


Interesting. I'm creating one additional thread explicitly and I will  
definitely have a look at that.




I've tried using the MallocStackLoggingNoCompact environment  
variable with malloc_history but my results have been inconclusive  
at best.


What is the best way to go about looking for this type of bug with  
Garbage Collection enabled?


Do you have backtraces from the point of the crash?



I haven't got any that I can post right now, but they are always  
different and very rarely contain my code. I will try and make it  
crash now and report back!


--
Rob Keniger



___

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: Replacing objects

2008-12-22 Thread WT

On Dec 23, 2008, at 1:04 AM, Kyle Sluder wrote:


On Mon, Dec 22, 2008 at 6:03 PM, WT  wrote:

Of course,
the proxy object's class has to share the same interface as the  
class of the
objects it represents so that your code doesn't need to know  
whether it's

dealing with a proxy or with the real thing.


This isn't true in Objective-C.  Take a look at NSProxy, the canonical
implementation of the very pattern you're describing.  To state this
is to completely miss the characteristics that define Objective-C.


One is not obligated to use NSProxy to implement the Proxy pattern. I  
must admit not being all that familiar with NSProxy, but having the  
proxy and the object it stands for share the same public API (by being  
instances of subclasses of the same abstract class) seems to me to be  
a good thing since the object and its proxy can be transparently  
swapped in code. If I understand NSProxy correctly, you lose that  
transparency when you use it, because NSProxy and NSObject are in  
different inheritance trees.



Like Ken said, you're probably doing something very wrong.


Not me, but Dimitri. I agree, though, that his design can be improved  
so he won't need to do what he described.


Wagner
___

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: Debugging memory smashers with GC

2008-12-22 Thread Bill Bumgarner

On Dec 22, 2008, at 4:19 PM, Rob Keniger wrote:
My app is using garbage collection and I'm running into a memory  
smasher bug where the app will crash at seemingly random times, with  
an EXE_BAD_ACCESS.


Obviously there is some reference to an object that is being  
released when I don't want it to be but I'm having a lot of trouble  
tracking it down as it is quite intermittent, so every time I fire  
up Instruments the crash never seems to occur.


Not necessarily.   Any number of things can cause crashes like this:

- trashing memory
- thread mis-synchronization
- something goes awry in the malloc zone

That it never happens under Instruments indicates that it might be a  
threading issue.  Instruments employs some fairly intrusive  
interrogation methods and, thus, causes scheduling to be quite a bit  
different in a running application being interrogated by Instruments.


I've tried using the MallocStackLoggingNoCompact environment  
variable with malloc_history but my results have been inconclusive  
at best.


What is the best way to go about looking for this type of bug with  
Garbage Collection enabled?


Do you have backtraces from the point of the crash?

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 arch...@mail-archive.com


Debugging memory smashers with GC

2008-12-22 Thread Rob Keniger

Hi,

My app is using garbage collection and I'm running into a memory  
smasher bug where the app will crash at seemingly random times, with  
an EXE_BAD_ACCESS.


Obviously there is some reference to an object that is being released  
when I don't want it to be but I'm having a lot of trouble tracking it  
down as it is quite intermittent, so every time I fire up Instruments  
the crash never seems to occur.


I've tried using the MallocStackLoggingNoCompact environment variable  
with malloc_history but my results have been inconclusive at best.


What is the best way to go about looking for this type of bug with  
Garbage Collection enabled?


--
Rob Keniger



___

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: Replacing objects

2008-12-22 Thread Kyle Sluder
On Mon, Dec 22, 2008 at 6:03 PM, WT  wrote:
> Of course,
> the proxy object's class has to share the same interface as the class of the
> objects it represents so that your code doesn't need to know whether it's
> dealing with a proxy or with the real thing.

This isn't true in Objective-C.  Take a look at NSProxy, the canonical
implementation of the very pattern you're describing.  To state this
is to completely miss the characteristics that define Objective-C.

Like Ken said, you're probably doing something very wrong.

--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 arch...@mail-archive.com


Re: NSStream APIs

2008-12-22 Thread Alex Kac
I have - and there are still so many questions with things like the  
HTTP Post CF code I have and that's what I was hoping for something  
more in-depth.



On Dec 22, 2008, at 4:32 PM, Jean-Daniel Dupas wrote:





Le 22 déc. 08 à 19:48, Alex Kac a écrit :

Does anyone have a good tutorial on how to use these? I have to  
admit to being stumped. I have some pre-written code written using  
NSData to send data using CFNetwork and ASyncSocket code and I just  
can't seem to figure out how to get the file stream stuff in there.  
What I would love is not just "sample" code, but perhaps a: here is  
how to do it with NSData and here is the same code with NSStream.




You can check the CFStream documentation.
In the CFNetwork programming guide, there is a section "Using  
stream". http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/Introduction/chapter_1_section_1.html


As NSStream API is just an obj-c wrapper on CFStream, the general  
concepts are the same.




Alex Kac - President and Founder
Web Information Solutions, Inc.

"Forgiveness is not an occasional act: it is a permanent attitude."
-- Dr. Martin Luther King




___

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: selectionShouldChangeInTableView called twice

2008-12-22 Thread Andre Masse


On Dec 22, 2008, at 12:12, Corbin Dunn wrote:


Sorry for the late reply on this, but just to add what others have  
said, and to make more sense of what is going on:


When the selection is changing, the tableview is in the  middle of  
tracking the mouse. It sends out the - 
selectionShouldChangeInTableView: and expects an immediate answer.  
Showing a non-modal dialog (ie: sheet) at this point can cause  
problems that you wouldn't expect, specifically, the tableview needs  
an answer so it can stop processing the mouse event.


So (as others have noted), the best solution is to always save off  
the target selection, present your Save/Cancel UI (if "dirty"), and  
after the UI has closed change the selection to the saved off target  
selection. When your UI is present, you should return NO for  
selectionShouldChange.


We do have a bug logged for this issue of the double-delegate  
calling, but you are always welcome to log a new bug report with  
your test case.


Thanks for the info Corbin.

Andre Masse
___

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: Replacing objects

2008-12-22 Thread WT

Hi Dimitri,

you can make use of the so-called Proxy design pattern. Write all your  
code in terms of a proxy object that stands in for the real thing.  
Then your code doesn't have to know, or care, whether the object  
you're manipulating comes from the server or is local. It's the  
responsibility of the proxy object's class to do the swapping that you  
want.


In other words, you have something like this:

Ptr A -> proxy1
Ptr B -> proxy1
Ptr C -> proxy1

and those pointers never stop pointing to proxy1. Proxy1, however, has  
an internal object that it can swap with something else as needed. Of  
course, the proxy object's class has to share the same interface as  
the class of the objects it represents so that your code doesn't need  
to know whether it's dealing with a proxy or with the real thing.


For more details, look here:
http://en.wikipedia.org/wiki/Proxy_pattern

Wagner

Hey guys, I'm fairly new to cocoa development here, so please bear  
with me. Is it possible to replace an object with another object so  
that all pointers to that object now point to the new object? In  
other words:

Ptr A -> object1
Ptr B -> object1
Ptr C -> object1

I want to replace object1 with another object (of the same type), so  
that all my pointers now point to object2. I realize that I could  
manually replace all of the internal data in the object, thus  
leaving the pointer intact, but I was hoping that there would be an  
easier way.


The reason I'm trying to do this is that I have a number of  
NSMutableArray's throughout my application whose contents are based  
off a database on a server. Periodically, the user searches the  
database, which returns a list of objects. Some of these objects the  
client already has, and in that case I would like to replace the  
local object with the one I've created via the server. I've  
implemented an NSDictionary that holds all of the objects that have  
come in from the server, and each NSMutableArray points to those  
same objects (they are all subsets of the main list). This works  
fine except for in the case where an existing object comes in from  
the server. I'd like to be able to replace the original object with  
my new one and retain all of it's pointers.


Thanks for the help,
Dimitri

___

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: Replacing objects

2008-12-22 Thread Ken Thomases

On Dec 22, 2008, at 4:09 PM, DAS wrote:

Is it possible to replace an object with another object so that all  
pointers

to that object now point to the new object?


No.  There are techniques you can use to achieve something similar,  
but I think the real problem is with your design.  If you're asking  
this question, it means there's something wrong.



The reason I'm trying to do this is that I have a number of  
NSMutableArray's

throughout my application whose contents are based off a database on a
server.


Having these arrays "throughout" your application suggests that you  
haven't got a proper model in your design.


The model is responsible for both holding your data and manipulating  
it according to your app's "business" or "domain" logic.  The model is  
responsible for always presenting a coherent view of your app's or  
document's state.



Periodically, the user searches the database, which returns a list
of objects. Some of these objects the client already has, and in  
that case I
would like to replace the local object with the one I've created via  
the

server.


Updating like this is part of the model responsibilities I described  
above.  It should all happen within the model and under the control of  
the model.  If other parts of your app outside of the model need to  
mirror that data (for example, in a cache) then those other parts need  
to register themselves as observers on the appropriate properties of  
the model so that they will be notified when that data changes.


Regards,
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: NSString property: copy or retain?

2008-12-22 Thread Ken Thomases

On Dec 22, 2008, at 4:04 PM, Debajit Adhikary wrote:


Let's say I have a class called SomeClass with a string property name:

@interface SomeClass : NSObject{
   NSString* name;
}

@property (nonatomic, retain) NSString* name;

@end

I understand that name may be assigned a NSMutableString in which  
case this

will may to errant behavior.

(1) For strings in general, is it *always* a good idea to use the  
"copy"

attribute instead of "retain"?


I would say that it is almost always proper to use the copy attribute  
for a string property.  Merely "retain" means that the property is  
modeling a relationship rather than an attribute.  There might be very  
rare cases where you want to have a relationship with a string, but I  
can't think of any off-hand.



(2) Is a "copied" attribute in any way less efficient than such a
"retain-ed" attribute?


For most of Cocoa's immutable value objects, -copy is equivalent to - 
retain (with perhaps one extra message dispatch).  For mutable value  
objects, -copy makes real copy -- a new immutable object with the same  
value.  This turns out to be exactly when you want a new object,  
because basing one of your attributes on a mutable string provided by  
somebody else opens you up to violations of encapsulation -- your  
object's attributes changing behind its back.


However, you should really stop yourself from thinking about what's  
less efficient until you see evidence of a performance problem and  
analyze the cause.  It's a bad habit that will just cause you to waste  
effort and time.


Regards,
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: NSString property: copy or retain?

2008-12-22 Thread Ricky Sharp


On Dec 22, 2008, at 4:04 PM, Debajit Adhikary wrote:


Let's say I have a class called SomeClass with a string property name:

@interface SomeClass : NSObject{
   NSString* name;
}

@property (nonatomic, retain) NSString* name;

@end

I understand that name may be assigned a NSMutableString in which  
case this

will may to errant behavior.

(1) For strings in general, is it *always* a good idea to use the  
"copy"

attribute instead of "retain"?


No.  This isn't a "one way or another" situation.  It's really up to  
what you need.  Having said that, there are good guidelines as to why  
you'd want to use one over the other.  Look at the memory-management  
guidelines or search the archives.



(2) Is a "copied" attribute in any way less efficient than such a
"retain-ed" attribute?


Definitely.  It will cost more cycles to copy the object vs. retain  
it.  And, will use more memory.  However, the performance and memory  
costs may not have any noticeable impact on your code.  A profiler can  
tell you for sure.


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



___

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

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

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

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


Re: NSString property: copy or retain?

2008-12-22 Thread Jean-Daniel Dupas


Le 22 déc. 08 à 23:04, Debajit Adhikary a écrit :


Let's say I have a class called SomeClass with a string property name:

@interface SomeClass : NSObject{
   NSString* name;
}

@property (nonatomic, retain) NSString* name;

@end

I understand that name may be assigned a NSMutableString in which  
case this

will may to errant behavior.

(1) For strings in general, is it *always* a good idea to use the  
"copy"

attribute instead of "retain"?


Yes


(2) Is a "copied" attribute in any way less efficient than such a
"retain-ed" attribute?


No, as the string will be retain if it is immutable (the copy  
operation is optimized to return [self retain])



___

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: Thread crashing problem

2008-12-22 Thread Michael Ash
On Mon, Dec 22, 2008 at 10:22 AM, Ken Tozier  wrote:
> How would one share a lock? Should I make it a property of the class? And
> then what? According to the NSLock documentation, multiple calls to tryLock
> are a no no, so how does one determine the current state of a lock? I didn't
> see any methods like "isLocked"

I hate to say this, but You Are Doing It Wrong.

Asking how to determine the current state of a lock is asking the
wrong question. Determining the current state of the lock is (almost)
never useful. It's certainly never useful here.

Determining the current state of the lock is like determining the
current state of a stoplight, only you're looking at the state of the
light for the intersecting road. If it's green, obviously stop. If
it's red... well, who knows?

Instead what you should do is simply stop your car if *your* light is
red, and continue if *your* light is green.

The way you do this is to lock and unlock. You simply do [lock lock],
then [lock unlock]. In the middle, you put the stuff that needs to be
protected. The system takes care of ensuring that only one person at a
time is allowed in the middle. You don't have to worry about how it
works or what state the lock is in or anything of the sort. Lock,
modify or read, unlock. That's it. And note that *every access to any
shared data* must be locked. You can't just lock the "threaded"
access. The moment any data is shared between threads, *all* accesses
*anywhere* must be locked.

My personal recommendation would be to just copy the array and give up
on locking. Pass the copy into your thread and then you have no shared
data. Shared data is the bane of threading. The moment two threads
share data, the potential for misfortune goes up by a factor of at
least a million. Avoid it whenever you can. The cost of copying an
array is irrelevant by comparison.

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 arch...@mail-archive.com


Re: NSStream APIs

2008-12-22 Thread Jean-Daniel Dupas




Le 22 déc. 08 à 19:48, Alex Kac a écrit :

Does anyone have a good tutorial on how to use these? I have to  
admit to being stumped. I have some pre-written code written using  
NSData to send data using CFNetwork and ASyncSocket code and I just  
can't seem to figure out how to get the file stream stuff in there.  
What I would love is not just "sample" code, but perhaps a: here is  
how to do it with NSData and here is the same code with NSStream.




You can check the CFStream documentation.
In the CFNetwork programming guide, there is a section "Using stream". 
http://developer.apple.com/documentation/Networking/Conceptual/CFNetwork/Introduction/chapter_1_section_1.html

As NSStream API is just an obj-c wrapper on CFStream, the general  
concepts are the same.


___

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: Drawing in a NSView out side of drawRect

2008-12-22 Thread Michael Ash
On Mon, Dec 22, 2008 at 4:22 PM, David Alter  wrote:
>> > CGContextRef myContext =
>> > (CGContextRef)[[NSGraphicsContext currentContext]graphicsPort];
>>
>> Right now you're getting the current graphics context, which is purely
>> arbitrary. Nothing has set it yet, so you're getting whatever happened
>> to be hanging around.
>
> Is there a way to create a NSGraphicsContext for the view?

The paragraph immediately following the one you quoted describes how.

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 arch...@mail-archive.com


Replacing objects

2008-12-22 Thread DAS
Hey guys, I'm fairly new to cocoa development here, so please bear with me.
Is it possible to replace an object with another object so that all pointers
to that object now point to the new object? In other words:
Ptr A -> object1
Ptr B -> object1
Ptr C -> object1

I want to replace object1 with another object (of the same type), so that
all my pointers now point to object2. I realize that I could manually
replace all of the internal data in the object, thus leaving the pointer
intact, but I was hoping that there would be an easier way.

The reason I'm trying to do this is that I have a number of NSMutableArray's
throughout my application whose contents are based off a database on a
server. Periodically, the user searches the database, which returns a list
of objects. Some of these objects the client already has, and in that case I
would like to replace the local object with the one I've created via the
server. I've implemented an NSDictionary that holds all of the objects that
have come in from the server, and each NSMutableArray points to those same
objects (they are all subsets of the main list). This works fine except for
in the case where an existing object comes in from the server. I'd like to
be able to replace the original object with my new one and retain all of
it's pointers.

Thanks for the help,
Dimitri
___

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


NSString property: copy or retain?

2008-12-22 Thread Debajit Adhikary
Let's say I have a class called SomeClass with a string property name:

@interface SomeClass : NSObject{
NSString* name;
}

@property (nonatomic, retain) NSString* name;

@end

I understand that name may be assigned a NSMutableString in which case this
will may to errant behavior.

(1) For strings in general, is it *always* a good idea to use the "copy"
attribute instead of "retain"?
(2) Is a "copied" attribute in any way less efficient than such a
"retain-ed" attribute?
___

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: NSMutableArray sorting

2008-12-22 Thread Ben Trumbull


On Dec 22, 2008, at 8:13 AM, Adam R. Maxwell wrote:


On Dec 22, 2008, at 1:09 AM, Ben Trumbull wrote:

I've never seen it documented though perceived performance would  
indicate this is indeed the case


Generally, implementation details about caching behaviors falls  
isn't something that gets formally documented.  It's not part of  
the API contract, and can change some from release to release.


That said, Robert is right that NSSortDescriptor does significant  
caching throughout the sorting.  It assumes the results of  
valueForKey are stable for the duration of the sorting operation.   
If your custom comparison function is based on valueForKey,  
NSSortDescriptor will do a much better job than - 
sortedArrayUsingFunction.  That said, NSSortDescriptor is really  
only happy with keys and keypaths, and overriding its comparison  
method will disable the caching.


In fact, I discovered this while trying to figure out why an  
NSSortDescriptor subclass with a comparison override gave such  
abysmal performance; it was calling valueForKeyPath: so many times  
while sorting a few thousand objects that it filled the autorelease  
pool and crashed the app.  A lot of time looking at Shark traces for  
Apple's sorting led me to write my own NSArray sort method that  
gives similar performance, even when using NSSortDescriptor  
subclasses.  Unfortunately, Apple wasn't interested in that.



I would recommend you encourage other people who want to see that  
change file enhancement requests at bugreport.apple.com


- Ben

___

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: C++ instance variables not destructed if NSZombieEnabled

2008-12-22 Thread Greg Parker

On Dec 22, 2008, at 6:49 AM, Klaus Backert wrote:
In an application of mine I have some Objective-C classes with C++  
instance variables (the Objective-C things own the C++ things). I  
build with the option GCC_OBJC_CALL_CXX_CDTORS = YES, i.e. run non- 
trivial default constructors and destructors on C++ instance  
variables of Objective-C classes.


As long as I do *not* set the environment variable NSZombieEnabled  
to YES, everything works like this: Constructors of C++ instance  
variables have been called when returning from NSObject's init, and  
destructors have been called when returning from NSObject's dealloc.


But if I do set NSZombieEnabled to YES, then the destructors are  
*not* called anymore (by the way, setting NSDeallocateZombies to YES  
or NO does not make a difference).


I can observe all this with logging and debugging.

Does anybody know, if this is normal behavior, or what else? It  
looks like there is an annoying difference: With zombies enabled,  
dealloc methods of Objective-C are invoked, but destructors of C++  
are not called.


It's a loophole in the implementation of NSZombie. Sorry. You might be  
able to use Guard Malloc instead (man libgmalloc); it doesn't have  
that destructor problem.



--
Greg Parker gpar...@apple.com Runtime Wrangler


___

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: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Kenneth Bruno

On Mon, 22 Dec 2008 12:01:11 -0800, "mmalc Crawford"
 said:
> 
> On Dec 22, 2008, at 11:48 AM, Kenneth Bruno wrote:
> 
> > Basically, NSCalendarDate gets you pretty much what you need:
> >
> As in a recent message:
> 
> "Important: Use of NSCalendarDate strongly discouraged. It is not  
> deprecated yet, however it may be in the next major OS release after  
> Mac OS X v10.5. For calendrical calculations, you should use suitable  
> combinations of NSCalendar, NSDate, and NSDateComponents, as described  
> in Calendars in Date and Time Programming Guide for Cocoa."
>   

You're correct, I saw that just after I posted my solution.  Of course
similar things can be done with NSCalendar, NSDate, et al.

I didn't see the note in the documentation on my computer so it must be
fairly recent.  I guess I'll have to update my documentation.
___

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: Drawing in a NSView out side of drawRect

2008-12-22 Thread David Alter
>
> > CGContextRef myContext =
> > (CGContextRef)[[NSGraphicsContext currentContext]graphicsPort];
>
> Right now you're getting the current graphics context, which is purely
> arbitrary. Nothing has set it yet, so you're getting whatever happened
> to be hanging around.


Is there a way to create a NSGraphicsContext for the view?

>
>
>
___

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: Optimizing NSRectFill

2008-12-22 Thread Peter Ammon
setNeedsDisplay: and setNeedsDisplayInRect: do not integrate with  
coalesced updates as well as they might.  If you call setNeedsDisplay:  
faster than 60 times per second, then you will encounter the problem  
described in the technote.


Did turning off coalesced updates in Quartz Debug help?  If so, do not  
call setNeedsDisplay: or setNeedsDisplayInRect: for every event, but  
only if the time since the previous call is at least 1/60th of a  
second.  This should give you the responsiveness you expect.


On Dec 20, 2008, at 6:22 AM, Oleg Krupnov wrote:


Here is how I arrived at the conclusion that NSRectFill is the
bottleneck. (I cannot show the code because it's spread over objects).

The slowness of redraw is only noticeable when I drag the mouse, e.g.
to resize an object in the custom view. I see that update of the
resized object is always late after the actual position of the mouse
pointer, and the latency is sometimes pretty great to not be excused.
Especially when the size of the rectangle to be updated is large.

My custom view supports zooming, so I call NSRectFill after setting an
NSAffineTransform. Larger zooms, as I said, seem to cause greater
latency. Sometimes I also use clipping ([NSBezierPath addClip]) before
calling NSRectFill.

I never call -[NSView displayIfNeeded] or use other ways of forcing
the view to update itself. I always rely on -[NSView
setNeedsDisplayInRect:] to invalidate the rectangle(s) that need to be
updated and then wait until the next refresh. What is true, that
-[NSView setNeedsDisplayInRect:] are often called multiple times for
the same rectangles, but I don't think it matters.

I run my app with the Shark tool and drag the mouse to resize an
object, to and fro, for few seconds, then check the sample. It always
shows that 20-30% of time is taken by the NSRectFill function, which
is called only once to simply draw the background of the view with
solid white! This is ridiculous. I tried to put an NSLog  near the
NSRectFill call to check if it is called extra times, but it seems
that it is being called exactly one time per single mouse drag
message. When I comment out the call to NSRectFill, then the refresh
becomes noticeably smoother, and the Shark gives leadership to other
bottlenecks, in my case the NSBezierPath stroke and fill messages, for
the objects drawn in the view.

Any ideas?


On Sat, Dec 20, 2008 at 1:45 AM, Peter Ammon  wrote:


On Dec 19, 2008, at 7:37 AM, Oleg Krupnov wrote:


I'm developing a custom view and noticed that drawRect is becoming
increasingly slow. The Shark has pointed out that the bottleneck is
the NSRectFill function (that calls CGContextFillRect under the  
hood)

that I use to draw the background of the view.


A common cause of apparently excessive time in graphics related ops  
is that
you are running afoul of coalesced updates by attempting to refresh  
faster

than 60 times a second.

See
http://developer.apple.com/documentation/Performance/Conceptual/Drawing/Articles/FlushingContent.html 
 .
Try disabling coalesced updates in Quartz Debug and see if it  
speeds up
your drawing.  If so, ensure your app does not refresh faster than  
60 Hz.


-Peter




___

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


Core DataTableView Column Sort at launch with bindings?

2008-12-22 Thread vince
Thanks for the help ...
Is it possible to set up my Core Data doc application's Bindings so that
upon launch my mainColumn header is selected and the column is pre-sorted
(ascending) without implementing code?

thanks again.

vince.
___

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: Cocoa-dev Digest, Vol 5, Issue 2191

2008-12-22 Thread mmalc Crawford


On Dec 22, 2008, at 11:48 AM, Kenneth Bruno wrote:


Basically, NSCalendarDate gets you pretty much what you need:


As in a recent message:

"Important: Use of NSCalendarDate strongly discouraged. It is not  
deprecated yet, however it may be in the next major OS release after  
Mac OS X v10.5. For calendrical calculations, you should use suitable  
combinations of NSCalendar, NSDate, and NSDateComponents, as described  
in Calendars in Date and Time Programming Guide for Cocoa."



mmalc
___

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: Cocoa-dev Digest, Vol 5, Issue 2191

2008-12-22 Thread Kenneth Bruno
On Dec 22, 2008, at 2:53 AM, Keith Blount wrote:

> All I want to do is this: I would like to generate the names of all the
> months for a specified year. Then for each month in that year, I would
> like to generate the names of every day. For instance:
> 
> 2009
> - January
> -- Thursday, 1st January 2009
> -- Friday, 2nd January 2009
> ... and so on
> - February
> -- ... etc.

I didn't bother converting the ordinals for you (1st, 2nd, etc) but
here's a relatively simple way to do what you want.  Basically,
NSCalendarDate gets you pretty much what you need:

NSCalendarDate *aDate = [NSCalendarDate dateWithYear:2008 month:1 day:1
hour:0 minute:0 second:0 timeZone:0];

NSLog([aDate descriptionWithCalendarFormat:@"%Y"]);

do
{
if([aDate dayOfMonth] == 1)
NSLog([aDate descriptionWithCalendarFormat:@"- %B"]);

NSLog([aDate descriptionWithCalendarFormat:@"-- %A, %e %B %Y"]);

aDate = [aDate dateByAddingYears:0 months:0 days:1 hours:0 minutes:0 
seconds:0];

} while([aDate dayOfYear] > 1);
___

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: CharacterAtIndex method?

2008-12-22 Thread Kevin Gessner

On Dec 22, 2008, at 2:22 PM, Richard S. French wrote:


I am receiving a compiler warning: “NSString may not respond to
–characterAtIndex” from the following code.
This is from MathPaper – Chapter 12 of Building Cocoa Apps. Any help  
is

appreciated.
Thanks.

- (void)appendString:(NSString *)string
{
   int i;

   for (i=0;i<[string length];i++) {
   unichar c = [string characterAtindex:i];

[snip]


Watch your capitalization: you've got "characterAtindex:", but the  
selector is "characterAtIndex:".


HTH,
-- Kevin

Kevin Gessner
http://kevingessner.com
ke...@kevingessner.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: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Nathan Vander Wilt

On Dec 22, 2008, at 11:38 AM, mmalc Crawford wrote:

On Dec 22, 2008, at 9:22 AM, Nathan Vander Wilt wrote:
[Good advice, except:]
NSCalendar can handle overflow, so you can have an NSDateComponent  
that says something like  Year:2008 Month:1 Days:364 and you will  
get the right date from components.



You should not rely on this behaviour.



Oh dear, thanks for noticing that! I should have double-checked: Only - 
dateByAddingComponents:toDate:options: is documented to handle  
"overflow". Not -dateFromComponents:, which is actually documented to  
return nil for out-of-range values. Sorry about that.


-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 arch...@mail-archive.com


CharacterAtIndex method?

2008-12-22 Thread Richard S. French
I am receiving a compiler warning: ³NSString may not respond to
­characterAtIndex² from the following code.
This is from MathPaper ­ Chapter 12 of Building Cocoa Apps. Any help is
appreciated.
Thanks.

- (void)appendString:(NSString *)string
{
int i;

for (i=0;i<[string length];i++) {
unichar c = [string characterAtindex:i];

switch(c) {
case '\n':
case  '{':
case  '}':
case '\\':
[self appendChar:'\\'];
break;
default:
break;
}
[self appendChar:c];
}
}

___

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: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread mmalc Crawford


On Dec 22, 2008, at 11:20 AM, Ken Tozier wrote:


NSCalendarDate *date = [NSCalendarDate dateWithYear: ...


No!
This is precisely the direction in which not to go:
"Important: Use of NSCalendarDate strongly discouraged. It is not  
deprecated yet, however it may be in the next major OS release after  
Mac OS X v10.5. For calendrical calculations, you should use suitable  
combinations of NSCalendar, NSDate, and NSDateComponents, as described  
in Calendars in Date and Time Programming Guide for Cocoa."



mmalc

___

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: Color space for cmyk eps images converting to rgb

2008-12-22 Thread Ken Ferry
Hi Ken,

The -colorSpaceName method on NSImageRep returns only a best-effort
approximation.  This method, like many of the methods of NSImageRep,
is used by NSImage to decide which NSImageRep is the best choice for
drawing to a given destination.  The design is easiest to comprehend
from that point of view.  If an image rep doesn't have a 'home'
colorspace, calibrated RGB is the default.

EPS on Mac OS X is handled by converting the data to PDF.  The
interface NSEPSImageRep uses is documented here:
.
 I'm not familiar with the EPS format (since we just convert it to
PDF), but a PDF doesn't have any one colorspace.  Different embedded
bitmaps may have different colorspaces.  We do not look through the
included bitmaps for a most popular colorspace or anything like that.

This is more of an explanation than a workaround.  You can and should
file a bug, but even if you can define exactly what you want to have
happen, you'll have to go it alone for now.

-Ken
Cocoa Frameworks

On Sun, Dec 21, 2008 at 10:04 PM, Ken Tozier  wrote:
> Hi
>
> If you open an eps image in a text editor like BBEdit, you can see clearly
> what color space it was saved as but when you create an NSImage from the
> file and call [image representations] or [image bestRepresentationForDevice:
> ] all you get are images with
> "NSCalibratedRGBColorSpace." Most of our images are saved as cmyk so why is
> NSImage ignoring that info and replacing it with rgb? Is there any way to
> load eps's differently so that their saved color spaces are preserved? I
> could write a little hack to read the eps header directly and extract the
> info, but I'd like to avoid that if there is a way to do it with NSImage.
>
> Reason I ask is that I wrote a file cataloging application and one critical
> piece of info is the color space, so users will know, at a glance, whether
> an image they are about to import into a print document needs to be
> converted to cmyk.
>
> Thanks for any 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/kenferry%40gmail.com
>
> This email sent to kenfe...@gmail.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: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Ken Tozier
Following everyone's advice, I came up with the following, more  
compact, solution


- (NSDictionary *) dates:(int) inYear
{
NSMutableDictionary *result = 
[NSMutableDictionary dictionary];
NSMutableArray  *days   = 
[NSMutableArray array];

int startMonth  
= 1;

NSTimeZone  *tz 
= [NSTimeZone localTimeZone];

NSCalendarDate  *date   = 
[NSCalendarDate dateWithYear: inYear

month: startMonth

day: 1

hour: 0

minute: 0

second: 0

timeZone: tz];


	[result setObject: days forKey: [date descriptionWithCalendarFormat:  
@"%B"]];


while ([date yearOfCommonEra] == inYear)
{
date= [date dateByAddingYears: 0
months: 0
days: 1
hours: 0
minutes: 0
seconds: 0];

if ([date monthOfYear] > startMonth)
{
days= [NSMutableArray array];
			[result setObject: days forKey: [date  
descriptionWithCalendarFormat: @"%B"]];

startMonth++;
}

		[days addObject: [date descriptionWithCalendarFormat: @"%a %m/%d/%y  
%I:%M %p"]];

}


return result;  
}


On Dec 22, 2008, at 12:38 PM, mmalc Crawford wrote:



On Dec 22, 2008, at 9:22 AM, Nathan Vander Wilt wrote:
[Good advice, except:]
NSCalendar can handle overflow, so you can have an NSDateComponent  
that says something like  Year:2008 Month:1 Days:364 and you will  
get the right date from components.



You should not rely on this behaviour.

mmalc
(With thanks for sage advice to Chris Kane.)

___

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/kentozier%40comcast.net

This email sent to kentoz...@comcast.net


___

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


NSStream APIs

2008-12-22 Thread Alex Kac
Does anyone have a good tutorial on how to use these? I have to admit  
to being stumped. I have some pre-written code written using NSData to  
send data using CFNetwork and ASyncSocket code and I just can't seem  
to figure out how to get the file stream stuff in there. What I would  
love is not just "sample" code, but perhaps a: here is how to do it  
with NSData and here is the same code with NSStream.


-
Alex Kac - President and Founder
Web Information Solutions, Inc.

"Champions aren't made in the gyms. Champions are made from something  
they have deep inside of them - a desire, a dream, a vision. They have  
last-minute stamina, they have to be a little faster, they have to  
have the skill, and the will. But the will must be stronger than the  
skill."

-- Muhammad Ali





___

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: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread Keith Blount
Many thanks for your replies, and for the pointers to the samples and your own 
example - much appreciated. Before getting your second reply I'd just been 
through the code and done something pretty similar, using the suggestions you 
posted, to build up my hierarchical list for use in an NSOutlineView. Looking 
at your example, I think (hope) I've now got a workable solution:

- (NSMutableDictionary *)diarySpacesForYear:(NSInteger)year
{   
NSMutableArray *newDiarySpaces = [NSMutableArray array];

NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *yearDate, *monthDate, *dayDate;
NSRange monthRange, dayRange;
NSDateComponents *comps;

NSString *yearName = [NSString stringWithFormat:@"%i", year];

NSDictionary *localeDict = [[NSUserDefaults standardUserDefaults] 
dictionaryRepresentation];
NSTimeZone *timeZone = [NSTimeZone localTimeZone];

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
//[dateFormatter setDateStyle:NSDateFormatterFullStyle];
//[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateFormat:@"d - "];

// Get first day of the year.
comps = [[NSDateComponents alloc] init];
[comps setDay:1];
[comps setMonth:1];
[comps setYear:year];
yearDate = [calendar dateFromComponents:comps];
[comps release];

// Get month range.
monthRange = [calendar rangeOfUnit:NSMonthCalendarUnit 
inUnit:NSYearCalendarUnit forDate:yearDate];

// Go through each month.
int month;
for (month = monthRange.location; month < NSMaxRange(monthRange); 
month++)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

// Get first day of month.
comps = [[NSDateComponents alloc] init];
[comps setDay:1];
[comps setMonth:month];
[comps setYear:year];
monthDate = [calendar dateFromComponents:comps];
[comps release];

// Add this month to our array of months - get its name using 
NSDateComponents.
NSString *monthName = [monthDate 
descriptionWithCalendarFormat:@"%B" timeZone:timeZone locale:localeDict];

// Add this month.
NSMutableDictionary *currentMonth = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:

 monthName, @"Title",

 [NSMutableArray array], @"Days",

 yearName, @"Year",

 [NSNumber numberWithInt:NSMonthCalendarUnit], @"CalendarUnit",

 nil];

// Now go through every day for this month.
dayRange = [calendar rangeOfUnit:NSDayCalendarUnit 
inUnit:NSMonthCalendarUnit forDate:monthDate];
int day;
for (day = dayRange.location; day < NSMaxRange(dayRange); day++)
{
// Get the date.
comps = [[NSDateComponents alloc] init];
[comps setDay:day];
[comps setMonth:month];
[comps setYear:year];
dayDate = [calendar dateFromComponents:comps];
[comps release];

// Add this date to our month info.
NSMutableDictionary *day = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:

[dateFormatter stringFromDate:dayDate], @"Title",

[NSNumber numberWithInt:NSDayCalendarUnit], @"CalendarUnit",

nil];
[[currentMonth objectForKey:@"Days"] addObject:day];
}

// Add the month.
[newDiarySpaces addObject:currentMonth];

[pool release];
}

[dateFormatter release];

return [NSMutableDictionary dictionaryWithObjectsAndKeys:
yearName, @"Title",
newDiarySpaces, @"Months",
[NSNumber numberWithInt:NSYearCalendarUni

drag'n'drop - stopping the image from being displayed.

2008-12-22 Thread John Clayton

Hi

I'd like to stop any drag image from being displayed under or near the  
mouse cursor during a drag operation when something is being dragged  
into my application from the finder.


The reason is that my app provides sufficient feedback to the user   
about the dragging operation already, and the image itself is actually  
getting in the way of this feedback - my feedback is the creation of a  
'track' in a list - all CALayer stuff - and the standard drag image is  
on top which obscures this new track, it'd be much much better if I  
can get rid of this drag image.


Is there a way to stop the image from being created/used?  I am  
receiving drag operations in an instance of NSView of course, and  
obviously have implemented the draggingEntered:/Exited:/Updating:  
methods already.


Thanks
--
John Clayton
Skype: johncclayton




___

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: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread mmalc Crawford


On Dec 22, 2008, at 9:22 AM, Nathan Vander Wilt wrote:
[Good advice, except:]
NSCalendar can handle overflow, so you can have an NSDateComponent  
that says something like  Year:2008 Month:1 Days:364 and you will  
get the right date from components.



You should not rely on this behaviour.

mmalc
(With thanks for sage advice to Chris Kane.)

___

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: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread mmalc Crawford


On Dec 22, 2008, at 8:47 AM, mmalc Crawford wrote:

There shouldn't be any need, though, to "add a month" for each  
iteration, just start a new month with a date components object with  
a new month number.


This could be made a little more efficient (and if you're not using  
garbage collection, needs suitable memory management), but for the  
sake of explicitness you could do something like the following.


mmalc


NSInteger specifiedYear = 2009;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@" d  y"];

NSLocale *locale = [NSLocale currentLocale];
dateFormatter.locale = locale;

NSCalendar *calendar = [locale objectForKey:NSLocaleCalendar];

NSDateComponents *yearStartComponents = [[NSDateComponents alloc] init];
[yearStartComponents setDay:1];
[yearStartComponents setMonth:1];
[yearStartComponents setYear:specifiedYear];

NSDate *yearStartDate = [calendar  
dateFromComponents:yearStartComponents];


NSRange monthsRange = [calendar rangeOfUnit:NSMonthCalendarUnit  
inUnit:NSYearCalendarUnit forDate:yearStartDate];

NSUInteger months = monthsRange.length;
NSUInteger month;

for (month = 1; month <= months; month++) {

NSDateComponents *monthStartComponents = [[NSDateComponents  
alloc] init];

[monthStartComponents setDay:1];
[monthStartComponents setMonth:month];
[monthStartComponents setYear:specifiedYear];

NSDate *monthStartDate = [calendar  
dateFromComponents:monthStartComponents];


NSRange daysRange = [calendar rangeOfUnit:NSDayCalendarUnit  
inUnit:NSMonthCalendarUnit forDate:monthStartDate];

NSUInteger days = daysRange.length;
NSUInteger day;

for (day = 1; day <= days; day++) {

NSDateComponents *dayComponents = [[NSDateComponents alloc]  
init];

[dayComponents setDay:day];
[dayComponents setMonth:month];
[dayComponents setYear:specifiedYear];

NSDate *day = [calendar dateFromComponents:dayComponents];
NSString *dayString = [dateFormatter stringFromDate:day];
NSLog(@"dayString: %@", dayString);

}
}

___

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: warning: unused parameter '_value'

2008-12-22 Thread Nathan Vander Wilt

On Dec 22, 2008, at 4:42 AM, Gerriet M. Denkmann wrote:

When I use [GCC_WARN_UNUSED_PARAMETER, -Wunused-parameter]

I get (in Release build, not in Development) for every @synthesize  
statement a warning:

warning: unused parameter '_value'
There is no "value" nor "_value" in the source to be found.

What am I doing wrong?

Xcode Version 3.1.1; gcc 4.0; 10.5.6


This was a bug in the compiler until gcc 4.2:
http://lists.apple.com/archives/objc-language/2008/jul/msg00043.html

If you're able change your compiler setting at this point in  
development, that's the easiest fix.


-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 arch...@mail-archive.com


Re: Managed Object won't dealloc even after Hit with Kitchen Sink

2008-12-22 Thread Jim Correia

On Dec 22, 2008, at 12:17 AM, Jerry Krinock wrote:


REAL-LIFE PROBLEM

In a managed memory application, I have a managed object which,  
besides its Core Data managed properties, has a single instance  
variable, a worker-kind of object which does some heavy lifting for  
it.  So that this retained worker, etc., will be deallocced, I need  
this managed object to get deallocced when no longer needed.


The documentation [1] seems very clear that, although the  
'insert...' methods return an autoreleased NSManagedObject, a  
managed object may be retained by:

  (a) the managed object context, until changes are saved
 or rolled back, or,
  (b) the managed object context's undo manager, as long as
 an action involving the managed object remains on
 the undo stack.


The documentation is also clear that Core Data "reserves exclusive  
control over the life cycle of the managed object".


Absent a really good reason not to, you probably should release (and  
nullify the iVar) the worker-kind object when you are turned into a  
fault (-didTurnIntoFault.)


If you do this, does it solve your problem?

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 arch...@mail-archive.com


Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Nathan Vander Wilt


On Dec 22, 2008, at 4:53 AM, Keith Blount wrote:

Hi,

Apologies in advance for what I think must be a basic question. It's  
something I've never had cause to do before, assumed must be fairly  
straightforward, and then seemed a lot more complicated than it  
should be which leads me to think that I am using the wrong search  
terms...


All I want to do is this: I would like to generate the names of all  
the months for a specified year. Then for each month in that year, I  
would like to generate the names of every day. For instance:


2009
- January
-- Thursday, 1st January 2009
-- Friday, 2nd January 2009
... and so on
- February
-- ... etc.

I seem to be looking in the wrong areas in the frameworks, though. I  
thought NSDate and NSCalendar would be the place to look, but both  
seem overly complicated for this purpose. As far as I can see, in  
order to use NSCalendar to do this, I would have to do the following:




I would not agree with the other two posters on this, though their  
solutions should work in practice for your situation if you don't need  
anything general purpose. Otherwise, NSCalendar is your friend; if you  
find yourself typing something like January = 31 or 6 = "Friday" or 60  
* 60 * 24 in your code you're likely duplicating its functionality  
without getting any of its benefits (language issues, and political  
issues like daylight savings, leap years, leap seconds, etc.) The way  
people label time is a complicated, changeable thing, best to let the  
operating system handle it for you.




1) Start with a January NSDate in the specified year.


[the following code is all typed up in Mail, so may not be quite  
working]


Sounds good, and if you know the year the easiest way would be:
NSDateComponents* components = [[NSDateComponents alloc] init];
[components setMonth:1];
[components setYear:specifiedYear];
[calendar dateFromComponents:components];

Otherwise, if you have a date within the year:
NSDate* startOfYear = nil;
[calendar rangeOfUnit:NSYearCalendarUnit startDate:&startOfYear  
interval:NULL forDate:dateWithinYear];



2) Get number of months for that year using [calendar  
rangeOfUnit:NSMonthCalendarUnit inUnit:NSYearCalendarUnit  
forDate:january] (given that the app is only for personal purposes  
for now, I could just assume 12 for this part).


You could do this, or just iterate as described below until the year  
changes.


3) Get number of days in each month by using [calendar  
rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit  
forDate:january] and then adding on a month (though how to do that?  
- NSTimeInterval is in seconds and there are different numbers of  
days in each month...) to get the number of days for each month.


You can easily add on a month or day at a time using NSDateComponents  
and calendar. You can either use NSCalendar's - 
dateByAddingComponents:toDate:options:, or what I might do is take the  
component you might have made (or can get) from the original year 
+January and add days directly to that. NSCalendar can handle  
overflow, so you can have an NSDateComponent that says something like   
Year:2008 Month:1 Days:364 and you will get the right date from  
components. (Which you can then convert back to normalized components  
if you want to, say, check if the month has changed since the last day.)


4) Use NSDateFormatter to format the date for display (I'll have to  
do that part no matter what method I use).


Yes, among other benefits, this saves you from having to localize all  
the month names and such yourself.


Steps 1-3 seem needlessly complicated and error-prone, though, which  
leads me to suspect I am taking completely the wrong approach and  
missing the blindingly obvious. Is there a better way of doing this?


I think your steps were on the right track, I've just tried to point  
out some other helpful methods. NSCalendar is not always exactly  
intuitive or succinct to use, but it does a LOT for you and even if  
this project is simple, getting familiar with it now will be a win if  
you ever do something needing more accuracy in the future.


hope this helps,
–natevw___

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: selectionShouldChangeInTableView called twice

2008-12-22 Thread Corbin Dunn


On Dec 20, 2008, at 10:23 AM, Andre Masse wrote:


Hi,

I'm using a master/detail view in my application. If the user select  
another row in the master table and the detail has been modified, I  
want to present an alert to save, cancel or return to detail. I'm  
not using binding here, only datasource and delegate methods. So in - 
selectionShouldChangeInTableView: I return YES if the user saved or  
cancelled and NO if he choose the third option.


Problem is that selectionShouldChangeInTableView is called twice  
when returning NO. Having googled it, I found a couple of matches on  
this list and no replies... To make sure this is a bug, I made a  
test project available here and will radar it if it has no workaround:


http://idisk.mac.com/miyano/Public/TestRowChanges.zip

Now, since I can't rely on -selectionShouldChangeInTableView:, how  
do you guys handle this?


Sorry for the late reply on this, but just to add what others have  
said, and to make more sense of what is going on:


When the selection is changing, the tableview is in the  middle of  
tracking the mouse. It sends out the - 
selectionShouldChangeInTableView: and expects an immediate answer.  
Showing a non-modal dialog (ie: sheet) at this point can cause  
problems that you wouldn't expect, specifically, the tableview needs  
an answer so it can stop processing the mouse event.


So (as others have noted), the best solution is to always save off the  
target selection, present your Save/Cancel UI (if "dirty"), and after  
the UI has closed change the selection to the saved off target  
selection. When your UI is present, you should return NO for  
selectionShouldChange.


We do have a bug logged for this issue of the double-delegate calling,  
but you are always welcome to log a new bug report with your test case.

thanks,
corbin




___

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: Thread crashing problem

2008-12-22 Thread Jason Foreman

On Dec 22, 2008, at 9:42 AM, Ken Tozier wrote:
Problem is, I'm a thread noob so have no idea which type of lock is  
right for my situation. As to @synchronized, Robert Marini seemed to  
suggest that that was a Leopard-pnly solution. This app has to work  
on Tiger as well.




As a self professed "thread noob," make sure you've read this:

http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/Multithreading/

You might also be well served to do some research on pthreads, and  
make sure you understand the synchronization primitives such as  
semaphores and mutexes.  You'll only end up doing bodily harm to  
yourself and others if you don't understand the basics of threading at  
a fundamental level.


After you've read those, you should realize that, as Kyle points out,  
your code does not determine when it is safe to run.  Instead it  
should acquire a lock to tell the threading system that it wants to do  
something (e.g. modify a data structure), and the threading library  
will let your code run when it is safe to do so (it can acquire the  
lock).  @synchronized is essentially some syntax sugar that wraps a  
block of code with a lock, so that only one thread can be executing  
that code at a time.


Any code which modifies a shared data structure should be protected by  
a lock.  The lock is there to ensure that only one thread can modify  
the data at a time.  So all your code that modifies the data structure  
should use a (the same) lock.  So to answer one of your questions:  
yes, make the lock a property of the class--you need to use *the same*  
lock in each method to ensure proper synchronization.


Also, you needn't determine if the lock is locked.  Look at the docs  
for the NSLocking protocol.  You'll want to call -[NSLock lock], which  
will block the calling thread until the lock can be acquired.  Your  
concerns about multiply calling tryLock are only applicable to  
acquiring a lock recursively, i.e. acquiring the lock again on a  
thread which already holds it.


This is a very simplified account however, so please make sure you  
understand what you're doing and why--don't just take my word for it  
(I could be full of it).  Threaded programming can be hard and is very  
easy to get wrong.


Good luck!

Jason




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 arch...@mail-archive.com

Re: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread mmalc Crawford


On Dec 22, 2008, at 8:34 AM, Keith Blount wrote:


Hi,

Many thanks to both of you for your very helpful replies - much  
appreciated! I've gone with Ken's solution, which works perfectly  
for what I need. For the sake of the archives, I've attached the  
method I created based on Ken's code, which just creates a  
hierarchical dictionary of objects with the hierarchy Year->Month- 
>Day, with a "Title" key for each object, so that it can be used  
easily enough in the data source an NSOutlineView (which is how I'll  
be using it).


Thanks again - and happy holidays.

All the best,
Keith

-- Ken's code modified for use with an NSOutlineView data source or  
suchlike --


- (NSMutableDictionary *)diarySpacesForYear:(int)year
{
NSString *yearStr = [NSString stringWithFormat:@"%i", year];

	NSDate *startDate = [NSDate dateWithNaturalLanguageString:[NSString  
stringWithFormat:@"January 1 %i", year]];
	NSDate *endDate = [NSDate dateWithNaturalLanguageString:[NSString  
stringWithFormat:@"January 1 %i", year+1]];


Per the documentation, use of dateWithNaturalLanguageString is  
strongly discouraged.

Don't derive dates like this in code, use NSDateComponents...


while ([startDate timeIntervalSinceDate:endDate] < 0)



This is simply horrible.
If you want to perform calendrical calculations, again use  
NSDateComponents:


More examples are given in this version:




If you just want an array of month names, use monthSymbols (or  
standaloneMonthSymbols, or any of the related methods):


NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// set locale and/or calendar as appropriate
NSArray *monthSymbols = [dateFormatter monthSymbols];

Your original suggestion:

1) Start with a January NSDate in the specified year.
2) Get number of months for that year using [calendar  
rangeOfUnit:NSMonthCalendarUnit inUnit:NSYearCalendarUnit  
forDate:january] (given that the app is only for personal purposes  
for now, I could just assume 12 for this part).
3) Get number of days in each month by using [calendar  
rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit  
forDate:january] and then adding on a month (though how to do that?  
- NSTimeInterval is in seconds and there are different numbers of  
days in each month...) to get the number of days for each month.




is basically the correct way to approach this.
There shouldn't be any need, though, to "add a month" for each  
iteration, just start a new month with a date components object with a  
new month number.


mmalc

___

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: Thread crashing problem

2008-12-22 Thread Scott Ribe
> Given that, could you give a really simple example of how to
> coordinate access between the three methods?

First, your lock is an instance variable of the class, so in init you alloc
& init it, and in dealloc you release it...

- (void) methodA
{
[myLock tryLockBeforeDate: [NSDate distantFuture]];
// do your stuff here
[myLock unlock];
}

- (void) methodB
{
[myLock tryLockBeforeDate: [NSDate distantFuture]];
// do your stuff here
[myLock unlock];
}

- (void) methodC
{
[myLock tryLockBeforeDate: [NSDate distantFuture]];
// do your stuff here
[myLock unlock];
}


-- 
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice


___

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: NSCalendar/NSDate - generating all months/days in a year [SOLVED]

2008-12-22 Thread Keith Blount
Hi,

Many thanks to both of you for your very helpful replies - much appreciated! 
I've gone with Ken's solution, which works perfectly for what I need. For the 
sake of the archives, I've attached the method I created based on Ken's code, 
which just creates a hierarchical dictionary of objects with the hierarchy 
Year->Month->Day, with a "Title" key for each object, so that it can be used 
easily enough in the data source an NSOutlineView (which is how I'll be using 
it).

Thanks again - and happy holidays.

All the best,
Keith

-- Ken's code modified for use with an NSOutlineView data source or suchlike --

- (NSMutableDictionary *)diarySpacesForYear:(int)year
{
NSString *yearStr = [NSString stringWithFormat:@"%i", year];

NSDate *startDate = [NSDate dateWithNaturalLanguageString:[NSString 
stringWithFormat:@"January 1 %i", year]];
NSDate *endDate = [NSDate dateWithNaturalLanguageString:[NSString 
stringWithFormat:@"January 1 %i", year+1]];

NSMutableArray *newDiarySpaces = [NSMutableArray array];

NSMutableDictionary *currentMonth = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:

 NSLocalizedString(@"January",nil), @"Title",

 [NSMutableArray array], @"Days",

 yearStr, @"Year",

 [NSNumber numberWithInt:NSMonthCalendarUnit], @"CalendarUnit",

 nil];
int secondsPerDay= 60 * 60 * 24;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
//[dateFormatter setDateStyle:NSDateFormatterFullStyle];
//[dateFormatter setTimeStyle:NSDateFormatterNoStyle];
[dateFormatter setDateFormat:@"d - "];

// init list.
[newDiarySpaces addObject:currentMonth];

NSMutableDictionary *day = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:
[dateFormatter 
stringFromDate:startDate], @"Title",
[NSNumber 
numberWithInt:NSDayCalendarUnit], @"CalendarUnit",
nil];
[[currentMonth objectForKey:@"Days"] addObject:day];

// Loop until interval >= 0.
while ([startDate timeIntervalSinceDate:endDate] < 0)
{
// Get the next day.
startDate = [startDate addTimeInterval:secondsPerDay];

// Check we are still in the year, so that we don't add 1st Jan 
of the next year.
NSString *checkYear = [startDate 
descriptionWithCalendarFormat:@"%Y"

  timeZone:[NSTimeZone localTimeZone]

locale:[[NSUserDefaults 
standardUserDefaults] dictionaryRepresentation]];
if ([checkYear isEqualToString:yearStr] == NO)
break;  // We're into another year, so go no further.

// Get month from date.
NSString *checkMonth = [startDate 
descriptionWithCalendarFormat:@"%B"

   timeZone:[NSTimeZone localTimeZone]

 locale:[[NSUserDefaults 
standardUserDefaults] dictionaryRepresentation]];

// If month is different add it to the list of months.
if ([checkMonth isEqualToString:[currentMonth 
objectForKey:@"Title"]] == NO)
{
currentMonth = [NSMutableDictionary 
dictionaryWithObjectsAndKeys:
checkMonth, @"Title",
[NSMutableArray array], 
@"Days",
yearStr, @"Year",
[NSNumber 
numberWithInt:NSMonthCalendarUnit], @"CalendarUnit",
nil];
[newDiarySpaces addObject:currentMonth];
}

// Add date to list of days in this month.
NS

Re: NSMutableArray sorting

2008-12-22 Thread Adam R. Maxwell

On Dec 22, 2008, at 1:09 AM, Ben Trumbull wrote:

I've never seen it documented though perceived performance would  
indicate this is indeed the case


Generally, implementation details about caching behaviors falls  
isn't something that gets formally documented.  It's not part of the  
API contract, and can change some from release to release.


That said, Robert is right that NSSortDescriptor does significant  
caching throughout the sorting.  It assumes the results of  
valueForKey are stable for the duration of the sorting operation.   
If your custom comparison function is based on valueForKey,  
NSSortDescriptor will do a much better job than - 
sortedArrayUsingFunction.  That said, NSSortDescriptor is really  
only happy with keys and keypaths, and overriding its comparison  
method will disable the caching.


In fact, I discovered this while trying to figure out why an  
NSSortDescriptor subclass with a comparison override gave such abysmal  
performance; it was calling valueForKeyPath: so many times while  
sorting a few thousand objects that it filled the autorelease pool and  
crashed the app.  A lot of time looking at Shark traces for Apple's  
sorting led me to write my own NSArray sort method that gives similar  
performance, even when using NSSortDescriptor subclasses.   
Unfortunately, Apple wasn't interested in that.


--
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 arch...@mail-archive.com

Configuring NSNumberFormatter non-programmatically

2008-12-22 Thread Avery Nickelby
I've looked through the archives and the documentation; most of the
information is related to using NSNumberFormatter programatically. I am
looking for a good explanation for using 10.4 style data formatters in
Interface Builder; when I configure a number data formatter I can only get
one of two behaviors (I've tried different permutations of the switches in
IB):
1) User MUST type in a currency symbol before the field accepts input. The
information is displayed as $123.45.
2) The user doesn't type in a currency symbol. The information is just
displayed in decimal format (123.45)

I want: The user types in a number. The formatter looks up the appropriate
currency symbol tied to the user-defined default locale and displays a
locale-specific format.

How do I get this behavior? Do I need to revert to the old style (which I
can get to work)?

Thanks

Avery
___

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: Thread crashing problem

2008-12-22 Thread Kyle Sluder
On Mon, Dec 22, 2008 at 10:42 AM, Ken Tozier  wrote:
> "You should not use this class to implement a recursive lock. Calling the
> lock method twice on the same thread will lock up your thread permanently.
> Use the NSRecursiveLock class to implement recursive locks instead."

It says "lock", not "tryLock."

> Given that, could you give a really simple example of how to coordinate
> access between the three methods? @synchronized may be the way to go but it
> doesn't explain how one method could determine busy status and wait for an
> opening before doing its thing.

Simply put, when you're doing threading, you don't "determine"
anything.  You use the synchronization primitives you have to control
your code.  Any attempt you make to "determine" which thread should
execute will either be 1) useless because the synchronization
primitives are already controlling thread execution; or 2) incorrect
because you've introduced the very race conditions you're trying to
avoid.

--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 arch...@mail-archive.com


Re: Thread crashing problem

2008-12-22 Thread Ken Tozier


On Dec 22, 2008, at 10:30 AM, Kyle Sluder wrote:


Nowhere does the documentation say this.  You can't call -[NSLock
lock] multiple times, because you'll block on a lock you already have
(that's why we have recursive locks).  Otherwise -[NSLock tryLock]
would be quite useless, wouldn't it?


Maybe I misinterpreted, but from the first page of NSLock:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSLock_Class/Reference/Reference.html

"You should not use this class to implement a recursive lock. Calling  
the lock method twice on the same thread will lock up your thread  
permanently. Use the NSRecursiveLock class to implement recursive  
locks instead."




From the questions you're asking, it sounds like you're going to
implement a spinlock on top of NSLock.  Don't do this.  Just use
@synchronized.


Problem is, I'm a thread noob so have no idea which type of lock is  
right for my situation. As to @synchronized, Robert Marini seemed to  
suggest that that was a Leopard-pnly solution. This app has to work on  
Tiger as well.


Basically here's the scenario:

The app has a small number of user defined root watch folders. Each  
root folder spawns it's own watcher. When the root folder timer fires,  
It tells all it's child watchers to check their contents for changes.  
If a directory was inserted into one of the subdirectories, a new  
watcher is created and added to the root watcher list. The root  
watcher is the only one that initiates update messages for it's  
subfolders but the subfolders can add or remove items from it.


Given that, could you give a really simple example of how to  
coordinate access between the three methods? @synchronized may be the  
way to go but it doesn't explain how one method could determine busy  
status and wait for an opening before doing its thing.


___

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: Thread crashing problem

2008-12-22 Thread Kyle Sluder
On Mon, Dec 22, 2008 at 10:22 AM, Ken Tozier  wrote:
> How would one share a lock? Should I make it a property of the class? And
> then what? According to the NSLock documentation, multiple calls to tryLock
> are a no no, so how does one determine the current state of a lock? I didn't
> see any methods like "isLocked"

Nowhere does the documentation say this.  You can't call -[NSLock
lock] multiple times, because you'll block on a lock you already have
(that's why we have recursive locks).  Otherwise -[NSLock tryLock]
would be quite useless, wouldn't it?

>From the questions you're asking, it sounds like you're going to
implement a spinlock on top of NSLock.  Don't do this.  Just use
@synchronized.

--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 arch...@mail-archive.com


Re: Thread crashing problem

2008-12-22 Thread Ken Tozier
How would one share a lock? Should I make it a property of the class?  
And then what? According to the NSLock documentation, multiple calls  
to tryLock are a no no, so how does one determine the current state of  
a lock? I didn't see any methods like "isLocked"




On Dec 22, 2008, at 10:12 AM, Scott Ribe wrote:

The lock (the same one) has to be used by all the methods to  
coordinate
access. Taking a lock in updateDirectoriesInThread doesn't magically  
make

addDirectory and removeDirectory wait for the lock.

--
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice




___

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: Thread crashing problem

2008-12-22 Thread Robert Marini
If you can target Leopard and above, @synchronized is probably a  
better route to go though as scott said, the object to be synchronized  
around would need to be checked by all methods using it (in your case  
this would be the instance of the NSLock).


-rob.

On Dec 22, 2008, at 10:12 AM, Scott Ribe wrote:

The lock (the same one) has to be used by all the methods to  
coordinate
access. Taking a lock in updateDirectoriesInThread doesn't magically  
make

addDirectory and removeDirectory wait for the lock.

--
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice


___

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/rob%40pinchmedia.com

This email sent to r...@pinchmedia.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 arch...@mail-archive.com

Re: Thread crashing problem

2008-12-22 Thread Scott Ribe
Unless that busy flag is only used for UI display or debugging info, lose
it. The lock is the way to coordinate access, you can't do that by checking
a flag.

-- 
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice


___

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: Thread crashing problem

2008-12-22 Thread Scott Ribe
The lock (the same one) has to be used by all the methods to coordinate
access. Taking a lock in updateDirectoriesInThread doesn't magically make
addDirectory and removeDirectory wait for the lock.

-- 
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice


___

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: Thread crashing problem

2008-12-22 Thread Ken Tozier
Found a partial solution but it's ugly. If I copy the  array before  
enumerating it, no more crashes, but I'd prefer to not add that  
overhead...


On Dec 22, 2008, at 9:24 AM, Ken Tozier wrote:


Hi

I wrote a little app to do deep folder watching on Windows servers  
from a Mac and am getting crashes when directories are added or  
removed from the watch directory. The directory scanning takes place  
in a thread and I tried to isolate the array from outside changes by  
locking it, but its still getting mutated out from underneath me.


Here's the method that executes in a thread

- (void) updateDirectoriesInThread:(id) inData
{
NSLock  *lock = [[NSLock alloc] init];

busy= YES;

if ([lock tryLock])
{
// allocate a new autorelease pool
NSAutoreleasePool   *pool   = 
[[NSAutoreleasePool alloc] init];

NSEnumerator*enumerator = 
[directories objectEnumerator];

CNCDirectoryWatcher *directory;

while (directory = [enumerator nextObject])
{
[directory update];
}

// release the pool
[pool release];

[lock unlock];
}

busy= NO;
}

And here are the mutator methods which can be called at any time by  
other threads


- (void) addDirectory:(CNCDirectoryWatcher *) inObserver
{
[directories setObject: inObserver forKey: [inObserver directoryID]];
}

- (void) removeDirectory:(CNCDirectoryWatcher *) inObserver
{
[directories removeObjectForKey: [inObserver directoryID]];
}


How do I get other threads to go into a holding pattern until the  
target thread is done enumerating the directories array? I want the  
other threads to be able to add their items without losing any data,  
just not until the target is done.


Any pointers 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/kentozier%40comcast.net

This email sent to kentoz...@comcast.net


___

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: NSMutableArray sorting

2008-12-22 Thread Scott Ribe
> Generally, implementation details about caching behaviors falls isn't
> something that gets formally documented.  It's not part of the API
> contract, and can change some from release to release.

True, but significant performance behaviors should be documented.

-- 
Scott Ribe
scott_r...@killerbytes.com
http://www.killerbytes.com/
(303) 722-0567 voice


___

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


C++ instance variables not destructed if NSZombieEnabled

2008-12-22 Thread Klaus Backert
In an application of mine I have some Objective-C classes with C++  
instance variables (the Objective-C things own the C++ things). I  
build with the option GCC_OBJC_CALL_CXX_CDTORS = YES, i.e. run non- 
trivial default constructors and destructors on C++ instance variables  
of Objective-C classes.


As long as I do *not* set the environment variable NSZombieEnabled to  
YES, everything works like this: Constructors of C++ instance  
variables have been called when returning from NSObject's init, and  
destructors have been called when returning from NSObject's dealloc.


But if I do set NSZombieEnabled to YES, then the destructors are *not*  
called anymore (by the way, setting NSDeallocateZombies to YES or NO  
does not make a difference).


I can observe all this with logging and debugging.

Does anybody know, if this is normal behavior, or what else? It looks  
like there is an annoying difference: With zombies enabled, dealloc  
methods of Objective-C are invoked, but destructors of C++ are not  
called.


Mac OS X 10.5.5, Xcode 3.1.2, GCC 4.0, garbage collection off.

Thanks
Klaus

___

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: Reliable way to capitalize camel-case strings? [SOLVED]

2008-12-22 Thread Jean-Daniel Dupas


Le 22 déc. 08 à 14:48, Michael Ash a écrit :

On Mon, Dec 22, 2008 at 8:25 AM, Graham Cox   
wrote:


I ended up writing this category method. I guess it will be  
reliable, as

it's making no assumptions about encoding.


Actually it is! It assumes that the first character is the first
"character". You'll want to stick in a call to
-rangeOfComposedCharacterSequenceAtIndex: if you want to be 100%
universal.

However I would not hesitate to assume ASCII. The language only allows
ASCII in identifiers, so you can't define, declare, or call a
non-ASCII method directly in code. You could do so by building one at
runtime, but if you're doing such a crazy thing then you deserve
whatever poor behavior you get!


In fact the language allows some strange things.
C99 allows usage of some UCN in identifier (see annex D of C99  
reference fo know the full list):


And so, this is valid Obj-C99 (obj-c code compiled using -std=c99) code.

--

int h\u00e1 = 0;

@interface Test {
}

- (void)\u00e1rf;

@end

@implementation Test

- (void)\u00e1rf {}

@end

--___

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

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

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

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


Thread crashing problem

2008-12-22 Thread Ken Tozier

Hi

I wrote a little app to do deep folder watching on Windows servers  
from a Mac and am getting crashes when directories are added or  
removed from the watch directory. The directory scanning takes place  
in a thread and I tried to isolate the array from outside changes by  
locking it, but its still getting mutated out from underneath me.


Here's the method that executes in a thread

- (void) updateDirectoriesInThread:(id) inData
{
NSLock  *lock = [[NSLock alloc] init];

busy= YES;

if ([lock tryLock])
{
// allocate a new autorelease pool
NSAutoreleasePool   *pool   = 
[[NSAutoreleasePool alloc] init];

NSEnumerator*enumerator = 
[directories objectEnumerator];

CNCDirectoryWatcher *directory;

while (directory = [enumerator nextObject])
{
[directory update];
}

// release the pool
[pool release];

[lock unlock];
}

busy= NO;
}

And here are the mutator methods which can be called at any time by  
other threads


- (void) addDirectory:(CNCDirectoryWatcher *) inObserver
{
[directories setObject: inObserver forKey: [inObserver directoryID]];
}

- (void) removeDirectory:(CNCDirectoryWatcher *) inObserver
{
[directories removeObjectForKey: [inObserver directoryID]];
}


How do I get other threads to go into a holding pattern until the  
target thread is done enumerating the directories array? I want the  
other threads to be able to add their items without losing any data,  
just not until the target is done.


Any pointers 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: warning: unused parameter '_value'

2008-12-22 Thread Michael Ash
On Mon, Dec 22, 2008 at 5:42 AM, Gerriet M. Denkmann
 wrote:
> When I use [GCC_WARN_UNUSED_PARAMETER, -Wunused-parameter]
>
> I get (in Release build, not in Development) for every @synthesize statement
> a warning:
> warning: unused parameter '_value'
> There is no "value" nor "_value" in the source to be found.
>
> What am I doing wrong?

Sounds like the only thing you're doing "wrong" is using that warning.
I would file a bug and then turn it back off. (I gave up on
-Wunused-parameter long ago; Cocoa apps have far too many legitimately
unused parameters to make it worthwhile. That said, this is no excuse
for the compiler generating such warnings in its own code!)

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 arch...@mail-archive.com


Re: Reliable way to capitalize camel-case strings? [SOLVED]

2008-12-22 Thread Michael Ash
On Mon, Dec 22, 2008 at 8:25 AM, Graham Cox  wrote:
>
> I ended up writing this category method. I guess it will be reliable, as
> it's making no assumptions about encoding.

Actually it is! It assumes that the first character is the first
"character". You'll want to stick in a call to
-rangeOfComposedCharacterSequenceAtIndex: if you want to be 100%
universal.

However I would not hesitate to assume ASCII. The language only allows
ASCII in identifiers, so you can't define, declare, or call a
non-ASCII method directly in code. You could do so by building one at
runtime, but if you're doing such a crazy thing then you deserve
whatever poor behavior you get!

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 arch...@mail-archive.com


Re: Reliable way to capitalize camel-case strings?

2008-12-22 Thread Gregory Weston

Graham Cox wrote:


In my app I need a way to generate the name of a method based on a
property key. If the key is, e.g. -scaleFactor, and the generated
method name needs to be -displayNameForScaleFactor, how can I reliably
turn "scaleFactor" into "ScaleFactor"? I tried [NSString
capitalizedString] but I get "Scalefactor". Obviously capitalizing an
ASCII string is trivial but I'm not sure that I can assume that
encoding for method names.


There are probably more efficient ways, but brute force should work:

NSRange fc = NSMakeRange(0,1);
NSString* s2 = [[s1 substringWithRange:fc] uppercaseString];
NSString* s3 = [s1 stringByReplacingCharactersInRange:fc withString:s2];

If you need to support pre-10.5, I guess you'll need to make a  
mutable string for the replacement step.


___

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: Reliable way to capitalize camel-case strings? [SOLVED]

2008-12-22 Thread Graham Cox


On 22 Dec 2008, at 11:22 pm, Rob Rix wrote:

I’m interested to know if there’s a better way to do this than the  
ugly way I’ve been using, too:


NSString *first = [string substringWithRange: NSMakeRange(0, 1)];
NSString *rest = [string substringFromIndex: 1];
NSString *result = [[first uppercaseString] stringByAppendingString:  
rest];


Rob

On 22-Dec-08, at 6:23 AM, Graham Cox wrote:

In my app I need a way to generate the name of a method based on a  
property key. If the key is, e.g. -scaleFactor, and the generated  
method name needs to be -displayNameForScaleFactor, how can I  
reliably turn "scaleFactor" into "ScaleFactor"? I tried [NSString  
capitalizedString] but I get "Scalefactor". Obviously capitalizing  
an ASCII string is trivial but I'm not sure that I can assume that  
encoding for method names.


Since the KVC mechanism must be doing this a lot, I wondered if  
there was an API I'm overlooking.





I ended up writing this category method. I guess it will be reliable,  
as it's making no assumptions about encoding. There's clearly more  
than one way to skin this cat... ;-)


- (NSString*)   stringByCapitalizingFirstCharacter
{
	// returns a copy of the receiver with just the first character  
capitalized, ignoring all others.

// Thus, the rest of the string isn't necessarily forced to lowercase.

NSMutableString*sc = [self mutableCopy];
NSString*   firstChar = [[self substringToIndex:1] 
uppercaseString];

[sc replaceCharactersInRange:NSMakeRange(0,1) withString:firstChar];

return [sc autorelease];
}


I'm calling this solved, though if anyone has a better method or knows  
of an API, please pipe up!


thanks, 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 arch...@mail-archive.com


Re: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread WT

Hi Keith,

Ken's suggestion is much more elegant than mine, but here's mine  
anyway. I wrote a little Foundation Tool to test it and it works fine.


Note that the year (2009), and the fact that 2009 is not a leap year,  
are hard-coded. You'll have to change that, of course.


Hope this helps.
Wagner

=== source ===

#import 

static int monthDays[] =
{
31, // Jan
28, // Feb - hard-coded for non-leap years
31, // Mar
30, // Apr
31, // May
30, // Jun
31, // Jul
31, // Aug
30, // Sep
31, // Oct
30, // Nov
31, // Dec
};

int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

NSArray *dayNames = [[NSArray alloc] initWithObjects:
@"Saturday",
@"Sunday",
@"Monday",
@"Tuesday",
@"Wednesday",
@"Thursday",
@"Friday",
nil];

NSArray *monthNames = [[NSArray alloc] initWithObjects:
@"January",
@"February",
@"March",
@"April",
@"May",
@"June",
@"July",
@"August",
@"September",
@"October",
@"November",
@"December",
nil];

NSDateComponents *comps = [[NSDateComponents alloc] init];
[comps setYear: 2009]; // hard-coded
[comps setMonth: 1];
[comps setDay: 1];

NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier: NSGregorianCalendar];

NSDate *date = [gregorian dateFromComponents: comps];
[comps release];

NSDateComponents *weekdayComponents =
[gregorian components: NSWeekdayCalendarUnit fromDate: date];

int weekday = [weekdayComponents weekday];

int daysInYear = 365; // hard-coded for non-leap years

int day = 0;
int month = 0;

for (int i = 0; i < daysInYear; ++i)
{
int dayOfWeek = (i + weekday) % 7;
++day;

if (day > monthDays[month])
{
++month; // go to next month
day = 1; // reset day to the start of the month
NSLog(@" "); // to separate months in the output
}

NSLog(@"%@, %@ %i %i",
[dayNames objectAtIndex: dayOfWeek],
[monthNames objectAtIndex: month],
day,
2009); // hard-coded
}

[dayNames release];
[monthNames release];

[pool drain];

return 0;
}

=== output ===

[Session started at 2008-12-22 14:02:20 +0100.]
2008-12-22 14:02:20.304 Calendrical[909:10b] Thursday, January 1 2009
2008-12-22 14:02:20.310 Calendrical[909:10b] Friday, January 2 2009
...
2008-12-22 14:02:20.343 Calendrical[909:10b] Friday, January 30 2009
2008-12-22 14:02:20.343 Calendrical[909:10b] Saturday, January 31 2009
2008-12-22 14:02:20.344 Calendrical[909:10b]
2008-12-22 14:02:20.344 Calendrical[909:10b] Sunday, February 1 2009
2008-12-22 14:02:20.345 Calendrical[909:10b] Monday, February 2 2009
...
2008-12-22 14:02:20.356 Calendrical[909:10b] Friday, February 27 2009
2008-12-22 14:02:20.356 Calendrical[909:10b] Saturday, February 28 2009
2008-12-22 14:02:20.357 Calendrical[909:10b]
2008-12-22 14:02:20.357 Calendrical[909:10b] Sunday, March 1 2009
2008-12-22 14:02:20.358 Calendrical[909:10b] Monday, March 2 2009
...
2008-12-22 14:02:20.373 Calendrical[909:10b] Monday, March 30 2009
2008-12-22 14:02:20.378 Calendrical[909:10b] Tuesday, March 31 2009
...
...
2008-12-22 14:02:20.700 Calendrical[909:10b] Wednesday, December 30 2009
2008-12-22 14:02:20.701 Calendrical[909:10b] Thursday, December 31 2009


___

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: Reliable way to capitalize camel-case strings?

2008-12-22 Thread Rob Rix
I’m interested to know if there’s a better way to do this than the  
ugly way I’ve been using, too:


NSString *first = [string substringWithRange: NSMakeRange(0, 1)];
NSString *rest = [string substringFromIndex: 1];
NSString *result = [[first uppercaseString] stringByAppendingString:  
rest];


Rob

On 22-Dec-08, at 6:23 AM, Graham Cox wrote:

In my app I need a way to generate the name of a method based on a  
property key. If the key is, e.g. -scaleFactor, and the generated  
method name needs to be -displayNameForScaleFactor, how can I  
reliably turn "scaleFactor" into "ScaleFactor"? I tried [NSString  
capitalizedString] but I get "Scalefactor". Obviously capitalizing  
an ASCII string is trivial but I'm not sure that I can assume that  
encoding for method names.


Since the KVC mechanism must be doing this a lot, I wondered if  
there was an API I'm overlooking.



thanks,

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/rix.rob%40gmail.com

This email sent to rix@gmail.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: NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Ken Tozier

Fun problem

Basically it's safe to assume 24 hours in a day for date calculation  
(check details at Wikipedia) so you just have to get January 1 of the  
target year, January 1 of the subsequent year and increment until the  
time interval between them equals zero. This makes no assumptions  
about how many days there are in a year so should work fine for leap  
years as well.


NSMutableArray  *result = [NSMutableArray array];

NSDate			*startDate		= [NSDate dateWithNaturalLanguageString:  
@"January 1 2009"],
*endDate		= [NSDate dateWithNaturalLanguageString: @"January 1  
2010"];


NSString*currentMonth   = @"January",
*testMonth;

int secondsPerDay   = 60 * 60 * 24;

// init list
[result addObject: currentMonth];
[result addObject: startDate];

// loop until interval >= 0
while ([startDate timeIntervalSinceDate: endDate] < 0)
{
// get the next day
startDate   = [startDate addTimeInterval: 
secondsPerDay];

// get month from date
testMonth   = [startDate descriptionWithCalendarFormat: 
@"%B"
timeZone: 
[NSTimeZone localTimeZone]
locale: [[NSUserDefaults standardUserDefaults]  
dictionaryRepresentation]];


// if month is different add it to the list
if (![testMonth isEqualToString: currentMonth])
{
[currentMonth release];
currentMonth= [testMonth retain];
[result addObject: currentMonth];
}

// add date to list
[result addObject: startDate];
}

NSLog(@"result: %@", result);

You could easily group days in each month by tweaking it slightly


On Dec 22, 2008, at 5:53 AM, Keith Blount wrote:


Hi,

Apologies in advance for what I think must be a basic question. It's  
something I've never had cause to do before, assumed must be fairly  
straightforward, and then seemed a lot more complicated than it  
should be which leads me to think that I am using the wrong search  
terms...


All I want to do is this: I would like to generate the names of all  
the months for a specified year. Then for each month in that year, I  
would like to generate the names of every day. For instance:


2009
- January
-- Thursday, 1st January 2009
-- Friday, 2nd January 2009
... and so on
- February
-- ... etc.

I seem to be looking in the wrong areas in the frameworks, though. I  
thought NSDate and NSCalendar would be the place to look, but both  
seem overly complicated for this purpose. As far as I can see, in  
order to use NSCalendar to do this, I would have to do the following:


1) Start with a January NSDate in the specified year.
2) Get number of months for that year using [calendar  
rangeOfUnit:NSMonthCalendarUnit inUnit:NSYearCalendarUnit  
forDate:january] (given that the app is only for personal purposes  
for now, I could just assume 12 for this part).
3) Get number of days in each month by using [calendar  
rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit  
forDate:january] and then adding on a month (though how to do that?  
- NSTimeInterval is in seconds and there are different numbers of  
days in each month...) to get the number of days for each month.
4) Use NSDateFormatter to format the date for display (I'll have to  
do that part no matter what method I use).


Steps 1-3 seem needlessly complicated and error-prone, though, which  
leads me to suspect I am taking completely the wrong approach and  
missing the blindingly obvious. Is there a better way of doing this?


Many thanks in advance for any help or pointers.
All the best,
Keith



___

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/kentozier%40comcast.net

This email sent to kentoz...@comcast.net


___

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: Saving the project

2008-12-22 Thread Mike Abdullah
Either NSWindow or NSWindowController have a -setDocumentEdited:  
method that will do what you want.


On 22 Dec 2008, at 11:39, Mahaboob wrote:

In my app I used NSTextView as editor and saves my project along  
with the
contents of editor by using archiving and also I can open the saved  
project.
Now I need to show a bubble in the close button when I'm making any  
changes
in the editor. How can I show the bubble? How can I notify when the  
editor

get edited?

Thanks in advance
mahaboob


___

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/cocoadev%40mikeabdullah.net

This email sent to cocoa...@mikeabdullah.net


___

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


Saving the project

2008-12-22 Thread Mahaboob
In my app I used NSTextView as editor and saves my project along with the
contents of editor by using archiving and also I can open the saved project.
Now I need to show a bubble in the close button when I'm making any changes
in the editor. How can I show the bubble? How can I notify when the editor
get edited?

Thanks in advance
mahaboob


___

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: Accepting iCal events dropped on my application's icon

2008-12-22 Thread Yang Meyer

Sean,

So in essence my question is: How can I tell my application to  
accept iCal events dragged directly from the iCal GUI?


When iCal events are dragged and exported to another application,  
iCal will provide a promised .ics file in ~/Library/Caches/ 
TemporaryItems.  This file has an extension "ics" and a UTI of  
com.apple.ical.ics.  Ideally, you'd just set the Document Types in  
your target's properties (Info.plist) to support this file, but it  
seems a bit tricky since this is a promised file and probably does  
not have these attributes set yet during the drag.


I didn't have a lot of time to experiment or research how to support  
promised file drops on the application icon, but one way to make  
this work is to register a "catch all" document type in Info.plist,  
and then your application will allow drops of iCal events, although  
along with it every other kind of file.  You can do this in your  
target's properties window by adding a document type with an  
extension of "*" and an OS type of "".


Thanks for the tip. Since indeed it seems that the attributes (UTI  
etc) are not set yet when the promised file is dragged, I implemented  
it with the catch-all solution you sketched.


The usability downside of catch-all is that the app icon gets darker  
(signalling that it accepts a dragged item) with whatever you drag  
onto it, e.g. folders, pictures, … So if anyone knows a better  
solution, I'm still interested :-)


Thanks again,
Yang___

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


Reliable way to capitalize camel-case strings?

2008-12-22 Thread Graham Cox
In my app I need a way to generate the name of a method based on a  
property key. If the key is, e.g. -scaleFactor, and the generated  
method name needs to be -displayNameForScaleFactor, how can I reliably  
turn "scaleFactor" into "ScaleFactor"? I tried [NSString  
capitalizedString] but I get "Scalefactor". Obviously capitalizing an  
ASCII string is trivial but I'm not sure that I can assume that  
encoding for method names.


Since the KVC mechanism must be doing this a lot, I wondered if there  
was an API I'm overlooking.



thanks,

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 arch...@mail-archive.com


NSCalendar/NSDate - generating all months/days in a year

2008-12-22 Thread Keith Blount
Hi,

Apologies in advance for what I think must be a basic question. It's something 
I've never had cause to do before, assumed must be fairly straightforward, and 
then seemed a lot more complicated than it should be which leads me to think 
that I am using the wrong search terms...

All I want to do is this: I would like to generate the names of all the months 
for a specified year. Then for each month in that year, I would like to 
generate the names of every day. For instance:

2009
- January
-- Thursday, 1st January 2009
-- Friday, 2nd January 2009
... and so on
- February
-- ... etc.

I seem to be looking in the wrong areas in the frameworks, though. I thought 
NSDate and NSCalendar would be the place to look, but both seem overly 
complicated for this purpose. As far as I can see, in order to use NSCalendar 
to do this, I would have to do the following:

1) Start with a January NSDate in the specified year.
2) Get number of months for that year using [calendar 
rangeOfUnit:NSMonthCalendarUnit inUnit:NSYearCalendarUnit forDate:january] 
(given that the app is only for personal purposes for now, I could just assume 
12 for this part).
3) Get number of days in each month by using [calendar 
rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:january] and 
then adding on a month (though how to do that? - NSTimeInterval is in seconds 
and there are different numbers of days in each month...) to get the number of 
days for each month.
4) Use NSDateFormatter to format the date for display (I'll have to do that 
part no matter what method I use).

Steps 1-3 seem needlessly complicated and error-prone, though, which leads me 
to suspect I am taking completely the wrong approach and missing the blindingly 
obvious. Is there a better way of doing this?

Many thanks in advance for any help or pointers.
All the best,
Keith


  
___

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


warning: unused parameter '_value'

2008-12-22 Thread Gerriet M. Denkmann

When I use [GCC_WARN_UNUSED_PARAMETER, -Wunused-parameter]

I get (in Release build, not in Development) for every @synthesize  
statement a warning:

warning: unused parameter '_value'
There is no "value" nor "_value" in the source to be found.

What am I doing wrong?

Xcode Version 3.1.1; gcc 4.0; 10.5.6


Kind regards,

Gerriet.

___

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: Toll Free Garbage

2008-12-22 Thread Julien Jalon
Under GC, retain/release is not the same as CFRetain/CFRelease
(retain/release does nothing but CFRetain/CFRelease ensures that the object
is kept around even if the GC might want to finalize it).
The general idea is then that you will have to "cast" the CFRetain at the
same time you cast the CFType:
1) cast a CFType+CFRetain to a NSObject+retain: use NSMakeCollectable()
2) cast a CFType+CFRetain to a __strong CFType+retain: use
CFMakeCollectable()

Note that you can only cast a CFRetain to "GC/retain" if the object was
allocated using the default CFAllocator (kCFDefaultAllocator or NULL)

Also, pair only CFRetains with CFReleases and retains with releases.

Examples:

NSString* s = NSMakeCollectable(CFStringCreateXXX(NULL, ...));

[...]

[s release]; // or nothing if you build only for GC

__strong CFStringRef s =
(CFStringRef)CFMakeCollectable(CFStringCreateXXX(NULL, ...));

[...]

[(id)s release]; // or nothing if you build only for  GC


CFStringRef s = CFStringCreateXXX(NULL, ...);

[...]

CFRelease(s); // required in GC and in no-GC

NSString* s = [NSString stringWithXXX];

CFRetain((CFTypeRef)s); // s will be kept around until CFRelease, in GC and
no-GC

[...]

CFRelease((CFTypeRef)s); // required in GC and in no-GC

-- 
Julien

On Mon, Dec 22, 2008 at 8:40 AM, Gerriet M. Denkmann
wrote:

>
> Assume some plug-in, which must work with garbage collection on or off.
> Assume further, that there is a method (not under our control):
>
> - (NSString *)copySomething;
>
> And that this method returns either an NSString* or a toll free bridged
> CFStringRef, of which we are the owner (because the name contains "copy").
>
> If we do:
> NSString *s = [ someObject copySomething];
> // do something with "s"
> [s release];
>
> it will work without garbage collection, but leak otherwise in the case of
> a CFStringRef.
> How to get rid of "s" ?
> Simply calling CFRelease() is no good, because it might be an NSString* on
> which someone has done a CFRetain().
>
>
> Kind regards,
>
> Gerriet.
>
> ___
>
> 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/jjalon%40gmail.com
>
> This email sent to jja...@gmail.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: NSToolbarItem identifier?

2008-12-22 Thread Quincey Morris

On Dec 22, 2008, at 00:44, aaron smith wrote:


I haven't been able to figure out how to set a custom identifier with
NSToolbarItem's. Is it possible? I don't see it anywhere in IB, or
anywhere in the class documentation? I can see the identifier at
runtime, but it's a uuid, can't I set a custom identifier?


You can't set one in IB. The workaround is to declare outlets in your  
File's Owner object to each of the toolbar items you need to refer to,  
and then use the outlets directly (or get the IB-assigned identifier  
via the outlet, if that's what you need). That will probably feel a  
bit hokey, but perhaps a future version of IB will have a more elegant  
implementation for this.



___

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: Managed Object won't dealloc even after Hit with Kitchen Sink

2008-12-22 Thread Ben Trumbull

// Insert a Foo without telling the undo manager
[undoManager disableUndoRegistration] ;
Foo *foo = [[Foo alloc] initWithEntity:runEntity
insertIntoManagedObjectContext:moc];


That's standard alloc/init.  It's retained and needs a matching  
release from you.  Whether or not it's inserted into the MOC is  
irrelevant.  The convenience method on NSEntityDescription is  
autoreleased (it's a class factory method).



// Now, NOBODY has any reason to hold on to foo, so
// when we release the pool, we expect that Foo should
// log a dealloc message:

[pool release];

// Actual result: no dealloc


Quincey's comments are accurate.  You'll need a call to - 
processPendingChanges after releasing the pool, or just release the  
MOC entirely instead of calling reset+processPendingChanges.  GUI apps  
usually don't have this problem since the event loop will catch this  
issue.


The managed objects can't be deallocated immediately if their MOC is  
still alive, since they can't know if it's a thread safe time for  
their MOC to operate upon them and their dependent resources. They  
can't know, because they could be leaked into an autorelease pool,  
like this example, while the MOC was handed off to another thread.   
Since so much of Cocoa API returns autoreleased results, including - 
executeFetchRequest, this scenario is easy to trip over.


On the bright side, NSManagedObject can safely have release invoked  
upon it from any thread at any time.  On the down side, there is a  
transition state in order to safely tear down dependent resources  
(release on related objects, row caches, MOC state, etc etc).  While  
less than ideal, personally, I think this is less cumbersome than the  
objects that can only be used on the main thread.


The object may additionally be retained by the MOC if it has pending  
changes for the next save operation, or if it is being held within the  
object graph by a related object that is not a fault.


- Ben

___

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: NSMutableArray sorting

2008-12-22 Thread Ben Trumbull
I've never seen it documented though perceived performance would  
indicate this is indeed the case


Generally, implementation details about caching behaviors falls isn't  
something that gets formally documented.  It's not part of the API  
contract, and can change some from release to release.


That said, Robert is right that NSSortDescriptor does significant  
caching throughout the sorting.  It assumes the results of valueForKey  
are stable for the duration of the sorting operation.  If your custom  
comparison function is based on valueForKey, NSSortDescriptor will do  
a much better job than -sortedArrayUsingFunction.  That said,  
NSSortDescriptor is really only happy with keys and keypaths, and  
overriding its comparison method will disable the caching.


What kind of calculations are involved when sorting? I ask because . 
5s for sorting 4000 objects seems *incredibly* slow


What Mike said.

- Ben

___

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


NSToolbarItem identifier?

2008-12-22 Thread aaron smith
I haven't been able to figure out how to set a custom identifier with
NSToolbarItem's. Is it possible? I don't see it anywhere in IB, or
anywhere in the class documentation? I can see the identifier at
runtime, but it's a uuid, can't I set a custom identifier?

Thanks all.
___

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


  1   2   >