Re: NSDistributedNotificationCenter questions.

2011-02-19 Thread Mr. Gecko
Something like this?

static NSAutoreleasePool *pool = nil;

void runloop(CFRunLoopObserverRef observer, CFRunLoopActivity activity, void 
*info) {
if (activity & kCFRunLoopEntry) {
if (pool!=nil) [pool drain];
pool = [NSAutoreleasePool new];
} else if (activity & kCFRunLoopExit) {
[pool drain];
pool = nil;
}
}

CFRunLoopObserverContext  context = {0, self, NULL, NULL, NULL};
CFRunLoopObserverRef observer = CFRunLoopObserverCreate(kCFAllocatorDefault, 
kCFRunLoopEntry | kCFRunLoopExit, YES, 0, runloop, &context);
CFRunLoopAddObserver(CFRunLoopGetCurrent(), observer, kCFRunLoopDefaultMode);

I know the way I'm doing it works, but I want to verify it's right.

On Feb 18, 2011, at 9:58 PM, Kyle Sluder wrote:

> Nest your own autorelease pool. You can use a runloop observer to make
> sure it gets drained regularly.
> 
> There's a constant somewhere that says what priority AppKit's
> NSAutoreleasePool runloop observer uses, but I can't find it in the
> documentation right now. You can insert yourself above that priority
> to ensure that your runloop wraps AppKit's.
> 
> --Kyle Sluder



smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

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

NSTextAttachment, MouseOver, GlyphPosition

2011-02-19 Thread Peter Krajčík
Hi,

I have subclassed NSTextAttachment/NSAttachemntCell pair and I need to 
implement mouseOver.
NSTextAttachment are inserted programatically to NSTextField's 
NSAttributedString object, displayed correctly
and I can manipulate them.
I have found not very elegant way how to create and track NSTrackingArea for 
each NSTextAttachment character in
NSTextField, but I am not happy with the way how I am getting NSRect 
representing NSTextAttachment.

What is a proper way to get cellFrame for NSTextAttachmentCell (or to be more 
general, position of glyph in NSAttributedString) that is inserted to 
NSAttributedString or drawn by NSTextFieldCell?

I think could use NSLayoutManager that could return a glyph position I could 
use as origin to calculate cellFrame, but
I have no idea how to get NSLayoutManager from NSTextField | NStextFieldCell | 
NSAttributted object.

Thank you.

Peter

___

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

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

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

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


inter-process locks

2011-02-19 Thread Alexander Cohen
Hello,

Is there anyway to do interprocess locks using cocoa ( like a Mutex in Win32 )? 
The best i've found is not cocoa and uses flock but the man pages say its 
advisory only which is kindof scary.

any help appreciated.

thx

AC___

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

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

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

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


Getting NSScrollView to ignore scrolling

2011-02-19 Thread Andrew Shamel
HI All,

I have a NSTableView/NSScrollView setup that I've configured automatically to 
resize to contain the content of the table.  This may sound silly, but I don't 
want scrolling behavior, but NSTableView seems to be designed to be inside a 
NSScrollView.  

My question is this: how do I get the scroll view to ignore scrolling messages? 
 The tables/scrollviews are sitting on views that are part of a homebrew 
collection view, and the scrolling "catches" on them, even though there's no 
scrolling to be done.  The scroll view is taking the events, but there is 
nothing for them to do.  I want to be able to scroll past the table using a 
scrollwheel or the trackpad without the scrolling action "catching."

Any ideas?

Thank you so much!!

Pax,

Andy Shamel___

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

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

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

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


Re: inter-process locks

2011-02-19 Thread Michael Babin
On Feb 19, 2011, at 12:29 PM, Alexander Cohen wrote:

> Is there anyway to do interprocess locks using cocoa ( like a Mutex in Win32 
> )? The best i've found is not cocoa and uses flock but the man pages say its 
> advisory only which is kindof scary.

NSDistributedLock:


Although I've never used it in practice. The current project I'm working on 
uses a scheme based on flock.

___

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

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

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

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


Connect iPad to Servlets on a Web Server

2011-02-19 Thread Bing Li
Dear all,


I am a new programmer on iMac. I have a Tomcat Web server. I would like to
connect my iPad to the servlets on the Web server.


However, I have not got the approaches to do that. I am reading the
articles, URL Loading System Programming Guide and CFNetwork Programming
Guide. According to the books, I believe my goal must be achieved on iPad.
Unfortunately, I cannot get complete samples from the articles. Since I am a
new programmer, I cannot run them correctly. Could you please provide me
with some relevant resources? Or could you tell me what prerequisites to
read the articles so that I learn the skills step by step?


I appreciate so much for your help!


LB
___

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

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

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

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


Re: inter-process locks

2011-02-19 Thread Greg Guerin

Alexander Cohen wrote:

Is there anyway to do interprocess locks using cocoa ( like a Mutex  
in Win32 )? The best i've found is not cocoa and uses flock but the  
man pages say its advisory only which is kindof scary.



man semget
man semop
man semctl

They're part of the Posix IPC functions, so obviously work across  
processes.


Like other Posix IPC functions, the proper use of the semaphore  
functions can be inscrutable.  I recommend searching for working  
examples rather than puzzling it out from man pages alone.


  -- GG

___

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

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

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

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


NSCalendar dateByAddingComponents: yields inconsistent results

2011-02-19 Thread Jim Thomason
I'm utterly stumped.

I haven't managed to boil this down to a succinct test case yet. It
only intermittently appears, basically, after I end up doing a "lot"
of date calculations on a separate thread. For some nebulous value of
a "lot".

The gyst is this - on occasion, NSCalendar's
dateByAddingComponents:toDate:options: is returning a nonsense value.
With the sample data I'm working with, I'm just creating a date
component with day value of 1 and everything else explicitly
initialized to zero.

For whatever it's worth, here's the method I'm using:

-(NSDate*) dateByAddingYears:(NSInteger) years months:(NSInteger)
months days:(NSInteger) days toDate:(NSDate*) date {
  NSDateComponents* delta = [NSDateComponents
deltaDateComponentWithYears:years months:months days:days];

  NSDate* rv = [[self gmtCalendar] dateByAddingComponents:delta
toDate:date options:0];

  if ([date compare:rv] == NSOrderedDescending && years == 0 && months
== 0 && days == 1) {
NSLog(@"TOTAL FAILURE"); //breakpoint here
  }


  return rv;
}

Sometimes (not even close to always, or even often), I bomb into the
total failure log statement and stop at the breakpoint.

At that point, inspection in the debugger yields nonsense results:
(gdb) print-object date
2013-10-23 00:00:00 +
(gdb) print-object rv
4713-02-19 00:00:00 +
(gdb) print (int) years
$4 = 0
(gdb) print (int) months
$5 = 0
(gdb) print (int) days
$6 = 1
(gdb) print (int) [delta year]
$7 = 0
(gdb) print (int) [delta month]
$8 = 0
(gdb) print (int) [delta day]
$9 = 1
(gdb) print-object [[self gmtCalendar] dateByAddingComponents:delta
toDate:date options:0]
2013-10-24 00:00:00 +

