Re: -[NSGarbageCollection disableCollectorForPointer:] ?

2008-10-14 Thread Ken Ferry
Hi Michael,

NSPointerFunctionsStrongMemory|NSPointerFunctionsOpaqueMemory doesn't
make sense. You're meant to specify only one of the memory options and
only one of the personality options.

Due to the way the bitfield work, your invocation is the same as
NSPointerFunctionsOpaqueMemory|NSPointerFunctionsOpaquePersonality.
This is the mode in which the pointer array is completely hands-off.
It acts like a C array.

Try NSPointerFunctionsStrongMemory|NSPointerFunctionsOpaquePersonality.
 That sounds right to me, though I get confused with the pointer
functions too.

-Ken

On Tue, Oct 14, 2008 at 9:43 PM, Michael Link <[EMAIL PROTECTED]> wrote:
> I have a situation where I create an NSPointerArray on the stack by:
>
> pointers = [NSPointerArray
> pointerArrayWithOptions:NSPointerFunctionsStrongMemory|NSPointerFunctionsOpaqueMemory|NSPointerFunctionsOpaquePersonality];
>
> I then go about adding a few objects a selector and a pointer (contextInfo
> that could point to anything even a non-object) to the pointer array.
>
> I then call:
>
> [[NSGarbageCollector defaultCollector] disableCollectorForPointer:pointers];
>
> The pointer array is then passed as the contextInfo for another method
> (which turns out to be a weak reference), but isn't garbage collected due to
> the previous call. The interesting part turns out that the object at index 0
> (NSError* in this case) in the pointer array is garbage collected (probably
> because it was a variable in the function that called us). The pointer array
> is configured to use strong references therefore index 0 isn't set to NULL
> and something else is located at that memory (sometimes a different object,
> sometimes garbage memory).
>
> If I use:
>
> [[NSGarbageCollector defaultCollector] disableCollectorForPointer:[pointers
> pointerAtIndex:0]];
>
> nothing bad happens and that object isn't collected.
>
> According to the documentation for disableCollectorForPointer: shouldn't the
> pointer array be considered a new root object, and none of it's pointers
> collected? Especially since it uses strong references?
>
> --
> Michael
> ___
>
> 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 [EMAIL PROTECTED]
>
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSTask not cleaning up it's threads

2008-10-14 Thread Ken Thomases

On Oct 14, 2008, at 6:43 AM, C Tearpak wrote:

The following is a test application that demonstrates what I am  
seeing. If
you look at the application in Activity monitor, you will see the  
threads go

up every second.

Is there something that I am missing? For a long-running application  
that
has the following in a thread loop, this causes a huge issue, as I  
can't
seem to get these threads to clean up. I have also tried dealloc(),  
setting
the pointers to nil and NULL, and calling -terminate: on the NSTask  
before I

exit the runCommand:: method;