the return value ("rv") is inconsistent - in this case it happens to
show up in the year 4713. It frequently shows up at year 0, but again,
not always.

As you can see, I'm handing in 0,0,1, and my NSDateComponents object
ends up with just a change of +1 days.

Finally, note that if I try creating a new date, it succeeds. Further,
it -always- succeeds this second time in the debugger.

My gmtCalendar and deltaDateComponents:... are just wrapper methods -
I return a static NSCalendar set to GMT, and a pre-existing
NSDateComponents if I've already made one. Those are static class
variables that get looked up.

It almost seems to be related to my gmtCalendar method. If I take it
out, and instead just create a new one each time, I can't make it fail
here. When I put it back in, it will fail occasionally as before. I
don't see anything suspect with my gmt method.

Here's my gmtCalendar method:

static NSCalendar* gmtCalendar = nil;
-(NSCalendar*) gmtCalendar {
@synchronized(self) {
if (gmtCalendar == nil) {
NSLog(@"NEEDS NEW GMT!");
NSCalendar* newGMTCalendar = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
[newGMTCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
gmtCalendar = newGMTCalendar;
}
}
return gmtCalendar;
}

I'm completely stumped for ideas. Has anybody ever seen any odd
behavior like this with NSDateComponents?

-Jim
___

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

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

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

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


Re: inter-process locks

2011-02-19 Thread Alexander Cohen
Yeah, that seems like a good option but since its based off of flock, it has 
the same issues. Things like apps crashing or not unlocking by error will 
prevent other processes from obtaining the lock even though the lock is not 
'really' in use anymore.

AC

On Feb 19, 2011, at 1:58 PM, Michael Babin wrote:

> On Feb 19, 2011, at 12:29 PM, Alexander Cohen wrote:
> 
>> Is there anyway to do interprocess locks using cocoa ( like a Mutex in Win32 
>> )? The best i've found is not cocoa and uses flock but the man pages say its 
>> advisory only which is kindof scary.
> 
> NSDistributedLock:
> 
> 
> Although I've never used it in practice. The current project I'm working on 
> uses a scheme based on flock.
> 


The information contained in this e-mail and any accompanying attachments may 
contain information that is privileged, confidential or otherwise protected 
from disclosure. If you are not the intended recipient of this message, or if 
this message has been addressed to you in error, please immediately alert the 
sender by reply e-mail and then delete this message and any attachments. Any 
dissemination, distribution or other use of the contents of this message by 
anyone other than the intended recipient is strictly prohibited. The company 
accepts no liability for any damage caused by any virus transmitted by this 
email or any attachments.
___

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

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

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

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


Re: NSCalendar dateByAddingComponents: yields inconsistent results

2011-02-19 Thread Stephen J. Butler
On Sat, Feb 19, 2011 at 1:16 PM, Jim Thomason  wrote:
> static NSCalendar* gmtCalendar = nil;
> -(NSCalendar*) gmtCalendar {
>    @synchronized(self) {
>        if (gmtCalendar == nil) {
>            NSLog(@"NEEDS NEW GMT!");
>            NSCalendar* newGMTCalendar = [[NSCalendar alloc]
> initWithCalendarIdentifier:NSGregorianCalendar];
>            [newGMTCalendar setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
>            gmtCalendar = newGMTCalendar;
>        }
>    }
>        return gmtCalendar;
> }

Is this method called from different threads? NSCalendar is
thread-unsafe (not to be shared across threads):

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.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 arch...@mail-archive.com


Re: inter-process locks

2011-02-19 Thread Stephen J. Butler
On Sat, Feb 19, 2011 at 1:20 PM, Alexander Cohen  wrote:
> Yeah, that seems like a good option but since its based off of flock, it has 
> the same issues. Things like apps crashing or not unlocking by error will 
> prevent other processes from obtaining the lock even though the lock is not 
> 'really' in use anymore.

If an app crashes or exits then the OS automatically releases all its
resources, including flocks. I don't know why you would think
otherwise.

If your app has an error where some code path fails to unlock... well,
that's an issue across almost every locking primitive.

Personally, I'd use semget in this case. But nothing wrong with flock.
___

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

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

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

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


Re: NSCalendar dateByAddingComponents: yields inconsistent results

2011-02-19 Thread Jim Thomason
> Is this method called from different threads? NSCalendar is
> thread-unsafe (not to be shared across threads):

Gaaah. Yes, that's exactly it. I'm glad I tracked the issues with
gmtCalendar and posted the method.

I re-wrote it to use the threadDictionary instead of a static and all
my problems magically went away. 4 hours of my life I'd like back.

Many thanks,

-Jim
___

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

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

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

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


RE: NSComboxBox alternative

2011-02-19 Thread FirstName LastName

The idea of using a combo box is that the text field contains the currently 
selected path while the list contains a history of previously selected paths. 
The NSPathControl only supports a single path and the NSPathStylePopup does not 
allow to choose a path from the previous history but a totally different path.
 


Subject: Re: NSComboxBox alternative
From: k...@highrolls.net
Date: Thu, 17 Feb 2011 13:26:28 -0700
To: c0ldp...@hotmail.com


NSPathControl -


NSPathStylePopUp

The pop-up display style and behavior. Only the last path component is 
displayed with an icon image and component name. The full path is shown when 
the user clicks on the cell. If the cell is editable, a Choose item is included 
to enable selecting a different path.
Available in Mac OS X v10.5 and later.










On Feb 17, 2011, at 1:22 PM, FirstName LastName wrote:





I have a selectable non-editable NSComboBox for choosing paths. However some of 
these paths are larger than the NSComboBox's width causing the following 
problems:

1. The list does not show the path's file names and extensions and there's no 
way to add a horizontal scroller.
2. The textfield is scrolled programmatically to show the file name and 
extension but the scroll goes away when another view becomes first responder.

What do you suggest for being able to show file names and extensions in a list 
of paths? And keeping the currently selected one scrolled? (Unless changed by 
the user).

Any help. ___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/koko%40highrolls.net

This email sent to k...@highrolls.net


  
___

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

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

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

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


RE: NSComboxBox alternative

2011-02-19 Thread FirstName LastName

I think the NSTableView in not retractable. It wastes space to have the whole 
history always displayed when in many cases the user will just choose the most 
recently used path. Also, multiple NSPathControls in popup mode is not the 
purpose of this UI. The idea is to choose a path but to keep a history of 
previously chosen ones. An NSOpenPanel activated via a nearby button will allow 
to choose a new path.
What do you think about using an NSFormatter to right align the paths in the 
list? Is it possible?
 
> From: lruc...@vmware.com
> To: sound-fab...@gmx.de
> CC: c0ldp...@hotmail.com; cocoa-dev@lists.apple.com
> Date: Thu, 17 Feb 2011 16:25:11 -0800
> Subject: Re: NSComboxBox alternative
> 
> Or one column that contains NSPathControls in popup mode.
> 
> Full Unix-style paths generally aren't terribly user friendly.
> 
> On Feb 17, 2011, at 4:05 PM, Peter Lübke wrote:
> 
> > What about NSTableView? Just one column with a pretty large width...
> > 
> > - Peter
> > 
> > 
> > Am 17.02.2011 um 20:41 schrieb FirstName LastName:
> > 
> >> 
> >> 
> >> 
> >> 
> >> I have a selectable non-editable NSComboBox for choosing paths. 
> >> However some of these paths are larger than the NSComboBox's width 
> >> causing the following problems:
> >> 
> >> 1. The list does not show the path's file names and extensions and 
> >> there's no way to add a horizontal scroller.
> >> 2. The textfield is scrolled programmatically to show the file name 
> >> and extension but the scroll goes away when another view becomes 
> >> first responder.
> >> 
> >> What do you suggest for being able to show file names and 
> >> extensions in a list of paths? And keeping the currently selected 
> >> one scrolled? (Unless changed by the user).
> >> 
> >> Any help.
> > 
> > ___
> > 
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> > 
> > Please do not post admin requests or moderator comments to the list.
> > Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> > 
> > Help/Unsubscribe/Update your Subscription:
> > http://lists.apple.com/mailman/options/cocoa-dev/lrucker%40vmware.com
> > 
> > This email sent to lruc...@vmware.com
> 
  
___

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

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

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

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


Re: NSComboxBox alternative

2011-02-19 Thread Kyle Sluder
On Sat, Feb 19, 2011 at 12:15 PM, FirstName LastName
 wrote:
> I think the NSTableView in not retractable. It wastes space to have the whole 
> history always displayed when in many cases the user will just choose the 
> most recently used path. Also, multiple NSPathControls in popup mode is not 
> the purpose of this UI. The idea is to choose a path but to keep a history of 
> previously chosen ones. An NSOpenPanel activated via a nearby button will 
> allow to choose a new path.

So are you going to allow people to type paths into the field? If not,
then why not just go for a popup list of N recently-used paths, with
an item at the bottom to "Choose path…" that spawns the NSOpenPanel?

> What do you think about using an NSFormatter to right align the paths in the 
> list? Is it possible?

That's not what NSFormatter's good at. If you stick with the
NSComboBox approach, you'd probably want to subclass NSComboBoxCell
instead.

--Kyle Sluder
___

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

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

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

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


Re: NSTextAttachment, MouseOver, GlyphPosition

2011-02-19 Thread Peter Krajčík
Hi,

one of the ways could be to use own NSLayoutManager and use it to draw 
NSAttributed string
in my subclass of NSTextAttachmentCell and its draw method.
NSLayoutManager has boundingRectForGlyphRange:inTextContainer: method from 
which I could obtain bounds of glyph representing 
NSTextAttachment at position I am interested in.
I can use this method to get rectangles of all attachments in my 
updateTrackingAreas method.

Does anybody see this as the right way ?

Peter

___

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

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

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

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


-[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Michael Crawford
I'm trying to compare instances of NSNumber using NSSet.  I have a set of 
numbers, which represent 64-bit persistent IDs for iTunes media-items.  I 
access these values using the -[NSNumber longLongValue] method.  I'm adding 
them to an instance of NSSet and then use that instance to determine whether or 
not I've seen the given item before.

The application is a black-list of songs and albums that want to avoid 
processing when scanning the iTunes library.  I find that the comparison does 
not always work when it should and I am at a loss to explain why.

I assumed that the -[NSObject hash] method is used to determining equality and 
that to different NSNumber instances will hash out to the same value if they 
have the same 64-bit value stored inside.

I also assumed that whether or not the value is signed or unsigned; negative or 
positive makes no difference as long as calling the same accessor method on 
both NSNumber instances returns the same result.

It looks like at least one, maybe both of these assumptions are wrong.  Since 
I'm working with both Core Data and the MediaLibrary APIs on iOS, I'm a little 
wary of subclassing NSNumber in an attempt to fix the hash method.

The following gdb console output demonstrates an instance of a media-item 
persistent-ID property that, when queried gives a large unsigned number.  When 
I ask again using the -longLongValue method, I get the answer I was expecting.  
When I look inside the set, you will see that the value -1748299021286640132 is 
in the set.  However, when -containsObject is called, it returns NO.

(gdb) po mediaItem
 16698445052422911484
(gdb) po [mediaItem persistentID]
0x930bf5fc does not appear to point to a valid object.
(gdb) po [mediaItem persistentIDProperty]
16698445052422911484
(gdb) p (NSNumber*) [mediaItem persistentIDProperty]
$1 = (NSNumber *) 0x79681b0
(gdb) p (long long)[$1 longLongValue]
$2 = -1748299021286640132
(gdb) po noPlaySongs
{(
-1748299021286641066,
-1748299021286641065,
-1748299021286640132
)}
(gdb) continue

Anyone have previous experience with this problem?  Can you shed some light on 
where my thinking and assumptions are wrong.  I could write a sweet of tests to 
try and prove/disprove what I think is happening but I'm hoping to benefit from 
someone else's pre-existing research, experiments, or internal knowledge.

My Google incantation did not yield any results, either.

Thanks.

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Scott Ribe
On Feb 19, 2011, at 3:17 PM, Michael Crawford wrote:

> I assumed that the -[NSObject hash] method is used to determining equality 
> and that to different NSNumber instances will hash out to the same value if 
> they have the same 64-bit value stored inside.

I'm pretty sure that, for instance, two calls to [NSNumber numberWithLongLong: 
1] will produce two different objects, and though they may fall into the same 
hash bucket if the hash method uses the numeric value, they will still not be 
treated as the same object by -containsObject.

If you look at the -member method instead, you'll see that it uses isEqual, so 
maybe that would do what you want, or maybe not, depending on how isEqual is 
implemented by NSNumber. -filteredSetUsingPredicate would seem to do it, but 
would be slower since it will iterate the whole set.

Personally, though my approach may not be terribly popular with the Cocoa 
crowd, I'd use std::set ;-)

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




___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Jim Correia
On Feb 19, 2011, at 2:17 PM, Michael Crawford wrote:

> I'm trying to compare instances of NSNumber using NSSet.  I have a set of 
> numbers, which represent 64-bit persistent IDs for iTunes media-items.  I 
> access these values using the -[NSNumber longLongValue] method.  I'm adding 
> them to an instance of NSSet and then use that instance to determine whether 
> or not I've seen the given item before.


> Anyone have previous experience with this problem?  Can you shed some light 
> on where my thinking and assumptions are wrong.

The documentation for -[NSSet containsObject:] says:

Return Value — YES if anObject is present in the set, otherwise NO.

The documentation for -[NSSet member:] says:

Return Value — If the set contains an object equal to object (as determined by 
isEqual:) then that object (typically this will be object), otherwise nil.

Jim


___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Andy Lee
On Feb 19, 2011, at 5:17 PM, Michael Crawford wrote:
> When I look inside the set, you will see that the value -1748299021286640132 
> is in the set.  However, when -containsObject is called, it returns NO.

Are you sure the objects you are dealing with are always NSNumbers? If one of 
them is an NSString, containsObject: will fail.

On Feb 19, 2011, at 5:28 PM, Scott Ribe wrote:
> I'm pretty sure that, for instance, two calls to [NSNumber 
> numberWithLongLong: 1] will produce two different objects, and though they 
> may fall into the same hash bucket if the hash method uses the numeric value, 
> they will still not be treated as the same object by -containsObject.

That would strike me as very odd, since it would imply that the two instances 
aren't isEqual: to each other. (The containsObject: doc isn't explicit about 
whether it uses isEqual: to test for membership, but I assume so since member: 
does.)

I just did a quick test and confirmed that you do get two different instances 
with the same hash, but they are in face isEqual: to each other and hence their 
presence in a set is detected, as I would expect.

NSNumber *one = [NSNumber numberWithLongLong:1];
NSNumber *another = [NSNumber numberWithLongLong:1];
NSSet *set = [NSSet setWithObject:another];

NSLog(@"+++ one %p, hash = %ld -- another %p, hash = %ld -- is eq = %d, 
contains one = %d, contains another = %d",
  one, [one hash], another, [another hash], [one isEqual:another], [set 
containsObject:one], [set containsObject:another]);

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


Re: Getting NSScrollView to ignore scrolling

2011-02-19 Thread Peter Lübke

HI All,

I have a NSTableView/NSScrollView setup that I've configured  
automatically to resize to contain the content of the table.  This  
may sound silly, but I don't want scrolling behavior, but  
NSTableView seems to be designed to be inside a NSScrollView.


My question is this: how do I get the scroll view to ignore  
scrolling messages?  The tables/scrollviews are sitting on views  
that are part of a homebrew collection view, and the scrolling  
"catches" on them, even though there's no scrolling to be done.   
The scroll view is taking the events, but there is nothing for them  
to do.  I want to be able to scroll past the table using a  
scrollwheel or the trackpad without the scrolling action "catching."