[...]
int main (int argc, const char * argv[]) {


mainTest* mainT = [mainTest new];

while(true)

{

NSLog([mainT runCommand: @"/bin/date" withArguments:[NSArray new]]);

sleep(1);

}


Have you tried using a run loop and a timer to perform this operation  
once a second, rather than a while loop and sleep()?


I suspect that the threads being created by NSTask and/or NSFileHandle  
are trying to interact with the main thread using something like - 
performSelectorOnMainThread:... with YES for the "wait" parameter.   
That requires that the main thread's run loop gets run in the  
specified mode (likely the default mode).


You can use Activity Monitor's Sample Process feature to get a sense  
of what the extraneous threads are stuck waiting for.


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


Re: EXC_BAD_ACCESS with NSAutoReleasePool, NSThread and NSThreadWillExitNotification

2008-10-14 Thread Ken Thomases

I realize you've already identified the cause of the crash but...

On Oct 14, 2008, at 9:38 AM, John Zorko wrote:


... and the threadStopped method does this:

- (void)threadStopped
{
NSLog(@"*** streamer thread has stopped ***");

[[NSNotificationCenter defaultCenter] removeObserver:self];

appDelegate.playbackThreadFinished = true;
}

Now, in my main thread, I have an observer on playbackThreadFinished  
that I set up as soon as the app launches (before the other thread  
is created):


	[self addObserver:self forKeyPath:@"playbackThreadFinished" options: 
0 context:nil];



... and when I see the "playbackThreadFinished" notification, I do  
things like see if there is a new song to play, etc.


There's an important consideration to be aware of.  First, the  
NSThreadWillExitNotification notification is delivered in the thread  
which is about to exit.  Therefore, your threadStopped method and its  
"appDelegate.playbackThreadFinished = true;" statement are executed in  
that same thread.  So, the KVO change notification that results from  
"appDelegate.playbackThreadFinished = true" is also delivered on that  
thread.  For either kind of notification, it doesn't matter on what  
thread the observer was registered.  It only matters on what thread  
the notification was posted or the property change was made.


However, in -observeValueForKeyPath:... you are performing operations  
on GUI controllers which will presumably have knock-on effects on GUI  
views, etc.  Those sorts of things aren't allowed on any thread but  
the main thread.  You're probably going to get yourself in trouble.


The solution is to use -performSelectorOnMainThread:... to move the  
updates of any properties which might be observed using KVO and  
bindings to the main thread.


In fact, I'm not sure why you're using NSThreadWillExitNotification  
nor KVO on the playbackThreadFinished property.  Your design might be  
considerably simplified if your thread method -startInternal were to  
simply use -performSelectorOnMainThread:... as its last action to  
invoke a method on the main thread to take care of any post-threaded- 
operation work.


More generally, since all of this work is happening within one class,  
there should be little reason for it to observe its own properties.   
If you want to perform work when one of your own properties changes,  
the cleaner approach is to put that work into the setter for the  
property.


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


-[NSGarbageCollection disableCollectorForPointer:] ?

2008-10-14 Thread Michael Link

I have a situation where I create an NSPointerArray on the stack by:

pointers = [NSPointerArray  
pointerArrayWithOptions:NSPointerFunctionsStrongMemory| 
NSPointerFunctionsOpaqueMemory|NSPointerFunctionsOpaquePersonality];


I then go about adding a few objects a selector and a pointer  
(contextInfo that could point to anything even a non-object) to the  
pointer array.


I then call:

[[NSGarbageCollector defaultCollector]  
disableCollectorForPointer:pointers];


The pointer array is then passed as the contextInfo for another method  
(which turns out to be a weak reference), but isn't garbage collected  
due to the previous call. The interesting part turns out that the  
object at index 0 (NSError* in this case) in the pointer array is  
garbage collected (probably because it was a variable in the function  
that called us). The pointer array is configured to use strong  
references therefore index 0 isn't set to NULL and something else is  
located at that memory (sometimes a different object, sometimes  
garbage memory).


If I use:

[[NSGarbageCollector defaultCollector] disableCollectorForPointer: 
[pointers pointerAtIndex:0]];


nothing bad happens and that object isn't collected.

According to the documentation for disableCollectorForPointer:  
shouldn't the pointer array be considered a new root object, and none  
of it's pointers collected? Especially since it uses strong references?


--
Michael
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Animating view transitions with Core Animation (problems with BasicCocoaAnimations sample)

2008-10-14 Thread Ken Ferry
On Mon, Oct 13, 2008 at 3:51 PM, Jim Correia <[EMAIL PROTECTED]> wrote:
> - Animation for -replaceSubview:with: appears to require a layer backed view 
> tree.

This is true.  Also true of animations for hiding or adding or removing views.

>- Focus rings are drawn incorrectly for editable NSTextField and
> friends [2]

When a view draws a focus ring, it just draws it as part of its normal
drawRect: drawing.  When the drawing is being targeted into a layer,
that means that the focus ring cannot extend outside of the layer.
The general approach to a workaround would be to make sure that the
view is padded out from where the text field cell is drawn, providing
enough space in the layer for the focus ring to draw in.

>- Non-editable NSTextFields have incorrect anti-aliasing (without
> Scott Stevenson's hack)

I'm not aware of Scott's hack, but the problem is that the algorithm
for LCD text smoothing requires knowledge of the pixel colors behind
the text at draw time.  You'll see the same degradation whenever text
is drawn into a transparent buffer.  Windows are usually opaque, but
in the case of layers, each view is its own buffer.

The simplest fix is to check the drawsBackground checkbox on the field
in IB, and then select the windowBackgroundColor from the Developer
palette in the color panel.  (Any opaque color will do, but in most
cases you'd want to match the window.)  More complicated than but more
flexible is to override drawRect: and draw something opaque before
calling super.  If none of this is applicable, you do better to turn
off text smoothing entirely in a drawRect: override, using
CGContextSetShouldSmoothFonts.  At some point in the future
NSTextField may itself turn off text smoothing before drawing if layer
backed mode is on and the field does not think it's going to opaquely
fill the buffer behind the text.


> Problem #3:
>
> In order to arrange for my view tree to only be layer backed for the
> duration of the animation, I need to know when the animation finishes :-)
>
> The benefit of the implicit view animations is that much of the heavy
> lifting has already been done for me, so I'd like to take advantage of it if
> possible. The problem, though, is that since I'm not running the animations
> explicitly, I don't know when they are done.
>
> My current hack is to begin the implicit animations in a group, and use a
> perform delayed action to cleanup after the animation (based on the groups
> interval.)
>
> This feels like a hack though. Is there a better way?

I think that's the recommended approach.

-Ken
Cocoa Frameworks
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Not so long filenames

2008-10-14 Thread Chris Suter
On Wed, Oct 15, 2008 at 7:00 AM, Gerriet M. Denkmann
<[EMAIL PROTECTED]> wrote:

> So again my question: why it is too long in this context and where is this
> documented?

This looks like a bug in the kernel code. It looks like it checks the
UTF8 string length against kHFSPlusMaxFileNameChars (rather than the
UTF-16 length).

You should report it.

-- Chris
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Targetting 10.4

2008-10-14 Thread Louis Demers


On 14-Oct-08, at 21:20 , James Walker wrote:


Louis Demers wrote:
   I developed (on 10.5.5 with the latest tools) a small app that  
runs well on 10.5 and cleaned it up for 10.4. I configured my  
project with Base SDK to 10.4  as below, cleaned all and built a  
release binary.


When you said "I configured my project" I wondered whether you made  
the change at the project level.  Have you checked whether your  
target has different settings than the project?


I checked everywhere I can think of. When I click on my Target as well  
on my Project (in all configurations debug mad release), I have


Base SDK10.4
Deployment Target 10.4




--
 James W. Walker, Innoventive Software LLC
 


Louis Demers eng.
www.obzerv.com


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Greg Parker

Chris Suter wrote:
The proper way to solve this, in my opinion, is to allow a way of  
specifying that the return type varies depending on the class it's  
implemented on i.e. define the alloc method in such a way so that  
the compiler knows that -[ alloc] returns an object of type  
. Something similar could be used for [NSString string] and  
[NSMutableString string] which have a similar problem (they return  
an id, rather than an NSString or NSMutableString).



We think so too.

 ER: Declare that an instance method's return  
type is the same as the receiver's declared type.
 ER: Declare that a class method's return type  
is the type of instances of the receiver.


The latter is the one that applies to +alloc. It returns an instance  
of the receiver object - which itself is a class - or some subclass  
thereof. The former is for things like -init, where the receiver type  
and the return type are the same.


There are a few binary- and source-compatibility issues to worry  
about, but the biggest reason this hasn't been done yet is simple lack  
of time.



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


Re: Targetting 10.4

2008-10-14 Thread James Walker

Louis Demers wrote:


I developed (on 10.5.5 with the latest tools) a small app that runs 
well on 10.5 and cleaned it up for 10.4. I configured my project with 
Base SDK to 10.4  as below, cleaned all and built a release binary.


When you said "I configured my project" I wondered whether you made the 
change at the project level.  Have you checked whether your target has 
different settings than the project?


--
  James W. Walker, Innoventive Software LLC
  
___

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

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

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

This email sent to [EMAIL PROTECTED]


Targetting 10.4

2008-10-14 Thread Louis Demers

Hi,

	I developed (on 10.5.5 with the latest tools) a small app that runs  
well on 10.5 and cleaned it up for 10.4. I configured my project with  
Base SDK to 10.4  as below, cleaned all and built a release binary.



<>



 Yet when I run it on 10.4.11, I get

= Tuesday, October 14, 2008 9:04:33 PM America/Montreal =
dyld: Symbol not found: _NSDefaultRunLoopMode
  Referenced from: /Obzerv Dev Apps/ICCD Bench.app/Contents/MacOS/ 
ICCD Bench
  Expected in: /System/Library/Frameworks/CoreFoundation.framework/ 
Versions/A/CoreFoundation


Oct 14 21:04:38 obzervs-powerbook-g4 crashdump[182]: ICCD Bench crashed
Oct 14 21:04:38 obzervs-powerbook-g4 crashdump[182]: crash report  
written to: /Users/obzerv/Library/Logs/CrashReporter/ICCD  
Bench.crash.log





Any clues how tofix. Never had problems before compiling for both OS  
versions and both architectures.


Louis Demers eng.
www.obzerv.com


___

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

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

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

This email sent to [EMAIL PROTECTED]

NSDistributedNotificationCenter in a prefpane?

2008-10-14 Thread randy chapel
Hi,

has anyone been able to get a NSDistributedNotificationCenter (send/rec) to 
work within a prefpane?

Randy


  
___

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

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

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

This email sent to [EMAIL PROTECTED]


NSDistributedNotificationCenter

2008-10-14 Thread randy chapel
Hi,

Has anyone had any luck using a NSDistributedNotificationCenter in a prefpane?

code:

in using the pref pane example from apple 
(http://developer.apple.com/samplecode/PrefsPane/index.html), I used the 
following code in the mainViewDidLoad method.

NSDistributedNotificationCenter *center = 
[NSDistributedNotificationCenter defaultCenter]; 
[center addObserver: self 
selector: @selector(callbackWithNotification:) 
name: @"My Notification" 
object: nil]; 


- (void)callbackWithNotification:(NSNotification *)myNotification {
[[NSSound soundNamed:@"pop"] play]; // yet it worked
}





with a notification in another app written as:

NSDistributedNotificationCenter *center = 
[NSDistributedNotificationCenter defaultCenter]; 
[center postNotificationName: @"My Notification" 
object: nil 
userInfo: nil /* no dictionary */ 
deliverImmediately: YES];



Of interest, I need to communicate back and forth.  Nothing is working either 
sending from the pref pane or receiving to it (at least in what I have tried).  
(see 
http://developer.apple.com/documentation/UserExperience/Conceptual/PreferencePanes/PreferencePanes.pdf)


Has anyone else had luck with such?  what am I missing?

Randy







  
___

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

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

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

This email sent to [EMAIL PROTECTED]


NSTask not cleaning up it's threads

2008-10-14 Thread C Tearpak
Hi there all,
I am relatively new, and from what I can tell, I am doing the following
correctly using GC  (required) on my XCode Project.

The following is a test application that demonstrates what I am seeing. If
you look at the application in Activity monitor, you will see the threads go
up every second.

Is there something that I am missing? For a long-running application that
has the following in a thread loop, this causes a huge issue, as I can't
seem to get these threads to clean up. I have also tried dealloc(), setting
the pointers to nil and NULL, and calling -terminate: on the NSTask before I
exit the runCommand:: method;

Thanks in advance for any light you can shed on this issue.



#import 

@interface mainTest :NSObject

{

 }


@end

@implementation mainTest

-(NSString *)runCommand:(NSString *) pathToCommand withArguments:(NSArray*)args

{

NSTask *task = [[NSTask alloc] init]; // initialise a NSTask for launching
the process

NSPipe *newPipe = [NSPipe pipe]; // initialise a one-way channel

NSFileHandle *readHandle = [newPipe fileHandleForReading]; // to read the
process output

NSData *inData; // the process output will be passed to a NSData

NSString *tempString; // and the NSData will be converted to a NSString

// Set up the operating conditions for the task

[task setCurrentDirectoryPath:NSHomeDirectory()];

[task setLaunchPath: pathToCommand];

[task setArguments:args];

[task setStandardOutput:newPipe]; // The Unix output is fed into the NSPipe

// Now launch the process

[task launch];

// Read everything sent and store in NSData

inData = [readHandle readDataToEndOfFile];

// Set up a temporary NSString containing the contents of the NSData

tempString = [[NSString alloc] initWithData:inData encoding:
NSASCIIStringEncoding];

 // Return the NSString holding the output of the Unix process

return tempString;

}


@end


int main (int argc, const char * argv[]) {


 mainTest* mainT = [mainTest new];

 while(true)

{

NSLog([mainT runCommand: @"/bin/date" withArguments:[NSArray new]]);

sleep(1);

}



return 0;

}
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Animating view transitions with Core Animation (problems with BasicCocoaAnimations sample)

2008-10-14 Thread Thomas Engelmeier


Am 14.10.2008 um 00:51 schrieb Jim Correia:


Problem #3:


My current hack is to begin the implicit animations in a group, and  
use a perform delayed action to cleanup after the animation (based  
on the groups interval.)


This feels like a hack though. Is there a better way?


I don't have a robust, good solution. but if you set the  
CAAnimationGroup delegate you might get the animationDidStop delegate  
method called.

Based on my empiric testing the gotcha is
a.) to know which views need cleanup one needs unique delegate objects
b.) the delegates are not guaranteed to be called - when an animation  
gets reapplied during a running animation the delegate method is not  
invoked, which introduces the problem of releasing the cleanup- 
delegates...


Maybe someone at Quartz-Dev has some better ideas (I need als a  
solution for #3. My hack to remove subviews after they are animated  
out - of - frame needs some serious improvement..)

Regards,
Tom_E

___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: VCards & Address Book -- Preferred Telephone Number

2008-10-14 Thread Nick Zitzmann


On Oct 14, 2008, at 4:53 PM, Thaddeus Cooper wrote:

When one generates a vcard from an Address Book entry how does  
Address Book decide what the "preferred" telephone number is.



The "preferred" value is the value that is designated as primary  
identifier in the ABMultiValue.


Nick Zitzmann


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Sharing a Bindings Controller between nibs

2008-10-14 Thread Graham Cox


On 15 Oct 2008, at 9:30 am, Citizen wrote:

I have a master-detail interface, where the Detail interface is in a  
separate nib from the main Master interface (so that different  
Detail interfaces can be swapped in).
The main Master interface nib contains an NSTreeController which is  
used to display an iTunes like source list.



But I can't help feeling that there must be a better way of doing  
this? Any suggestions?



To my mind it doesn't make sense to have each detail interface in a  
separate nib. The interface unit is the whole collection of views and  
parts that make it up, and these should be in the same nib. Doing that  
will simplify this in every way.


Having separate views for each detail is fine, but then your  
controller has to manage swapping them in and out. Even simpler might  
be using a tabless view to embed them in and simply switch tabs.  
That's what I do in a few M/D interfaces and it's very easy to set up  
and works a treat.


--Graham
___

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

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

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

This email sent to [EMAIL PROTECTED]


VCards & Address Book -- Preferred Telephone Number

2008-10-14 Thread Thaddeus Cooper
When one generates a vcard from an Address Book entry how does Address  
Book decide what the "preferred" telephone number is.


Thanks very much.

Thaddeus O. Cooper
([EMAIL PROTECTED])



___

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

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

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

This email sent to [EMAIL PROTECTED]


Sharing a Bindings Controller between nibs

2008-10-14 Thread Citizen

Hi,

I'm just getting to grips with bindings.

I have a master-detail interface, where the Detail interface is in a  
separate nib from the main Master interface (so that different Detail  
interfaces can be swapped in).
The main Master interface nib contains an NSTreeController which is  
used to display an iTunes like source list.


The Detail interface needs to access the current selection presented  
by the NSTreeController, but the tree controller is in another nib.


So, what is the cleanest way (i.e with the least glue code) of  
connecting the two?


My current plan is to connect the NSTreeController to an outlet (named  
sourceTree) in the MasterViewController. Then make the  
MasterViewController a delegate of the DetailViewController. And then  
access the selected content using a key path something like  
@"delegate.sourceTree.selection".


But I can't help feeling that there must be a better way of doing  
this? Any suggestions?


Thanks,
Dave
--
David Kennedy (http://www.zenopolis.com)


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Cocoa-dev Digest, Vol 5, Issue 1774

2008-10-14 Thread David Murphy

hi folks,


I'm looking to build a view, similar to the upper sequential thumbnail  
view in iPhoto's Edit mode window.
Before I go and build my own version, does anyone know if this is  
already available in an existing framework or library (from Apple or  
elsewhere)?



cheers


rgds Dave



__
David Murphy

Department of Computer Science
University College Cork
Ireland

p: 00353 (0)21 4903579
f:  00353 (0)21 4274390
e: [EMAIL PROTECTED]
w: http://multimedia.ucc.ie
w: http://www.cs.ucc.ie/staff/dmurphy.html
blog: http://vrplace.blogspot.com/




___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Not so long filenames

2008-10-14 Thread Sean McBride
On 10/14/08 5:28 PM, Gerriet M. Denkmann said:

>But in the program below there seems to exist some other limit (at
>least on 10.4.11 Tiger).
>Where is this documented?
>Or what am I doing wong?
>
>
>#import 
>
>int main (int argc, const char * argv[])
>{
>   NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
>   
>   NSData *data = [ @"Some Data" dataUsingEncoding:
>NSUTF8StringEncoding ];
>   NSFileWrapper *aWrapper = [ [ NSFileWrapper alloc ]
>initRegularFileWithContents: data ];
>   NSString *f2 = [ NSString stringWithUTF8String: //  64 * 
> DESERET
>CAPITAL LETTER LONG I
>   
> "???
>??
>??
>?"// 64
>   ];

Are you trying to create a constant NSString with UTF8 characters in
your source?  Is that what all the '?' chars are?  You can only do that
in 10.5.

--

Sean McBride, B. Eng [EMAIL PROTECTED]
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Not so long filenames

2008-10-14 Thread Gerriet M. Denkmann


On 14 Oct 2008, at 18:07, Jason Coco wrote:



On Oct 14, 2008, at 11:28 , Gerriet M. Denkmann wrote:

HFS+ and Finder can use filenames which use in Utf-16 up to 255  
shorts.


But in the program below there seems to exist some other limit (at  
least on 10.4.11 Tiger).

Where is this documented?
Or what am I doing wong?

... Filewrapper has preferred filename with 128 shorts in Utf16;  
Utf8 of fileSystemRepresentation has 256 bytes

... Error: writeToFile
Filename has exited with status 2.


I'm not really sure, but one thing I noticed right away is that 256  
> 255...


This is absolutely correct: 256 is greater than 255.
But the filename is 128 shorts in Utf-16 (and you might have noticed  
that 128 ≤ 255 ) and can be used in Finder and HFS+ can store it.


So again my question: why it is too long in this context and where is  
this documented?



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


Re: EXC_BAD_ACCESS with NSAutoReleasePool, NSThread and NSThreadWillExitNotification

2008-10-14 Thread John Zorko


Jonathan et al,

Yup -- that was exactly it -- had nothing to do with the thread,  
even ... I had instantiated something and made it autorelease, but  
then proceeded to release it myself anyway like a doof.


On Oct 14, 2008, at 7:47 AM, Jonathan del Strother wrote:


On Tue, Oct 14, 2008 at 3:38 PM, John Zorko <[EMAIL PROTECTED]> wrote:


Hello, all ...

I'm experiencing a crash after a thread exits.

Program received signal:  "EXC_BAD_ACCESS".
(gdb) bt
#0  0x300c8c18 in objc_msgSend ()
#1  0x3067073a in NSPopAutoreleasePool ()
#2  0x306770ea in __NSFinalizeThreadData ()
#3  0x31446f6e in _pthread_tsd_cleanup ()
#4  0x31449ae4 in _pthread_exit ()
#5  0x3144b7e8 in pthread_exit ()
#6  0x30676e66 in +[NSThread exit] ()
#7  0x30673444 in __NSThread__main__ ()
#8  0x3144a824 in _pthread_body ()
#9  0x in ?? ()
(gdb)



You're probably over-releasing something.  Turn on NSZombieEnabled to
find out what.
http://developer.apple.com/technotes/tn2004/tn2124.html



Regards,

John

Falling You - exploring the beauty of voice and sound
http://www.fallingyou.com











___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: replacing carbon menu with cocoa

2008-10-14 Thread Peter Ammon
I honestly don't know - replacing a Carbon main menu with a Cocoa main  
menu at runtime isn't a configuration I've ever tested.  If what you  
tried works and you're happy with the result, I guess go with it.


-Peter

On Oct 14, 2008, at 7:09 AM, Esteban Lorenzano wrote:


Hi,
I loaded from Nib, as you suggest, and something strange happens - 
strange, but near what I need-


If I load a Nib, the new main menu overlaps the old one (and two  
menus coexist)... but new Main Menu redraws "apple" menu too, and  
disappear if I reload the Nib. Finally, if I first "clean" carbon  
menu, and then load bundle twice, everything seems to be working.  
This is the code I wrote:


static sqInt initializeCocoaMenu(void) {
MenuRef cleanMenu;

//First we clean the carbon menu
CreateNewMenu(menuId, 0, &cleanMenu);
SetMenuTitleWithCFString(cleanMenu, CFSTR(""));
SetRootMenu(cleanMenu);
//Then we load the bundle
	[ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication  
sharedApplication ] ];

//... twice
	[ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication  
sharedApplication ] ];

return sqNil;
}

... but this is ok?

Thanks,
Esteban

On 13/10/2008, at 4:27p.m., Peter Ammon wrote:



On Oct 13, 2008, at 5:18 AM, Esteban Lorenzano wrote:


Hi,
I'm new to the list -and to cocoa-, and I don't know if what I  
want to do is possible: I'm writing a plugin for a previous  
existent application made in carbon, the application will take  
over the old app behavior, and for that, it needs to replace the  
menu with a new one...
I read documentation, saw examples and followed old threads on  
this list, and no one is very clear about this... ¿Is it possible?  
¿how?


You should make a nib from the "Application" template in Interface  
Builder, then load it via [NSBundle loadNibNamed:...].  Its main  
menu will replace the current main menu.




I already tried

[ NSApp setMainMenu: myMenu ]

It does not fail, but nothing happens :(


It's hard to say what this would do without seeing the code that  
creates myMenu.  But there's some problems creating a main menu  
programmatically; using a nib is the best approach.


-Peter



"Querer es suscitar las paradojas"
Camus - El mito de Sísifo



___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Finding clicked row in NSOutlineView

2008-10-14 Thread James Walker

Michael Ash wrote:

On Mon, Oct 13, 2008 at 9:23 PM, James Walker <[EMAIL PROTECTED]> wrote:

I need to be notified when a row of an NSOutlineView was clicked, and find
out which row.


See these methods:

-setAction:
-setTarget:
-clickedRow


Thanks, don't know how I missed that.

--
  James W. Walker, Innoventive Software LLC
  
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Quincey Morris

On Oct 14, 2008, at 02:17, Oleg Krupnov wrote:


If the alloc returns id, then, from the compiler's perspective, there
can be two solutions: 1) assume that the id type can have each and any
method and let it be resolved at run time without any compiler warning
or 2) assume that the id does not have any methods (except NSObject's)
and always issue a compiler warning when there is no explicit casting
to a type. What compiler seems to be doing is rather strange: it looks
through the project, arbitrarily picks up a class with the matching
message name and issues a warning if the rest of the actual message
signature is not matching. How would you explain that?


This is a fairly well-known issue. It reflects an Objective-C design  
constraint, and does not indicate random or inconsistent behavior in  
the compiler.


The design constraint is that Objective-C assumes (but does not  
enforce) that methods with identical selectors have identical  
parameter and return types. Your initWithContext: methods violate this  
constraint. It's certainly possible to violate the constraint without  
danger in particular cases, and it's certainly possible there are  
places in the frameworks where Apple does it, but the compiler's  
warning messages reflect the underlying assumption.


When the compiler sees a message sent to an object typed 'id', it  
checks to see if that message selector is defined at that point in the  
compilation. If it's not defined, you get a warning (that the object  
may not respond to that selector). If it's defined consistently in one  
or more classes that have been included in the compilation, there's no  
warning. If it's defined inconsistently in two or more classes  
included in the compilation, it issues the warning you saw. There's  
nothing arbitrary about it, and the compiler certainly doesn't "look  
through the project". If you don't include both of your offending  
class headers, you won't see the warning -- unless of course you're  
conflicting with frameworks headers that are included.


You may not like this behavior, but that's what it is.


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: intercepting NSBrowser multiple selection extension with shift down/up arrow

2008-10-14 Thread Martin Redington
On Tue, Oct 14, 2008 at 2:04 PM, Andy Lee <[EMAIL PROTECTED]> wrote:
> On Oct 14, 2008, at 8:11 AM, Martin Redington wrote:
>>
>> On Tue, Oct 14, 2008 at 8:12 AM, Andy Lee <[EMAIL PROTECTED]> wrote:
>>>
>>> If it helps with the ick factor, I
>>> would say that it's much less hacky to take advantage of one method's
>>> documented purpose -- "do something when the selection changes, even if
>>> it's
>>> via keyboard" -- than to do trivial overrides of multiple methods that
>>> you
>>> select by trial and error.
>>
>> Fair comment, although the documentation for setSendsActionOnArrowKeys
>> doesn't really state that explicitly - it probably wouldn't have
>> occurred to me to try that for a long time.
>
> Yeah, I was stretching for the interpretation my conscience would be most
> comfortable with :).  I think it's worth filing a Radar requesting
> notifications analogous to NSTableViewSelectionIsChangingNotification and
> NSTableViewSelectionDidChangeNotification.