What do you mean with "scroll past the table"?

Did you try to call setHasHorizontalScroller:NO,  
setHasVerticalScroller: NO, setHasHorizontalRuler:NO,  
setHasVerticalRuler:NO and setLineScroll:0.0 on the enclosing scroll  
view?


You can create your own table view without an enclosing scroll view;  
there's some more work to do than simply dragging an NSTableView into  
a window in IB. Create an NSTableView subclass, add your table  
columns, override -calcSize and -sizeToFit to fit your resizing  
behaviour, and add it wherever it is supposed to be in your view  
hierarchy. Start creating instances with [[myTableView alloc] - 
initWithFrame:...].


Cheers,
Peter
___

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

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

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

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


Re: Getting NSScrollView to ignore scrolling

2011-02-19 Thread Quincey Morris
On Feb 19, 2011, at 16:25, Peter Lübke wrote:

>> My question is this: how do I get the scroll view to ignore scrolling 
>> messages?  The tables/scrollviews are sitting on views that are part of a 
>> homebrew collection view, and the scrolling "catches" on them, even though 
>> there's no scrolling to be done.  The scroll view is taking the events, but 
>> there is nothing for them to do. I want to be able to scroll past the table 
>> using a scrollwheel or the trackpad without the scrolling action "catching."
>> 
> 
> What do you mean with "scroll past the table"?

I'm pretty sure the OP is talking specifically about scrolling with the scroll 
wheel. (It sounds like the individual table views in his view collection don't 
have scroll bars, and are sized to show all their content anyway.) In that 
case, the table views or scroll views are still responding the scroll wheel, 
which prevents the collection view itself from scrolling.

I think the only way to fix this is to override the appropriate 'scrollWheel:' 
event method, and to pass the event on up the responder chain. NSScrollView's 
documentation lists that method, so presumably that's the appropriate method, 
and so it would be necessary to subclass NSScrollView, override 'scrollWheel:' 
and figure out a way of bypassing the NSScrollView implementation (since the 
usual '[super scrollWheel:]' technique won't achieve that here). I guess you'd 
have to walk the responder chain manually (not normally recommended), or find 
the NSScrollView's superclass's implementation via the 'objc_...' runtime 
routines (not normally recommended), although maybe there's a simpler way 
that's just not occurring to me right now.


___

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

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

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

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


[Solved]: Trouble with design pattern

2011-02-19 Thread Carlos Eduardo Mello

Thanks Andy, Jon, Kirk, Murat and everyone who responded.

All your advices were very usefull.

I decided to use the delegate pattern and everything is working  
perfectly now. In fact I am starting to be able to implement sevall of  
my planed funcionalities just by adding messages to my working  
delegate protocol, and  my views know nothing about my document. I am  
tryng to make them more generic as well, so i can reuse them in other  
projects with similar requirements.
I am also learning how to use Notifications, and will be using them  
soon.


Thanks again.


On Feb 18, 2011, at 9:17 PM, aglee wrote:

I would use the delegate pattern. Look at some Cocoa classes that  
have delegates to get the idea of the general pattern. Examples:  
NSTableView, NSControl, NSURLConnection. My app, AppKiDo, provides  
an easy way to list classes that have delegates, and to skim the  
delegate methods. You could also search the Xcode doc window for  
"delegate methods". I believe there is also documentation that  
specifically discusses the pattern. And Erik Buck's book "Cocoa  
Design Patterns" also discusses it in detail.


Here are the general steps to follow this pattern:

In MyView.h, declare a protocol something like this (typed in Mail,  
untested):


@protocol MyViewDelegate

- (void)myView:(MyView *)view didMouseDown:(NSEvent *)mouseDownEvent;

@end

Have MyDocument conform to the MyViewDelegate protocol:

@protocol MyViewDelegate;  // Forward declaration of the protocol.

@interface MyDocument : NSDocument 

Add a delegate outlet to your custom view:

@interface MyView : NSView
{
//...
id  myViewDelegate;
//...
}

// IMPORTANT:
// Declare the delegate property as assign, NOT retain, as delegates  
are not retained in order to avoid retain loops.

@property (readwrite, assign) id myViewDelegate;

//...
@end

In IB, make the document the delegate of your custom view.

In MyView.m, send a myView:didMouseDown: message to the delegate at  
whatever the appropriate time is. If you're overriding mouseDown:,  
that's probably the right time, something like this:


- (void)mouseDown:(NSEvent *)event
{
[myViewDelegate myView:self didMouseDown:theEvent];
}

In MyDocument.m, implement the delegate method myView:didMouseDown:.

Note that MyView doesn't have to know that its delegate is a  
MyDocument. It doesn't care. It just knows that the delegate is some  
object that wants to be notified of mouse-down events.


Also note that delegate methods should take the object doing the  
delegating as their first argument, and should use the name of the  
delegating class (in this case "MyView", hence the "myView:" at the  
beginning of the delegate method). You see this in all Cocoa  
delegate protocols. This is in case you have two MyView instances  
with the same delegate. The delegate can use the first argument to  
tell which instance it is dealing with. Passing the delegating  
object also allows the delegate method to get further information  
about it if necessary.


An advantage of the delegate pattern over notifications is that  
delegate methods can have return values. For example, you could have  
myView:didMouseDown: return a BOOL indicating whether it did  
anything with the event. If the superclass of MyView has a non- 
trivial implementation of mouseDown:, you might want to fall back on  
that behavior by changing the above method like this:


- (void)mouseDown:(NSEvent *)event
{
if (![myViewDelegate myView:self didMouseDown:theEvent])
{
[super mouseDown:event];
}
}

One last variation this pattern: you might want to make some  
delegate methods @optional.


// In MyView.h:
@protocol MyViewDelegate

@optional

- (void)myView:(MyView *)view didMouseDown:(NSEvent *)mouseDownEvent;

@end

// In MyView.m:
- (void)mouseDown:(NSEvent *)event
{
if ([myViewDelegate  
respondsToSelector:@selector(myView:didMouseDown:)

&& ![myViewDelegate myView:self didMouseDown:theEvent])
{
[super mouseDown:event];
}
}

I hope this is not too confusing.

--Andy

On Feb 18, 2011, at 02:20 PM, Carlos Eduardo Mello > wrote:



Hi Everyone,

I am comming back to cocoa programming and to this list after a few
years without programming anything, so please forgive me in advance
for any stupid questions. I've read the docs, studied Hillegass's  
book

again and searched the archives, but still couldn't find a definitive
answer to my questions.

My app is document-based, started from the XCode template. I have two
custom views which are outlets of MyDocument and some extra buttons
and text fields on the document's NIB file. Drawing, actions and
events work fine for the most part. but in order to do the fun stuff
with the app, I need to acess methods in the document as a result of
mouse events in the custom views, like updating the values in the  
text

fields and making modifications to my data model classes (the data
engine is a collection of crossplatform C++ classes). I came across a

Re: inter-process locks

2011-02-19 Thread Ken Thomases
On Feb 19, 2011, at 12:29 PM, Alexander Cohen wrote:

> Is there anyway to do interprocess locks using cocoa ( like a Mutex in Win32 
> )? The best i've found is not cocoa and uses flock but the man pages say its 
> advisory only which is kindof scary.

"Advisory" only means that programs need to explicitly cooperate with the 
locking scheme -- opt-in, as it were -- in order to be affected by it.  But 
that's going to be true of most locking primitives such as semaphores or 
mutexes, too.

Regards,
Ken

___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Ken Thomases
On Feb 19, 2011, at 4:17 PM, Michael Crawford wrote:

> I also assumed that whether or not the value is signed or unsigned; negative 
> or positive makes no difference as long as calling the same accessor method 
> on both NSNumber instances returns the same result.

I think this is wrong.  I can't imagine why you assumed that some future method 
call would affect whether two NSNumbers are equal.  They are equal if they 
contain the same value.  You must realize that, for example, -boolValue would 
map a great many different NSNumbers to the same return value, but that doesn't 
imply that the NSNumbers are equal.

Regards,
Ken

___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Michael Crawford

On Feb 19, 2011, at 9:31 PM, Ken Thomases wrote:

> On Feb 19, 2011, at 4:17 PM, Michael Crawford wrote:
> 
>> I also assumed that whether or not the value is signed or unsigned; negative 
>> or positive makes no difference as long as calling the same accessor method 
>> on both NSNumber instances returns the same result.
> 
> I think this is wrong.  I can't imagine why you assumed that some future 
> method call would affect whether two NSNumbers are equal.  They are equal if 
> they contain the same value.  You must realize that, for example, -boolValue 
> would map a great many different NSNumbers to the same return value, but that 
> doesn't imply that the NSNumbers are equal.
> 
> Regards,
> Ken
> 

I assumed this is the case because regardless of whether or not you call 
-boolValue or -longLongValue, -hash returns the same result.  I've already 
shown that they do indeed contain the same value, when -longLongValue is called 
on both items.  See the dbg output.

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Kyle Sluder
On Feb 19, 2011, at 7:01 PM, Michael Crawford  wrote:

> 
> I assumed this is the case because regardless of whether or not you call 
> -boolValue or -longLongValue, -hash returns the same result.  I've already 
> shown that they do indeed contain the same value, when -longLongValue is 
> called on both items.  See the dbg output.

Why do you keep fixating on -hash? There are two common definitions of 
equality: -isEqual: and pointer identity. Neither of these relies on -hash.

Your experience indicates that -containsObject: uses pointer identity, whereas 
-member: uses -isEqual:.

--Kyle Sluder
> 
___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Andy Lee
On Feb 19, 2011, at 6:08 PM, Andy Lee wrote:
> I just did a quick test and confirmed that you do get two different instances 
> with the same hash, but they are in face isEqual: to each other and hence 
> their presence in a set is detected, as I would expect.
> 
>   NSNumber *one = [NSNumber numberWithLongLong:1];
>   NSNumber *another = [NSNumber numberWithLongLong:1];
>   NSSet *set = [NSSet setWithObject:another];
> 
>   NSLog(@"+++ one %p, hash = %ld -- another %p, hash = %ld -- is eq = %d, 
> contains one = %d, contains another = %d",
> one, [one hash], another, [another hash], [one isEqual:another], [set 
> containsObject:one], [set containsObject:another]);

Whoops, actually I got the same instance using 1, presumably because NSNumber 
keeps a few low number instances cached. What I said above is true if I retry 
with 123456789.

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Ken Thomases
On Feb 19, 2011, at 9:01 PM, Michael Crawford wrote:

> On Feb 19, 2011, at 9:31 PM, Ken Thomases wrote:
> 
>> On Feb 19, 2011, at 4:17 PM, Michael Crawford wrote:
>> 
>>> I also assumed that whether or not the value is signed or unsigned; 
>>> negative or positive makes no difference as long as calling the same 
>>> accessor method on both NSNumber instances returns the same result.
>> 
>> I think this is wrong.  I can't imagine why you assumed that some future 
>> method call would affect whether two NSNumbers are equal.  They are equal if 
>> they contain the same value.  You must realize that, for example, -boolValue 
>> would map a great many different NSNumbers to the same return value, but 
>> that doesn't imply that the NSNumbers are equal.
> 
> I assumed this is the case because regardless of whether or not you call 
> -boolValue or -longLongValue, -hash returns the same result.

So?  -hash being the same does not imply equality.  Equality implies that the 
hash must be the same, which is not the same thing.

> I've already shown that they do indeed contain the same value, when 
> -longLongValue is called on both items.  See the dbg output.

And my point is exactly that this doesn't imply equality of the NSNumber 
objects.  Why would you think it does?  That's exactly like saying that calling 
-boolValue on both items gave the same result so therefore they must be equal.

Notice that when the description is printed, you got 16698445052422911484 from 
[mediaItem persistentIDProperty] while the elements of the set show 
-1748299021286641066, -1748299021286641065, and -1748299021286640132.  That's 
an indication that the numbers are not the same "under the hood".  At the very 
least, one is positive while the others are negative.

You are essentially asking NSNumber whether the numbers 16698445052422911484 
and -1748299021286640132 are equal, and it's giving you the fairly obvious 
answer that, no, they are different numbers.  Yes, when cast to long long, they 
both end up as the same long long value, but that's a transformation that 
throws away information about the original numbers.  It doesn't mean the 
original numbers are equal.

Regards,
Ken

___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Quincey Morris
On Feb 19, 2011, at 19:06, Kyle Sluder wrote:

> On Feb 19, 2011, at 7:01 PM, Michael Crawford  wrote:
> 
>> 
>> I assumed this is the case because regardless of whether or not you call 
>> -boolValue or -longLongValue, -hash returns the same result.  I've already 
>> shown that they do indeed contain the same value, when -longLongValue is 
>> called on both items.  See the dbg output.
> 
> Why do you keep fixating on -hash? There are two common definitions of 
> equality: -isEqual: and pointer identity. Neither of these relies on -hash.

Putting it another way: -hash is of interest only to *implementers* of certain 
classes. To users of classes, it's an implementation detail.

> Your experience indicates that -containsObject: uses pointer identity, 
> whereas -member: uses -isEqual:.

What's especially confusing is that -[NSArray containsObject:] is documented to 
use -isEqual. It seems like the NSSet method ought to be called 
-containsObjectIdenticalTo: for consistency (and now clarity) reasons.


___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Ken Thomases
On Feb 19, 2011, at 9:26 PM, Quincey Morris wrote:

> On Feb 19, 2011, at 19:06, Kyle Sluder wrote:
> 
>> Your experience indicates that -containsObject: uses pointer identity, 
>> whereas -member: uses -isEqual:.
> 
> What's especially confusing is that -[NSArray containsObject:] is documented 
> to use -isEqual. It seems like the NSSet method ought to be called 
> -containsObjectIdenticalTo: for consistency (and now clarity) reasons.

I think Kyle was just mistaken about this, lead astray by Michael's claims.  
Andy's experiment shows that -[NSSet containsObject:] relies on equality, not 
identity, just as one expects.  It's just that Michael has two truly non-equal 
NSNumber objects, as his gdb output showed.

Regards,
Ken

___

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

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

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

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


Re: Multithread, Window, Event, Runloop, ... => Headache

2011-02-19 Thread Marco Antognini

On Feb 19, 2011, at 3:10, Ken Thomases wrote:

> On Feb 17, 2011, at 8:48 AM, Marco Antognini wrote:
> 
>> But now I'm stuck with a problem : is there any way to create/destroy 
>> window/view, make them live (e.g. rendering process) and get event 
>> notification; all that only in a worker thread (like we can do on Linux or 
>> Windows) ?
> 
> Short answer: no.
> 
> To the Mac frameworks, the main thread is special.  The main thread is always 
> the original thread of the process.  You can't designate which thread is the 
> main thread.
> 
> One can poke around in the Darwin sources to see that the non-portable 
> pthread_main_np() function is determined as the C library initializes itself, 
> and further that CFRunLoopGetMain() and similar functions rely on it.
> 
> Also, some of the frameworks install run loop sources on the current thread's 
> run loop when they are loaded.  For a typical program, they are loaded when 
> the executable is loaded when there is only the main thread. So, their run 
> loop sources are only processed on the main thread.
> 
> I think your best bet is to reserve the main thread for running the standard 
> main application event loop and spawn a secondary thread to run the work of 
> the client of your library.  I realize this is a cumbersome requirement on 
> both you and the clients of the library.  Sorry I don't have better news.
> 
> Regards,
> Ken
> 

That's what I was afraid of...

Anyway, thank you for your answer even if it's bad news for me.

Best,
Marco___

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

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

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

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


mount .dmg and run file from there

2011-02-19 Thread Crni Gorac
Am working on a small application that would download given larger
.dmg installer, showing download progress along the way, and then
mount .dmg image and run .pkg file from this image.  I have everything
working properly, except for that last step.  I'm using NSWorkspace
openFile to mount the .dmg image after downloading it, but I don't
know how to run the .pkg file from the mounted image (note that .dmg
file name is varying, basically it's like ExampleApp-x.y.z.dmg, where
"x", "y" and "z" are numbers).  Any suggestions?

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/archive%40mail-archive.com

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


How to use Photo Albums of the landscape mode iphone app

2011-02-19 Thread 吴明
HI Guys:


My iphone app Interface Orientation is landscape.
I need load  a picture to my app. so. I use 


if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary]) {
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}