rdar://6290957

> I did a quick search for a third-party alternative to NSBrowser, along the
> lines of what Rainer Brockerhoff did with RBSplitView.  I thought maybe
> there would be something at Cocoatech
> .  But I haven't found anything.

Koders seems to have some NSBrowser code in its index, which might
have something relevant, but I didn't look too closely.

http://www.koders.com/default.aspx?s=NSBRowser&btn=&la=ObjectiveC&li=*


>
> --Andy
>



-- 
http://www.mildmanneredindustries.com/
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: listening for changes to active application

2008-10-14 Thread Jason Coco


On Oct 14, 2008, at 11:58 , Robert Nikander wrote:


Hi,

How can I be notified when the foreground application changes?  I  
found "activeApplication" in NSWorkspace.  Is there a way to observe  
changes to that property?  I tried the following, which doesn't seem  
to work...


[[NSWorkspace sharedWorkspace] addObserver:obs  
forKeyPath:@"activeApplication" options: 0 context:NULL];

// where obs implements...
- (void)observeValueForKeyPath:ofObject:change:context:


You have to use the Carbon event manager to do this... there's no way  
to do it in Cocoa...

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: Not so long filenames

2008-10-14 Thread Jason Coco


On Oct 14, 2008, at 11:28 , Gerriet M. Denkmann wrote:

HFS+ and Finder can use filenames which use in Utf-16 up to 255  
shorts.


But in the program below there seems to exist some other limit (at  
least on 10.4.11 Tiger).

Where is this documented?
Or what am I doing wong?

... Filewrapper has preferred filename with 128 shorts in Utf16;  
Utf8 of fileSystemRepresentation has 256 bytes

... Error: writeToFile
Filename has exited with status 2.


I'm not really sure, but one thing I noticed right away is that 256 >  
255...


J

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Not so long filenames

2008-10-14 Thread Gerriet M. Denkmann

HFS+ and Finder can use filenames which use in Utf-16 up to 255 shorts.

But in the program below there seems to exist some other limit (at  
least on 10.4.11 Tiger).

Where is this documented?
Or what am I doing wong?


#import 

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

  NSData *data = [ @"Some Data" dataUsingEncoding:  
NSUTF8StringEncoding ];
  NSFileWrapper *aWrapper = [ [ NSFileWrapper alloc ]  
initRegularFileWithContents: data ];
	NSString *f2 = [ NSString stringWithUTF8String: 	//	64 * DESERET  
CAPITAL LETTER LONG I
			"𐐀𐐀𐐀 
𐐀𐐀 
𐐀𐐀 
𐐀"// 64

];
  [ aWrapper setPreferredFilename: f2 ];

  NSLog(@"%s Filewrapper has preferred filename with %u shorts in  
Utf16; "

"Utf8 of fileSystemRepresentation has %u bytes",
__FUNCTION__, [ f2 length], strlen([f2 
fileSystemRepresentation]));

  NSTextAttachment *attachment = [ [ NSTextAttachment alloc ]  
initWithFileWrapper: aWrapper ];
  NSAttributedString *textStorage = [ NSMutableAttributedString  
attributedStringWithAttachment: attachment ];


  NSRange all = NSMakeRange( 0, [ textStorage length ] );
  NSFileWrapper *fw = [ textStorage 	RTFDFileWrapperFromRange: all   
documentAttributes: nil ];

if ( fw == nil )//  error
{
NSLog(@"%s Error: RTFDFileWrapperFromRange",__FUNCTION__);
return 1;
};

NSString *path = @"/tmp/a.rtfd";
BOOL ok = [ fw writeToFile: path atomically: NO updateFilenames: NO ];
if ( !ok )  //  error
{
//  we come here if strlen([f2 fileSystemRepresentation]) > 
255

NSLog(@"%s Error: writeToFile",__FUNCTION__);
return 2;
};

NSLog(@"%s wrote rtfd wrapper %@",__FUNCTION__, path);

[pool release];
return 0;
}

Result:

... Filewrapper has preferred filename with 128 shorts in Utf16; Utf8  
of fileSystemRepresentation has 256 bytes

... Error: writeToFile
Filename has exited with status 2.

___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Providing replicable views in IB

2008-10-14 Thread Ashley Clark
You can implement copying of a view by archiving and immediately  
unarchiving the root view.


Something like this (written on the phone, don't expect this to parse  
correctly immediately):


-(id)copyWithZone:(NSZone *)zone {
 return [NSKeyedUnarchiver unarchiveObjectWithData: 
[NSKeyedArchiver archiveDataWithRootObject:self]];

}

__
Ashley

On Oct 14, 2008, at 10:38 AM, "Matteo Manferdini" <[EMAIL PROTECTED] 
> wrote:



Hi all,
I was trying to find a way to design a replicable view in IB.
The behaviour I'm trying to replicate is the one of  
NSCollectionView: it
gets a custom view designed in IB as the prototype view and then  
replicates
it to display its contents. Is there an easy way to do this? Since  
NSView

does not implement the copy method, I don't think this is the approach
taken.
The hard solution would be to provide a copy method myself that  
replicates
all the subviews and controls (which are also subviews), but it  
would be
very long and difficult since for each subview all the instance  
properties
must be replicated, without talking about sub-subviews. Since I  
don't want

to go throug all this, is there an easier way to do it?
Thank you very much.
Cheers.

Matteo Manferdini
Pawn Software
www.pawn-soft.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/aclark%40ghoti.org

This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


listening for changes to active application

2008-10-14 Thread Robert Nikander

Hi,

How can I be notified when the foreground application changes?  I  
found "activeApplication" in NSWorkspace.  Is there a way to observe  
changes to that property?  I tried the following, which doesn't seem  
to work...


[[NSWorkspace sharedWorkspace] addObserver:obs  
forKeyPath:@"activeApplication" options: 0 context:NULL];

// where obs implements...
- (void)observeValueForKeyPath:ofObject:change:context:

thanks,
Rob
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Providing replicable views in IB