[self presentModalViewController:picker animated:YES];


- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image
 editingInfo:(NSDictionary *)editingInfo {
UIImage *pickedImage =[[UIImage alloc] initWithCGImage:image.CGImage];
UIImage *newImage = [self newAdjustSize:pickedImage];
[pickedImage release];
}


- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissModalViewControllerAnimated:YES];
}


but. The UIImagePickerController Interface Orientation is Portrait.
I hope the UIImagePickercontrooler Interface Orientation is Landscape.
How do it.


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/archive%40mail-archive.com

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


NSDateFormatter initialization+formatting not working

2011-02-19 Thread Markus Spoettl
Hello,

  I'm not getting why this is not working:

 NSDate *date = [NSDate date];

 NSDateFormatter *df1 = [[NSDateFormatter alloc] initWithDateFormat:@"EEE d" 
allowNaturalLanguage:NO]; 
 NSString *s1 = [df1 stringFromDate:date];

s1 ---> @"EEE d";

 NSDateFormatter *df2 = [[NSDateFormatter alloc] init];
 [df2 setDateFormat:@"EEE d"]; 
 NSString *s2 = [df2 stringFromDate:date];

s2 ---> @"Sat 19"  (on a Saturday the 19th)

I could live with that but the documentation tells me that -init is deprecated 
in 10.6? Is that really true? When I look at the NSDateFormatter header things 
look quite differently:

#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
@interface NSDateFormatter (NSDateFormatterCompatibility)

- (id)initWithDateFormat:(NSString *)format allowNaturalLanguage:(BOOL)flag;
- (BOOL)allowsNaturalLanguage;

@end
#endif

Which to me tries to convey that -initWithDateFormat: is deprecated -- not by 
saying so directly of course.

So who is wrong, docs or header? And why doesn't the -initWithDateFormat: 
initializer work?

Puzzled
Markus
--
__
Markus Spoettl

___

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

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

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

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


Keeping Multiple Identical Tables in Synch - Weird SortDescriptor Binding Problem

2011-02-19 Thread Peter Zegelin

I  have several tables showing the same data that need to stay in synch. The 
tables are instantiated via the same nib so they are identical. The tables get 
their data through an array controller bound to an array in a shared object and 
their selection stay in synch by the array controller being bound to an 
NSMutableIndexSet in the same shared object. After a bit of fooling around I 
also managed to get the table sorting also in synch but how it works seems a 
bit strange.

I eventually created an array of sort descriptors in the shared object and 
bound the Array Controller to that. There is only one descriptor in the array. 
The table in turn is bound to the sortDescriptors Controller Key of the Array 
Controller. This all works except for the fact that there is only one sort 
descriptor but several table columns and they all sort as well. Indeed I 
commented out the actual creation of the sort descriptor in the shared object 
and it still sorts on all columns.

Does anyone know what may be going on and what is the correct way to do 
synchronised sorting via bindings?

thanks!

Peter Zegelin
http://www.fracturedsoftware.com
Rondo - MIDI for your mac
MacSimAVR - AVR microcontroller simulator for OS X

___

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

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

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

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


Re: NSDateFormatter initialization+formatting not working

2011-02-19 Thread Ken Thomases
On Feb 19, 2011, at 9:53 PM, Markus Spoettl wrote:

> NSDateFormatter *df1 = [[NSDateFormatter alloc] initWithDateFormat:@"EEE d" 
> allowNaturalLanguage:NO]; 
> NSString *s1 = [df1 stringFromDate:date];
> 
> s1 ---> @"EEE d";
> 
> NSDateFormatter *df2 = [[NSDateFormatter alloc] init];
> [df2 setDateFormat:@"EEE d"]; 
> NSString *s2 = [df2 stringFromDate:date];
> 
> s2 ---> @"Sat 19"  (on a Saturday the 19th)

> And why doesn't the -initWithDateFormat: initializer work?

I think it does work, but produces a formatter using the old-style behavior.  
From 
:

> If you initialize a formatter using initWithDateFormat:allowNaturalLanguage:, 
> you are (for backwards compatibility reasons) creating an “old-style” date 
> formatter. To use the new behavior, you initialize the formatter with init. 
> If necessary, you can set the default class behavior using 
> setDefaultFormatterBehavior:), you can set the behavior for an instance using 
> setFormatterBehavior: message with the argument NSDateFormatterBehavior10_4.


My best guess about -init is not so much that it is deprecated to invoke that 
method, but that there used to be an override with its own documentation, but 
now it's just implicit that -init is inherited from NSObject.  So, the old 
method documentation was removed from the class reference and put in a 
"deprecated" page.  If you look at the header, there is a commented-out 
declaration of -init with a comment saying it is the designated initializer.  
In previous versions of that header, the -init method declaration was not 
commented out.

Regards,
Ken

___

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

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

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

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


Re: Keeping Multiple Identical Tables in Synch - Weird SortDescriptor Binding Problem

2011-02-19 Thread Quincey Morris
On Feb 19, 2011, at 20:00, Peter Zegelin wrote:

> I  have several tables showing the same data that need to stay in synch. The 
> tables are instantiated via the same nib so they are identical. The tables 
> get their data through an array controller bound to an array in a shared 
> object and their selection stay in synch by the array controller being bound 
> to an NSMutableIndexSet in the same shared object. After a bit of fooling 
> around I also managed to get the table sorting also in synch but how it works 
> seems a bit strange.
> 
> I eventually created an array of sort descriptors in the shared object and 
> bound the Array Controller to that. There is only one descriptor in the 
> array. The table in turn is bound to the sortDescriptors Controller Key of 
> the Array Controller. This all works except for the fact that there is only 
> one sort descriptor but several table columns and they all sort as well. 
> Indeed I commented out the actual creation of the sort descriptor in the 
> shared object and it still sorts on all columns.
> 
> Does anyone know what may be going on and what is the correct way to do 
> synchronised sorting via bindings?