2008-10-14 Thread Michael Ash
On Tue, Oct 14, 2008 at 11:38 AM, Matteo Manferdini
<[EMAIL PROTECTED]> wrote:
> Hi all,
> I was trying to find a way to design a replicable view in IB.
> The behaviour I'm trying to replicate is the one of NSCollectionView: it
> gets a custom view designed in IB as the prototype view and then replicates
> it to display its contents. Is there an easy way to do this? Since NSView
> does not implement the copy method, I don't think this is the approach
> taken.
> The hard solution would be to provide a copy method myself that replicates
> all the subviews and controls (which are also subviews), but it would be
> very long and difficult since for each subview all the instance properties
> must be replicated, without talking about sub-subviews. Since I don't want
> to go throug all this, is there an easier way to do it?
> Thank you very much.
> Cheers.

There are basically two ways to do it.

One way, the crappy way, which NSCollectionView uses, is to use
NSCoder. You'll note that NSView does not conform to NSCopying but it
does conform to NSCoding. So the easy way to "copy" a view is to
serialize and then deserialize it. This is crappy because it's kind of
unnatural, requires some extra work to maintain external connections,
and in general is just sort of clunky.

The other way, which I prefer, is to simply put the view in question
into a separate nib. Then just load the nib any time you want a new
view.

Mike
___

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

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

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

This email sent to [EMAIL PROTECTED]


Providing replicable views in IB

2008-10-14 Thread Matteo Manferdini
Hi all,
I was trying to find a way to design a replicable view in IB.
The behaviour I'm trying to replicate is the one of NSCollectionView: it
gets a custom view designed in IB as the prototype view and then replicates
it to display its contents. Is there an easy way to do this? Since NSView
does not implement the copy method, I don't think this is the approach
taken.
The hard solution would be to provide a copy method myself that replicates
all the subviews and controls (which are also subviews), but it would be
very long and difficult since for each subview all the instance properties
must be replicated, without talking about sub-subviews. Since I don't want
to go throug all this, is there an easier way to do it?
Thank you very much.
Cheers.

Matteo Manferdini
Pawn Software
www.pawn-soft.com
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: EXC_BAD_ACCESS with NSAutoReleasePool, NSThread and NSThreadWillExitNotification

2008-10-14 Thread Jonathan del Strother
On Tue, Oct 14, 2008 at 3:38 PM, John Zorko <[EMAIL PROTECTED]> wrote:
>
> Hello, all ...
>
> I'm experiencing a crash after a thread exits.
>
> Program received signal:  "EXC_BAD_ACCESS".
> (gdb) bt
> #0  0x300c8c18 in objc_msgSend ()
> #1  0x3067073a in NSPopAutoreleasePool ()
> #2  0x306770ea in __NSFinalizeThreadData ()
> #3  0x31446f6e in _pthread_tsd_cleanup ()
> #4  0x31449ae4 in _pthread_exit ()
> #5  0x3144b7e8 in pthread_exit ()
> #6  0x30676e66 in +[NSThread exit] ()
> #7  0x30673444 in __NSThread__main__ ()
> #8  0x3144a824 in _pthread_body ()
> #9  0x in ?? ()
> (gdb)
>

You're probably over-releasing something.  Turn on NSZombieEnabled to
find out what.
http://developer.apple.com/technotes/tn2004/tn2124.html
___

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

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

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

This email sent to [EMAIL PROTECTED]


EXC_BAD_ACCESS with NSAutoReleasePool, NSThread and NSThreadWillExitNotification

2008-10-14 Thread John Zorko


Hello, all ...

I'm experiencing a crash after a thread exits.

Program received signal:  “EXC_BAD_ACCESS”.
(gdb) bt
#0  0x300c8c18 in objc_msgSend ()
#1  0x3067073a in NSPopAutoreleasePool ()
#2  0x306770ea in __NSFinalizeThreadData ()
#3  0x31446f6e in _pthread_tsd_cleanup ()
#4  0x31449ae4 in _pthread_exit ()
#5  0x3144b7e8 in pthread_exit ()
#6  0x30676e66 in +[NSThread exit] ()
#7  0x30673444 in __NSThread__main__ ()
#8  0x3144a824 in _pthread_body ()
#9  0x in ?? ()
(gdb)

The NSThread itself runs well enough.  It allocates an autorelease  
pool and releases it at the end, like i've seen many NSThreads do:


- (void)startInternal
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

.
.
.

NSLog(@"- startInternal ending ... releasing pool");
[pool release];

exit;
}

I start this thread thusly:

- (void)start
{
	streamerThread = [[NSThread alloc] initWithTarget:self  
selector:@selector(startInternal) object:nil];


[[NSNotificationCenter defaultCenter] addObserver:self

  selector:@selector(threadStopped)

  name:NSThreadWillExitNotification

  object:streamerThread];
[streamerThread start];

appDelegate.playbackThreadFinished = false;
}

... and the threadStopped method does this:

- (void)threadStopped
{
NSLog(@"*** streamer thread has stopped ***");

[[NSNotificationCenter defaultCenter] removeObserver:self];

appDelegate.playbackThreadFinished = true;
}

Now, in my main thread, I have an observer on playbackThreadFinished  
that I set up as soon as the app launches (before the other thread is  
created):


	[self addObserver:self forKeyPath:@"playbackThreadFinished" options:0  
context:nil];



... and when I see the "playbackThreadFinished" notification, I do  
things like see if there is a new song to play, etc.


- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change 
context:(void *)context
{
	NSLog(@"observeValueForKeyPath -- current thread ID: %x, keypath:  
%s", [NSThread currentThread], [keyPath UTF8String]);


if ([keyPath isEqualToString:@"isPlaying"])
{
.
.
.
return;
}
else if ([keyPath isEqualToString:@"playbackThreadFinished"])
{
if (playbackThreadFinished)
{
// ... if we're in shuffle mode

if (playShuffleFlag)
{
if ([self.shufflePlayedList count] < [self 
countOfSongList])
{
NSUInteger randomSong;

do
{
randomSong = (int)(rand() % 
[self countOfSongList]);
}
	while ([self.shufflePlayedList indexOfObject:[NSNumber  
numberWithInt:randomSong]] != NSNotFound);


NSLog(@"play shuffle advancing to song 
%i", randomSong);
NSNumber *num = [[NSNumber alloc] 
initWithInt:randomSong];
[self.shufflePlayedList addObject:num];
[num release];

self.nextSong = randomSong;
}
else
{
NSLog(@"shuffle play has played all songs in 
the list");
	[artistViewController  
popToViewController:artistViewController.artistAlbumSongController  
animated:YES];

}
}

// ... if we're in album play mode

else if (playEntireAlbumFlag)
{
if (self.currentSong < [self countOfSongList] - 
1)
{
self.currentSong ++;
	NSLog(@"play album advancing to song %d of %d", self.currentSong,  
[self countOfSongList]);

self.nextSong = currentSong;
}
}

// ... if the user jus

Re: UI elements in custom view mess up drawing

2008-10-14 Thread Antonio Nunes

On 14 Oct 2008, at 14:43, Benjamin Stiglitz wrote:


The rect passed to -[NSView drawRect:] is the dirty rect of the view,
not the bounds of the view. The changing subviews are dirtying your  
view
and then you're drawing as if that changed area was your complete  
frame.


Try replacing your use of rect with -[NSView bounds] instead


Argh! I had a sinking feeling my brain was muddled up. It works now  
(the view that is, not sure about the brain ;-). Thanks!


-António


It is better to light a candle than to curse the darkness




___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSBrowser, NSTreeController and Core Data

2008-10-14 Thread Mark .


On Oct 13, 2008, at 15:44, Quincey Morris wrote:

> Your relationship is from categories to subcategories (and inversely
> from categories to parent categories). So calling the relationship
> "id" makes no sense. IAC, to-many relationship names make more sense
> if they're plural ("categories" instead of "id", and "parentCategory"
> instead of "parentID").

But I'm going to need to know the id of the category the user ultimately 
selects.  And, I'm reading it as one parentID to-many ids.


> If 'childNode' is of a Cocoa class like NSXMLNode, [childNode
> stringValue] is going to return the same value each time, which
> doesn't look like what you want. If you're trying to get to various
> XML nodes or attributes, you're going to have to do it a different
> way. (Or perhaps you've invented a class that returns different
> results each time.) This all suggests that you believe that the
> relationships are implemented by matching of (string) names. They're
> not. Relationships are object references. Core Data is an object
> graph, not a database.

I'm sorry.  I should have included the other code.  I realize that 
relationships are object references.  I am handling it in a different way.  
I'm looping through the nodes.  Also, what I had as "childNode", is actually 
"categoryChildNode".


// Get an enumerator that contains all the children of this one category 
listed in the XML


NSEnumerator *categoryChildEnumerator = [[categoryNode children] 
objectEnumerator];

NSXMLNode *categoryChildNode = nil;

while (categoryChildNode = [categoryChildEnumerator nextObject]) {

   NSString *categoryChildName = [categoryChildNode name];

   if ([categoryChildName isEqualToString:@"CategoryName"])
   {
   [category setValue:[categoryChildNode stringValue] forKey:@"name"];
   }
   else if ([categoryChildName isEqualToString:@"CategoryID"])
   {
   [category setValue:[childNode stringValue] forKey:@"id"];
   }
   else if ([categoryChildName isEqualToString:@"CategoryParentID"])
   {
   [category setValue:[childNode stringValue] forKey:@"parentID"];
   }


... and so on

}

All this works fine with core data and an NSTextView.

> When you create a category object, it's going to have no subcategories
> yet, so there's nothing to set for that relationship immediately. If
> it has a parent, you need to find the parent object (possibly via the
> name of the parent object, which is another subject), and set that
> object for the parent relationship. (The inverse will get set
> automatically.)

> The to-many relationship is a NSSet, so if you ever need to add or
> remove subcategories from an object directly, you would use NSSet
> accessors. You won't use [setValue:forKey:] for that.

Given the error I received, I guess this is really my main question then.  
How do I do this?  Do I need to create a custom managed object class?


Regards,
Mark.


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: replacing carbon menu with cocoa

2008-10-14 Thread Esteban Lorenzano

Hi,
I loaded from Nib, as you suggest, and something strange happens - 
strange, but near what I need-


If I load a Nib, the new main menu overlaps the old one (and two menus  
coexist)... but new Main Menu redraws "apple" menu too, and disappear  
if I reload the Nib. Finally, if I first "clean" carbon menu, and then  
load bundle twice, everything seems to be working. This is the code I  
wrote:


static sqInt initializeCocoaMenu(void) {
MenuRef cleanMenu;

//First we clean the carbon menu
CreateNewMenu(menuId, 0, &cleanMenu);
SetMenuTitleWithCFString(cleanMenu, CFSTR(""));
SetRootMenu(cleanMenu);
//Then we load the bundle
	[ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication  
sharedApplication ] ];

//... twice
	[ NSBundle loadNibNamed: @"MarsPlugin" owner: [ NSApplication  
sharedApplication ] ];

return sqNil;
}

... but this is ok?

Thanks,
Esteban

On 13/10/2008, at 4:27p.m., Peter Ammon wrote:



On Oct 13, 2008, at 5:18 AM, Esteban Lorenzano wrote:


Hi,
I'm new to the list -and to cocoa-, and I don't know if what I want  
to do is possible: I'm writing a plugin for a previous existent  
application made in carbon, the application will take over the old  
app behavior, and for that, it needs to replace the menu with a new  
one...
I read documentation, saw examples and followed old threads on this  
list, and no one is very clear about this... ¿Is it possible? ¿how?


You should make a nib from the "Application" template in Interface  
Builder, then load it via [NSBundle loadNibNamed:...].  Its main  
menu will replace the current main menu.




I already tried

[ NSApp setMainMenu: myMenu ]

It does not fail, but nothing happens :(


It's hard to say what this would do without seeing the code that  
creates myMenu.  But there's some problems creating a main menu  
programmatically; using a nib is the best approach.


-Peter



"Querer es suscitar las paradojas"
Camus - El mito de Sísifo

___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: UI elements in custom view mess up drawing

2008-10-14 Thread Graham Cox


On 15 Oct 2008, at 12:38 am, Antonio Nunes wrote:

As you can see from the image it looks like the view first draws  
itself correctly, then gets drawn for each of the other subviews,  
with its origin offset to match the origin of the subview in  
question. I don't understand why this happens.


You've made the classic error of assuming that 'rect' passed to  
drawRect: is your view's bounds. It's not. It's the area requiring  
update.


Replace all references to 'rect' with [self bounds] and all will be  
well. This must crop up at least once or twice a month.


hth,


Graham
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: UI elements in custom view mess up drawing

2008-10-14 Thread Benjamin Stiglitz
> When I turn off the progress indicator 
> however, or when I update the string value of the text field, the drawing 
> from the drawRect method above is drawn offset from its origin, instead 
> drawing at the origin of either of the subviews, resulting in spurious 
> lines being drawn where there should only be background (the gradient). 
> (You can see a screenshot of the effect here: 
> http://sintraworks.com/private/RenderingMess.png)

The rect passed to -[NSView drawRect:] is the dirty rect of the view,
not the bounds of the view. The changing subviews are dirtying your view
and then you're drawing as if that changed area was your complete frame.

Try replacing your use of rect with -[NSView bounds] instead, and then
take a look at the View Programming Guide [1].

-Ben

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


UI elements in custom view mess up drawing

2008-10-14 Thread Antonio Nunes

Hi,

I have a custom view that draws half a frame and a gradient:

- (void)drawRect:(NSRect)rect {

// This results in darker separator line at left side.
[[NSColor colorWithCalibratedWhite:0.18 alpha:1.0] set];
NSRectFill(NSMakeRect(NSMinX(rect), NSMinY(rect), 1, NSHeight(rect)));

// This results in lighter separator line along bottom.
[[NSColor colorWithCalibratedWhite:0.41 alpha:1.0] set];
	NSRectFill(NSMakeRect(NSMinX(rect) + 1, NSMinY(rect), NSWidth(rect) -  
1, NSHeight(rect)));


// Draw background
	NSGradient *gradient = [[NSGradient alloc] initWithStartingColor: 
[NSColor colorWithCalibratedWhite:0.63 alpha:1.0] endingColor:[NSColor  
colorWithCalibratedWhite:1.0 alpha:1.0]];
	[gradient drawInRect:NSMakeRect(NSMinX(rect) + 1, NSMinY(rect) + 1,  
NSWidth(rect), NSHeight(rect) - 1) angle:90.0];


}

In Interface Builder I set an Async progress indicator and a text  
field as subviews of the custom view. When I turn off the progress  
indicator however, or when I update the string value of the text  
field, the drawing from the drawRect method above is drawn offset from  
its origin, instead drawing at the origin of either of the subviews,  
resulting in spurious lines being drawn where there should only be  
background (the gradient). (You can see a screenshot of the effect  
here: http://sintraworks.com/private/RenderingMess.png)


As you can see from the image it looks like the view first draws  
itself correctly, then gets drawn for each of the other subviews, with  
its origin offset to match the origin of the subview in question. I  
don't understand why this happens.


I have tried several workarounds in IB, among others by promoting the  
async arrows and text field to not be subviews of the custom view, but  
simply sit on top of it, but none of the solutions seems to make any  
difference. Any pointers as to what the issue may be and how I can  
solve it?


Kind Regards,
António Nunes
SintraWorks

-
Forgiveness is not an occasional act;
it is a permanent attitude.

--Martin Luther King, Jr
-




___

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

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

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

This email sent to [EMAIL PROTECTED]


[CODE] JPDurationToDecimalNumberFormatter

2008-10-14 Thread Jamie Phelps
Hi, all. I have received so much help from this list that I wanted to  
share a small something back. It is a subclass of NSNumberFormatter to  
format time duration. It works for me but I'm sure it could be  
improved as well. You can download it from my iDisk public folder (http://idisk.mac.com/jrphelps-Public 
 from the web) under Code/JPDurationToDecimalNumberFormatter.zip


I wrote this class for a calculator application for computing selling  
prices for products based on time required and an hourly rate. It  
could also be used for a billing application or anywhere else time  
formatting is desirable.


It handles times in the format [dd:]hh:mm meaning that if there are  
two components, it reads as hours and minutes but if you add a third  
component it reads as days, hours, and minutes. It then converts this  
value into a decimal number representing the number of hours. So,  
12:15 would be 12.25, 1:13:45 would be 37.75. If the user enters  
anything other than a colon separated string, it falls back to super.  
It can also handle input as a decimal and then convert it to time  
formatted string so 8.5 can be entered and display as 8:30.


Anyway, I hope someone finds it useful and I welcome your thoughts,  
comments, and improvements. I have licensed it as a Creative Commons  
Attribution-Share Alike 3.0 United States license. If this is too  
restrictive, tell me. What I want is the "Don't Be a Jerk" and "Tell  
Me If You Use It" license. :)


Cheers,
Jamie
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: intercepting NSBrowser multiple selection extension with shift down/up arrow

2008-10-14 Thread Andy Lee

On Oct 14, 2008, at 8:11 AM, Martin Redington wrote:

On Tue, Oct 14, 2008 at 8:12 AM, Andy Lee <[EMAIL PROTECTED]> wrote:

If it helps with the ick factor, I
would say that it's much less hacky to take advantage of one method's
documented purpose -- "do something when the selection changes,  
even if it's
via keyboard" -- than to do trivial overrides of multiple methods  
that you

select by trial and error.


Fair comment, although the documentation for setSendsActionOnArrowKeys
doesn't really state that explicitly - it probably wouldn't have
occurred to me to try that for a long time.


Yeah, I was stretching for the interpretation my conscience would be  
most comfortable with :).  I think it's worth filing a Radar  
requesting notifications analogous to  
NSTableViewSelectionIsChangingNotification and  
NSTableViewSelectionDidChangeNotification.


I did a quick search for a third-party alternative to NSBrowser, along  
the lines of what Rainer Brockerhoff did with RBSplitView.  I thought  
maybe there would be something at Cocoatech .  But I haven't found anything.


--Andy

___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: +(NSSet *)keyPathsForValuesAffectingValueForKey:

2008-10-14 Thread Clark Cox
On Mon, Oct 13, 2008 at 9:43 PM, Chris Idou <[EMAIL PROTECTED]> wrote:
>
> Does anyone know if you can use this mechanism for dotted values, or does it 
> have to be a value local to the object?

Yes, you can use dotted values (that is why it is
keyPathsForValues..., not keysForValues...)

>
> For example, could you say that field "a" depends on "b.c"? I'm trying to do 
> that but it doesn't seem to work or me.

Are you sure that appropriate KVO notifications are being posted for b.c?


-- 
Clark S. Cox III
[EMAIL PROTECTED]
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: intercepting NSBrowser multiple selection extension with shift down/up arrow

2008-10-14 Thread Martin Redington
On Tue, Oct 14, 2008 at 8:12 AM, Andy Lee <[EMAIL PROTECTED]> wrote:
> On Oct 14, 2008, at 12:45 AM, Martin Redington wrote:
>>
>> On Tue, Oct 14, 2008 at 5:25 AM, Andy Lee <[EMAIL PROTECTED]> wrote:
>>>
>>> How about if you leave the matrix class alone and do [myBrowser
>>> setSendsActionOnArrowKeys:YES]?  Then give the browser a target and
>>> action,
>>> and in the action method do whatever you have to do.
>>
>> That sounds promising, although a bit disappointing and possibly still
>> a tiny bit hacky.
>
> It works for me.

Me too :-) with a couple of exceptions ... see below ...

> I did a quick test and it caught all the cases I tried,
> though I may have missed something.

I managed to remove all of my other notification posts, apart from

selectAll:

I also found that when modifying the selection programmatically, I
needed to post the notification manually, so a more general mechanism
than I require would need to post from at least a subset of the
selectXXX: methods.

> If it helps with the ick factor, I
> would say that it's much less hacky to take advantage of one method's
> documented purpose -- "do something when the selection changes, even if it's
> via keyboard" -- than to do trivial overrides of multiple methods that you
> select by trial and error.

Fair comment, although the documentation for setSendsActionOnArrowKeys
doesn't really state that explicitly - it probably wouldn't have
occurred to me to try that for a long time.

>> Surely it shouldn't really be that hard to capture/intercept selection
>> changes - to have to resort to trial and error over-riding of
>> selectXXX, et al. methods is a bit irksome.
>
> I agree, it seems a weird omission, given that with NSTableView you have a
> choice of using either a delegate method or a notification for that very
> purpose.
>
> --Andy
>



-- 
http://www.mildmanneredindustries.com/
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Graham Cox


On 14 Oct 2008, at 10:11 pm, Chris Suter wrote:


I believe the fact that they are class clusters is irrelevant; it's an
implementation detail. The objects returned still conform to the
interfaces defined by NSString and NSMutableString. They return id,
rather than NSString say, because otherwise you'd get a compiler
warning if you tried to do something like:

   NSMutableString *string = [NSMutableString string];


Well, that was my point. Maybe my terminology was incorrect - the  
point is that returning id allows this convenience with classes that  
derive from a common base. That isn't the case with the OP's code. He  
has two entirely separate classes that happen to share the same init  
method name. They *could* return the class type instead of id, as long  
as he doesn't plan to subclass them further. Whether that's OK in his  
case would have to be considered.



but for your own classes, you could define your
init... method to return the specific object type.


You can't override the type for existing methods. For example,
initWithString: always returns an id. You can define them as returning
something different but the compiler will ignore it.



I'm not talking about existing methods. I'm talking about the unique - 
initWithContext: methods that the OP defined.


I'm not even saying it's a good idea - I'd always return id from an  
init method because that's least confusing all round. And, as I said,  
I don't think it would help anyway - the return type is ignored when  
determining which of a pair of otherwise identically named methods to  
compile against. In fact this last point is potentially dangerous as I  
found out to my cost earlier this year (e.g. see: http://www.cocoabuilder.com/archive/message/cocoa/2008/6/5/209327)



Best solution is just not to make the methods look the same.


That's not always convenient. For example, it's nice to be able to do
[NSString initWithString:] and [NSMutableString initWithString:].


Yes. My point was that the OP has the option to do this, because it's  
his own code. I'm not advocating for one microsecond that anything in  
Cocoa should be changed. Well, at least not on this one point. ;-)


--Graham
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Chris Suter
On Tue, Oct 14, 2008 at 9:13 PM, Graham Cox <[EMAIL PROTECTED]> wrote:

> Isn't the problem here with the init method, rather than alloc?

It's a problem with both.

> NSString et. al. return id because they are class clusters (and because it's 
> the
> established convention),

I believe the fact that they are class clusters is irrelevant; it's an
implementation detail. The objects returned still conform to the
interfaces defined by NSString and NSMutableString. They return id,
rather than NSString say, because otherwise you'd get a compiler
warning if you tried to do something like:

NSMutableString *string = [NSMutableString string];

> but for your own classes, you could define your
> init... method to return the specific object type.

You can't override the type for existing methods. For example,
initWithString: always returns an id. You can define them as returning
something different but the compiler will ignore it.

> Best solution is just not to make the methods look the same.

That's not always convenient. For example, it's nice to be able to do
[NSString initWithString:] and [NSMutableString initWithString:].

-- Chris
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Graham Cox


On 14 Oct 2008, at 8:58 pm, Chris Suter wrote:


The proper way to solve this, in my opinion, is to allow a way of
specifying that the return type varies depending on the class it's
implemented on i.e. define the alloc method in such a way so that the
compiler knows that -[ alloc] returns an object of type
. Something similar could be used for [NSString string] and
[NSMutableString string] which have a similar problem (they return an
id, rather than an NSString or NSMutableString).



Isn't the problem here with the init method, rather than alloc?  
NSString et. al. return id because they are class clusters (and  
because it's the established convention), but for your own classes,  
you could define your init... method to return the specific object  
type. If your class is not intended for subclassing or public  
consumption, that should be fine.


Having said that though, there's still the problem of the return type  
not being an intrinsic part of the method signature when parsed by the  
compiler, so it might not fix the problem anyway.


Best solution is just not to make the methods look the same.

--Graham
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Chris Suter
On Tue, Oct 14, 2008 at 8:17 PM, Oleg Krupnov <[EMAIL PROTECTED]> wrote:
> You are right, casting from alloc worked, thank you.
>
> Is it the recommended practice to always cast after alloc?
>
> I still have a question in this regard.
>
> If the alloc returns id, then, from the compiler's perspective, there
> can be two solutions: 1) assume that the id type can have each and any
> method and let it be resolved at run time without any compiler warning
> or

This won't work. The compiler emits different code depending upon the
types involved. For example, there are differences depending on
whether the return types are structures, floating point or integer
values.

> 2) assume that the id does not have any methods (except NSObject's)
> and always issue a compiler warning when there is no explicit casting
> to a type.

Well that would be a pain. You'd get warnings everywhere. id, by
definition, can be sent anything.

> What compiler seems to be doing is rather strange: it looks
> through the project, arbitrarily picks up a class with the matching
> message name and issues a warning if the rest of the actual message
> signature is not matching. How would you explain that?

It comes down to the point I made above. It needs to know about the types.

The proper way to solve this, in my opinion, is to allow a way of
specifying that the return type varies depending on the class it's
implemented on i.e. define the alloc method in such a way so that the
compiler knows that -[ alloc] returns an object of type
. Something similar could be used for [NSString string] and
[NSMutableString string] which have a similar problem (they return an
id, rather than an NSString or NSMutableString).

-- Chris
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Graham Cox


On 14 Oct 2008, at 8:17 pm, Oleg Krupnov wrote:


You are right, casting from alloc worked, thank you.

Is it the recommended practice to always cast after alloc?


No, I never do it. I never see code that routinely does it either.


I still have a question in this regard.

If the alloc returns id, then, from the compiler's perspective, there
can be two solutions: 1) assume that the id type can have each and any
method and let it be resolved at run time without any compiler warning
or 2) assume that the id does not have any methods (except NSObject's)
and always issue a compiler warning when there is no explicit casting
to a type. What compiler seems to be doing is rather strange: it looks
through the project, arbitrarily picks up a class with the matching
message name and issues a warning if the rest of the actual message
signature is not matching. How would you explain that?



The compiler uses the first one it finds. What else is it to do, as it  
has nothing else to go on, and there's nothing to distinguish the two  
methods? It doesn't arbitrarily pick one, though it might seem that  
way - it goes with the first it found.


Chris's suggestion of using more descriptive method names is good  
advice - your code will not only be more readable to you, it won't  
trip up the compiler in this way. The casting that you're doing is not  
improving readability *for you*, and anything that doesn't help in  
that regard is hindering.


hth,

Graham
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Roland King

Oleg Krupnov wrote:


You are right, casting from alloc worked, thank you.

Is it the recommended practice to always cast after alloc?

 

Not really - the recommended practice is to have method names which have 
unique parameter types. Remember that Objective-C's notion of a selector 
is foo:bar:baz:, it doesn't encode what the types of the parameters are 
(or the return type). So if you  make every foo:bar:baz: have the same 
parameter types even though the compiler isn't going to enforce that for 
you, life gets simpler. If you have something which is very generic, 
like setDelegate: then you could make the parameter an id and test it in 
the code.


I have found myself more and more doing methods like this

-(void) methodWithSomeClass:(SomeClass*)someClassArg 
anotherClass:(AnotherClass*)anotherClassArg 
aSimilarClass:(ASimilarClass*)aSimilarClassArg;


and using the class names in the selector. It's verbose but .. 
objective-C seems to be verbose (I wish I could get XCode to fill in a 
template for the stuff I defined in the .h file when I go to define it 
in the .m file though)



I still have a question in this regard.

If the alloc returns id, then, from the compiler's perspective, there
can be two solutions: 1) assume that the id type can have each and any
method and let it be resolved at run time without any compiler warning
or 2) assume that the id does not have any methods (except NSObject's)
and always issue a compiler warning when there is no explicit casting
to a type. What compiler seems to be doing is rather strange: it looks
through the project, arbitrarily picks up a class with the matching
message name and issues a warning if the rest of the actual message
signature is not matching. How would you explain that?
 

Well I'd expect the compiler remembers the methods available for each 
class, cached under the selector name (remember no argument types in the 
selector name). So if you have two identically named selectors in two 
different classes but you call them ON instances of that class, all is 
fine. For id, the most generic class, I'd expect it caches the first one 
it finds with that selector name, then if you use it with different 
parameters, it warns you then. It could warn you at the point you 
declare the selector with different arguments, but that would be 
unecessary, because provided you used it on class instances, not ids, 
there's no ambiguity. So warning you at the point you use it on an id 
makes most sense.

___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Oleg Krupnov
You are right, casting from alloc worked, thank you.

Is it the recommended practice to always cast after alloc?

I still have a question in this regard.

If the alloc returns id, then, from the compiler's perspective, there
can be two solutions: 1) assume that the id type can have each and any
method and let it be resolved at run time without any compiler warning
or 2) assume that the id does not have any methods (except NSObject's)
and always issue a compiler warning when there is no explicit casting
to a type. What compiler seems to be doing is rather strange: it looks
through the project, arbitrarily picks up a class with the matching
message name and issues a warning if the rest of the actual message
signature is not matching. How would you explain that?


On Tue, Oct 14, 2008 at 12:00 PM, Chris Suter <[EMAIL PROTECTED]> wrote:
> On Tue, Oct 14, 2008 at 7:43 PM, Oleg Krupnov <[EMAIL PROTECTED]> wrote:
>> In my project I have two different, totally unrelated classes.
>>
>> @interface ClassA : NSObject{}
>>
>> -(id)initWithContext:(ContextA*)context;
>>
>> @end
>>
>>
>> @interface ClassB : NSObject{}
>>
>> -(id)initWithContext:(ContextB*)context;
>>
>> @end
>>
>> The problem is that when I call
>>
>> ContextA* context = ...;
>> [[ClassA alloc] initWithContext:context];
>>
>> Not in all cases, but in some I get the warning that the var "context"
>> is of different type (ContextA) than expected (ContextB). It seems
>> like the compiler erroneously resolves this call to ClassB instead of
>> ClassA, I guess because the two methods have the same name. This
>> problem disappears if I rename one of the methods to
>> "initWithContext2".
>>
>> I'd like to keep the same name and I hate the compiler warning. Is
>> there any resolution? Is it really a bug of the Obj-C compiler?
>
> No, it's not a bug.
>
> The problem is that the compiler doesn't know which method you mean
> because the "alloc" call returns an id. Either change the names of
> your methods (which might make sense given that "context" doesn't tell
> you much) or cast the return from alloc to the appropriate type. You
> could use a macro to make it slightly more readable.
>
> -- Chris
>
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSCollectionView - getting notified of selection change?

2008-10-14 Thread Graham Cox


On 14 Oct 2008, at 6:08 pm, Markus Spoettl wrote:

Since you have to have an array controller to get the collection  
view its data there is no overhead in this method.



Well, I don't have an array controller. I just set the view's content  
using -setContent:, as documented. Maybe the bug only shows up in this  
case? I'd better make that clear in my bug report.


--Graham
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: [Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Chris Suter
On Tue, Oct 14, 2008 at 7:43 PM, Oleg Krupnov <[EMAIL PROTECTED]> wrote:
> In my project I have two different, totally unrelated classes.
>
> @interface ClassA : NSObject{}
>
> -(id)initWithContext:(ContextA*)context;
>
> @end
>
>
> @interface ClassB : NSObject{}
>
> -(id)initWithContext:(ContextB*)context;
>
> @end
>
> The problem is that when I call
>
> ContextA* context = ...;
> [[ClassA alloc] initWithContext:context];
>
> Not in all cases, but in some I get the warning that the var "context"
> is of different type (ContextA) than expected (ContextB). It seems
> like the compiler erroneously resolves this call to ClassB instead of
> ClassA, I guess because the two methods have the same name. This
> problem disappears if I rename one of the methods to
> "initWithContext2".
>
> I'd like to keep the same name and I hate the compiler warning. Is
> there any resolution? Is it really a bug of the Obj-C compiler?

No, it's not a bug.

The problem is that the compiler doesn't know which method you mean
because the "alloc" call returns an id. Either change the names of
your methods (which might make sense given that "context" doesn't tell
you much) or cast the return from alloc to the appropriate type. You
could use a macro to make it slightly more readable.

-- Chris
___

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

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

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

This email sent to [EMAIL PROTECTED]


[Obj-C Compiler Bug?] Two different classes declaring a message with the same name - compiler warning

2008-10-14 Thread Oleg Krupnov
In my project I have two different, totally unrelated classes.

@interface ClassA : NSObject{}

-(id)initWithContext:(ContextA*)context;

@end


@interface ClassB : NSObject{}

-(id)initWithContext:(ContextB*)context;

@end

The problem is that when I call

ContextA* context = ...;
[[ClassA alloc] initWithContext:context];

Not in all cases, but in some I get the warning that the var "context"
is of different type (ContextA) than expected (ContextB). It seems
like the compiler erroneously resolves this call to ClassB instead of
ClassA, I guess because the two methods have the same name. This
problem disappears if I rename one of the methods to
"initWithContext2".

I'd like to keep the same name and I hate the compiler warning. Is
there any resolution? Is it really a bug of the Obj-C compiler?
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: intercepting NSBrowser multiple selection extension with shift down/up arrow

2008-10-14 Thread Andy Lee

On Oct 14, 2008, at 12:45 AM, Martin Redington wrote:

On Tue, Oct 14, 2008 at 5:25 AM, Andy Lee <[EMAIL PROTECTED]> wrote:

How about if you leave the matrix class alone and do [myBrowser
setSendsActionOnArrowKeys:YES]?  Then give the browser a target and  
action,

and in the action method do whatever you have to do.


That sounds promising, although a bit disappointing and possibly still
a tiny bit hacky.


It works for me.  I did a quick test and it caught all the cases I  
tried, though I may have missed something.  If it helps with the ick  
factor, I would say that it's much less hacky to take advantage of one  
method's documented purpose -- "do something when the selection  
changes, even if it's via keyboard" -- than to do trivial overrides of  
multiple methods that you select by trial and error.


The only possible issue I found with this approach is that it also  
catches at least one case where the selection *isn't* changing: if you  
have just one cell selected and you click it, the action method will  
be called even though the selection hasn't changed.  That should be  
easy to work around if it causes a problem.



Surely it shouldn't really be that hard to capture/intercept selection
changes - to have to resort to trial and error over-riding of
selectXXX, et al. methods is a bit irksome.


I agree, it seems a weird omission, given that with NSTableView you  
have a choice of using either a delegate method or a notification for  
that very purpose.


--Andy

___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSCollectionView - getting notified of selection change?

2008-10-14 Thread Markus Spoettl

On Oct 13, 2008, at 8:10 PM, Graham Cox wrote:



OK, it's a bug. Filed. Bah...



I'm a little late to this and I'm not really sure what the problem is.  
In my app I'm observing the -selectedObjects property of the  
NSArrayController that supplies the data to the NSCollectionView.  
Works without any problem. Since you have to have an array controller  
to get the collection view its data there is no overhead in this method.


Regards
Markus
--
__
Markus Spoettl



smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: how to create a faceless background application

2008-10-14 Thread Joseph Crawford

han,

by any chance would you be talking about NSThread?  You want to break  
a process off into another thread to complete your calculation then  
notify your application when it is completed.  This will not hold up  
the UI while doing the calculation.


I am not sure how to implement it as I am still new but NSThread seems  
to be what you are looking for.


Joseph Crawford


On Oct 14, 2008, at 2:53 AM, han wrote:

My application uses a faceless background application to perform  
some calculations. This background application is launched and  
terminated by my foreground application.But


I don't know how to create a faceless background application?
thanks.


___

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

This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: how to create a faceless background application

2008-10-14 Thread Jens Beuckenhauer

Hello,

My application uses a faceless background application to perform  
some calculations. This background application is launched and  
terminated by my foreground application.But


I don't know how to create a faceless background application?


1.) start Xcode
2.) choose "New Project"
3.) choose "Mac OS X/Command Line Utility/Foundation Tool"

Greetings
Jens
___

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

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

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

This email sent to [EMAIL PROTECTED]