If you sort on a column in the table view itself (by clicking the column header 
-- which is what I assume you mean by "several table columns ... they all sort 
as well"), then that changes the sort descriptor array, a change which the 
bindings you've described will push back to your model.

Chances are you've accidentally allowed your data model sort descriptors 
property be settable. (What happens when it's not, and the table view tries to 
change the sort descriptors, I don't know -- maybe an exception, maybe a 
harmless error in the log, maybe it's silently ignored.) You should probably 
make sure the property isn't settable (pay attention to 
+accessInstanceVariablesDirectly).

If you don't want the bindings to attempt to change your sort descriptors, you 
should turn off the "sortable" property in each table column.


___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Andy Lee
On Feb 19, 2011, at 10:31 PM, Ken Thomases wrote:

> On Feb 19, 2011, at 9:26 PM, Quincey Morris wrote:
> 
>> On Feb 19, 2011, at 19:06, Kyle Sluder wrote:
>> 
>>> Your experience indicates that -containsObject: uses pointer identity, 
>>> whereas -member: uses -isEqual:.
>> 
>> What's especially confusing is that -[NSArray containsObject:] is documented 
>> to use -isEqual. It seems like the NSSet method ought to be called 
>> -containsObjectIdenticalTo: for consistency (and now clarity) reasons.
> 
> I think Kyle was just mistaken about this, lead astray by Michael's claims.  
> Andy's experiment shows that -[NSSet containsObject:] relies on equality, not 
> identity, just as one expects.  It's just that Michael has two truly 
> non-equal NSNumber objects, as his gdb output showed.

BTW I was technically mistaken about my code's output. You get the *same* 
instance when you do [NSNumber numberWithLongLong:1] twice, because NSNumber 
happens to cache instances for low integer values. But I was correct in 
principle: substitute 123456789 for 1 and everything I said becomes true.

One thing I'm puzzled about is that NSSet does not copy its entries the way 
NSDictionary copies its keys. This is implied by the member: documentation 
quoted earlier:

"If the set contains an object equal to object (as determined by isEqual:) then 
that object (***typically this will be object***), otherwise nil."

A quick experiment confirms that elements are not copied, which leads to the 
risk that NSDictionary avoids. If elements of the set happen to be mutable, one 
element could mutate in such a way as to be isEqual: to another. This can be 
demonstrated actually happening:

NSMutableString *s1 = [NSMutableString stringWithString:@"abc"];
NSMutableString *s2 = [NSMutableString stringWithString:@"abc"];
NSMutableString *s3 = [NSMutableString stringWithString:@"def"];
NSSet *stringSet = [NSSet setWithObjects:s1, s2, s3, nil];

NSLog(@"+++ s1 [%@] %p, hash = %ld, set contains s1? %d", s1, s1, [s1 
hash], [stringSet containsObject:s1]);
NSLog(@"+++ s2 [%@] %p, hash = %ld, set contains s2? %d", s2, s2, [s2 
hash], [stringSet containsObject:s2]);
NSLog(@"+++ s3 [%@] %p, hash = %ld, set contains s3? %d", s3, s3, [s3 
hash], [stringSet containsObject:s3]);

NSLog(@"+++ elements BEFORE mutate:");
for (id obj in stringSet)
{
NSLog(@"+++ %p is [%@]", obj, obj);
}

[s3 setString:@"abc"];  // Mutate one set element to be equal to 
another.

NSLog(@"+++ count after mutate = %d", [stringSet count]);
NSLog(@"+++ elements AFTER mutate:");
for (id obj in stringSet)
{
NSLog(@"+++ %p is [%@] -- is eq to @\"abc\"? %d", obj, obj, 
[obj isEqual:@"abc"]);
}

Output:

2011-02-20 00:47:19.305 Scratcho[20333:a0f] +++ s1 [abc] 0x12b170, hash = 
516202353, set contains s1? 1
2011-02-20 00:47:19.309 Scratcho[20333:a0f] +++ s2 [abc] 0x12b1b0, hash = 
516202353, set contains s2? 1
2011-02-20 00:47:19.310 Scratcho[20333:a0f] +++ s3 [def] 0x12b1f0, hash = 
517992642, set contains s3? 1
2011-02-20 00:47:19.310 Scratcho[20333:a0f] +++ elements BEFORE mutate:
2011-02-20 00:47:19.311 Scratcho[20333:a0f] +++ 0x12b170 is [abc]
2011-02-20 00:47:19.313 Scratcho[20333:a0f] +++ 0x12b1f0 is [def]
2011-02-20 00:47:19.313 Scratcho[20333:a0f] +++ count after mutate = 2
2011-02-20 00:47:19.314 Scratcho[20333:a0f] +++ elements AFTER mutate:
2011-02-20 00:47:19.315 Scratcho[20333:a0f] +++ 0x12b170 is [abc] -- is eq 
to @"abc"? 1
2011-02-20 00:47:19.315 Scratcho[20333:a0f] +++ 0x12b1f0 is [abc] -- is eq 
to @"abc"? 1

Am I missing something? Is this a known loophole in the semantics of NSSet? Is 
it a deliberate compromise, which trades the performance gained by not copying 
elements for a risk that almost never matters in practice?

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Roland King

On 20-Feb-2011, at 1:54 PM, Andy Lee wrote:

> 
> One thing I'm puzzled about is that NSSet does not copy its entries the way 
> NSDictionary copies its keys. This is implied by the member: documentation 
> quoted earlier:
> 
> "If the set contains an object equal to object (as determined by isEqual:) 
> then that object (***typically this will be object***), otherwise nil."
> 
> A quick experiment confirms that elements are not copied, which leads to the 
> risk that NSDictionary avoids. If elements of the set happen to be mutable, 
> one element could mutate in such a way as to be isEqual: to another. This can 
> be demonstrated actually happening:
> 

No experiment needed - it's in the documentation .. quoting .. 

"The objects in a set must respond to the NSObject protocol methods hash and 
isEqual: (see NSObject for more information). If mutable objects are stored in 
a set, either the hash method of the objects shouldn’t depend on the internal 
state of the mutable objects or the mutable objects shouldn’t be modified while 
they’re in the set. For example, a mutable dictionary can be put in a set, but 
you must not change it while it is in there. (Note that it can be difficult to 
know whether or not a given object is in a collection)."
"NSSet provides a number of initializer methods, such as setWithObjects: and 
initWithArray:, that return an NSSet object containing the elements (if any) 
you pass in as arguments. Objects added to a set are not copied (unless you 
pass YES as the argument to initWithSet:copyItems:). Rather, an object is added 
directly to a set. In a managed memory environment, an object receives a retain 
message when it’s added; in a garbage collected environment, it is strongly 
referenced. For more information on copying and memory management, see “Copying 
Collections.”"

___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Andy Lee
Ah, thanks. That's here:



I was only looking at the NSSet docs.

--Andy


On Feb 20, 2011, at 1:03 AM, Roland King wrote:

> 
> On 20-Feb-2011, at 1:54 PM, Andy Lee wrote:
> 
>> 
>> One thing I'm puzzled about is that NSSet does not copy its entries the way 
>> NSDictionary copies its keys. This is implied by the member: documentation 
>> quoted earlier:
>> 
>> "If the set contains an object equal to object (as determined by isEqual:) 
>> then that object (***typically this will be object***), otherwise nil."
>> 
>> A quick experiment confirms that elements are not copied, which leads to the 
>> risk that NSDictionary avoids. If elements of the set happen to be mutable, 
>> one element could mutate in such a way as to be isEqual: to another. This 
>> can be demonstrated actually happening:
>> 
> 
> No experiment needed - it's in the documentation .. quoting .. 
> 
> "The objects in a set must respond to the NSObject protocol methods hash and 
> isEqual: (see NSObject for more information). If mutable objects are stored 
> in a set, either the hash method of the objects shouldn’t depend on the 
> internal state of the mutable objects or the mutable objects shouldn’t be 
> modified while they’re in the set. For example, a mutable dictionary can be 
> put in a set, but you must not change it while it is in there. (Note that it 
> can be difficult to know whether or not a given object is in a collection)."
> "NSSet provides a number of initializer methods, such as setWithObjects: and 
> initWithArray:, that return an NSSet object containing the elements (if any) 
> you pass in as arguments. Objects added to a set are not copied (unless you 
> pass YES as the argument to initWithSet:copyItems:). Rather, an object is 
> added directly to a set. In a managed memory environment, an object receives 
> a retain message when it’s added; in a garbage collected environment, it is 
> strongly referenced. For more information on copying and memory management, 
> see “Copying Collections.”"
> 

___

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

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

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

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


Re: mount .dmg and run file from there

2011-02-19 Thread Uli Kusterer
On 19.02.2011, at 13:12, Crni Gorac wrote:
> Am working on a small application that would download given larger
> .dmg installer, showing download progress along the way, and then
> mount .dmg image and run .pkg file from this image.  I have everything
> working properly, except for that last step.  I'm using NSWorkspace
> openFile to mount the .dmg image after downloading it, but I don't
> know how to run the .pkg file from the mounted image (note that .dmg
> file name is varying, basically it's like ExampleApp-x.y.z.dmg, where
> "x", "y" and "z" are numbers).  Any suggestions?

 Sparkle does that. It calls the hdiutil command line tool using NSTask, which 
lets you not only mount the DMG, but also query/specify where it will be 
mounted. Then you just have to list the contents at that location to find the 
PKG to run.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.masters-of-the-void.com



___

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

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

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

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


Re: -[NSSet containsObject:] returns NO when it should return YES

2011-02-19 Thread Greg Guerin

Michael Crawford wrote:

The following gdb console output demonstrates an instance of a  
media-item persistent-ID property that, when queried gives a large  
unsigned number.  When I ask again using the -longLongValue method,  
I get the answer I was expecting.  When I look inside the set, you  
will see that the value -1748299021286640132 is in the set.   
However, when -containsObject is called, it returns NO.



If the persistent-ID is unsigned, then longLongValue seems like the  
wrong type to use.  There are NSNumber methods for working with  
unsigned long long types.  Try using those exclusively and see if it  
changes anything.


NSNumber has a method that returns the type encoding as a C string (- 
objCType).  The long long type has a different value from the  
unsigned long long type: "q" vs. "Q".


There's also this special consideration (see NSNumber class reference  
doc):
"The returned type does not necessarily match the method the receiver  
was created with."


http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ 
Foundation/Classes/NSNumber_Class/Reference/Reference.html%23// 
apple_ref/occ/cl/NSNumber


The type encodings reference:
http://developer.apple.com/library/mac/#documentation/Cocoa/ 
Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html%23// 
apple_ref/doc/uid/TP40008048-CH100-SW1



If nothing else works, convert the persistent-ID number to NSString,  
using an encoding like BASE64 or simply hex in a consistent upper or  
lower case.  I doubt that the performance cost for a string would be  
so high that making your own NSValue subclass would be worthwhile.


  -- GG

___

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

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

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

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