Re: copy & isEqual nightmares

2012-02-15 Thread Uli Kusterer
On 14.02.2012, at 17:35, Quincey Morris wrote:
> Yes, you're right, I rashly forgot to consider all the possibilities. There 
> is a kind of class whose instances are *not* (necessarily) isEqual to 
> themselves over time. I don't know that there's terminology for this -- 
> "mutable object" doesn't cover it, because (say) NSMutableDictionary is 
> mutable but *is* isEqual to itself over time.

 Why would there ever be an object that is not -isEqual: to itself? Now you've 
lost me.

> NSDictionary may not use the value object hashes, but I don't see that 
> there's anything from preventing it from doing so if it proved beneficial to 
> the implementation (as well as, of course, using the hashes of the key 
> objects). But there's also NSSet, NSCountedSet and NSOrderedSet, where the 
> [un-copied] object *is* the key, as well as things like NSMapTable.

 Those are good examples of where you may get in trouble modifying an object, 
and definitely better than my hypothetical example.

> And there's nothing preventing NSArray from keeping a supplementary 
> hash-based index to assist in looking up objects, although I can't imagine 
> it's ever likely to be implemented that way.

 I think Apple is too pragmatic to make such a change now to classes like 
NSArray or NSDictionary. Even despite documentation, I'm pretty sure too many 
applications would break after such a change.

> What you say makes practical sense, and represents sane expectations. 
> However, again, I think it's important to keep track of what the API contract 
> is, and the API contract doesn't go that far.


 That's a good maxim to live by, but still doesn't change that computer science 
has a strict definition for what a hash is (a unidirectional projection, or 
whatever it is called in English), and it also requires that it "can be used as 
a table address in a hash table structure", which implicitly restricts the 
choice of implementation somewhat.

 This is not just my interpretation. A one-way projection that turns a given 
set of (object) values into a smaller set of numeric values and its behaviour 
is defined by set theory, and works exactly as said: Identical values end up 
projected onto the same value, and some collisions occur due to the limited 
value space. Hash not equal -> objects not equal. Hash equal -> object equal or 
hash collision; compare in detail.

The only other option would be to have a call to rand() or time() in there to 
mix things up, but then it would not be suitable for use in a hash table 
structure. The definitions may be terse, but they work together to provide 
exactly this result.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de




___

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

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

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

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


Re: Odd display of percent character

2012-02-15 Thread Uli Kusterer
On 14.02.2012, at 17:53, Jens Alfke wrote:
> On Feb 14, 2012, at 5:38 AM, Uli Kusterer wrote:
>> In addition to this, whenever I do not actually need a format in a case like 
>> NSRunAlertPanel or whatever, I set the string to @"%@" and specify the 
>> actual string at the end in the ... section. That way, I don't have to tell 
>> my localizers to double their '%' signs in these five strings, or check the 
>> string for a '%' sign that some language might use in their translation of 
>> whatever the orginal '%'-less message might be.
> 
> Definitely the right thing to do. In general, using any non-constant string 
> as a format argument to a printf-like function is dangerous. There’s an 
> optional compiler warning that will detect such occurrences (I think it’s 
> -Wformat-security, or something similar to that.)

 I think "constant" is a bad choice of criterion. It depends on whether the 
source of the string is trustworthy and can be intercepted. Depending on your 
interpretation, the result of NSLocalizedString is constant (for the runtime of 
your program) or non-constant (it actually gets loaded from a file at startup, 
into dynamically allocated memory).

 If your translator hasn't been made aware of which strings are format strings, 
they don't know to watch their percent signs.

> About five years ago there was a hacker/security group that was calling 
> attention to the lax state of security in Mac apps by releasing a zero-day 
> vulnerability once a week or so. I kept track, and a scary-high fraction of 
> these were format-string exploits, where an attacker can present the app with 
> a string containing a ‘%’ character and either crash it or make it behave 
> improperly.


"One exploit a day" or something like that ... ? Yeah, I vaguely remember.

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

IKPictureTaker crash

2012-02-15 Thread Appa Rao Mulpuri
Hi List,

 I am using IKPictureTaker class for getting the picture and crop an image. If 
I pass an image with one pixel width/ height its getting crashed and giving the 
following exception. Is there any way to prevent the crash.



#0  0x7fff92d0c390 in objc_msgSend_vtable14 ()

#1  0x7fff92fc5a96 in +[NSGraphicsContext setCurrentContext:] ()

#2  0x7fff8bbcd1c8 in -[IKImageWrapper unlockFocus] ()

#3  0x7fff8bc0840d in +[IKImageCropView(utils) 
croppedImageFromOriginalImage:cropInfo:cropSize:outputSize:bgColor:] ()

#4  0x7fff8bc09bb4 in -[IKImageCropView croppedImageWithSize:] ()

#5  0x7fff8bc09b03 in -[IKImageCropView croppedImage] ()

#6  0x7fff8bc6f5e2 in -[IKPictureTaker outputImage] ()

#7  0x7fff8bc6c875 in -[IKPictureTaker _saveRecents] ()

#8  0x7fff8bc6d625 in -[IKPictureTaker doneButton:] ()

#9  0x7fff9104e75d in -[NSObject performSelector:withObject:] ()

#10 0x7fff93082cb2 in -[NSApplication sendAction:to:from:] ()

#11 0x7fff93082be6 in -[NSControl sendAction:to:] ()

#12 0x7fff93082b11 in -[NSCell _sendActionFrom:] ()

#13 0x7fff93081fd4 in -[NSCell trackMouse:inRect:ofView:untilMouseUp:] ()

#14 0x7fff93101d04 in -[NSButtonCell 
trackMouse:inRect:ofView:untilMouseUp:] ()

#15 0x7fff93080bde in -[NSControl mouseDown:] ()

#16 0x7fff9304b6e0 in -[NSWindow sendEvent:] ()

#17 0x7fff92fe416d in -[NSApplication sendEvent:] ()

#18 0x0001745d in -[XXApplication sendEvent:] (self=0x1026707e0, 
_cmd=0x7fff93915eb0, anEvent=0x107bc7a10) at 
/Users///xx/x/XXApplication.m:89

#19 0x7fff92f7a1f2 in -[NSApplication run] ()

#20 0x7fff931f8b88 in NSApplicationMain ()

#21 0x00011d03 in main (argc=1, argv=0x7fff5fbffa88) at 
/Users///xx/x/main.m:13



Apparao Mulpuri



This email and any attachments are confidential, and may be legally privileged 
and protected by copyright. If you are not the intended recipient dissemination 
or copying of this email is prohibited. If you have received this in error, 
please notify the sender by replying by email and then delete the email 
completely from your system. Any views or opinions are solely those of the 
sender. This communication is not intended to form a binding contract unless 
expressly indicated to the contrary and properly authorised. Any actions taken 
on the basis of this email are at the recipient's own risk.
___

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

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

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

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


Re: How can I detect a mouse click outside a child window on Leopard?

2012-02-15 Thread Uli Kusterer
On 14.02.2012, at 14:39, Michael Crawford wrote:
> I was just looking at the documentation for NSApplication and wondering if 
> overriding sendEvent is the way to go?  I was thinking I could monitor events 
> dispatched to my app and then, when one arrives that is not destined for the 
> child window, dismiss the popover.  I can also dismiss the popover if the 
> application loses focus.

 Might be a bit hard to avoid dismissing on clicks in the menu bar though ... 
but I might be mixing that up with Carbon. Does sendEvent: get menu bar clicks?

 But yeah, that's what I would use. I thought there was a way to install an 
event filtering/monitoring callback on NSApplication, but I can't find the call 
right now. Anyway, it's probably 10.7-only, at best 10.6.

 Failing that, you could create a transparent, borderless window with a custom 
content view that handles mouse clicks and closes your fake popover (and 
itself), I suppose. Might have to call -preventWindowOrdering in there too, in 
case someone uses Spaces or Exposé to select your blanking window or otherwise 
screw up window ordering.

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: -[NSOutlineView ibIsInDesignMode]: unrecognized selector (???)

2012-02-15 Thread Uli Kusterer

On 14.02.2012, at 23:55, Kyle Sluder wrote:

> On Tue, Feb 14, 2012 at 12:34 PM, Mikkel Eide Eriksen
>  wrote:
>> Hi,
>> 
>> I was going to implement a source list, but it's causing XCode and the 
>> Simulator to freak out. I did the following in my existing project (and then 
>> in a fresh project to make sure):
>> 
>> 1. Create window nib
>> 2. Add a source list
>> 3. Menu: Editor > Simulate Document
>> 
>> From the stacktrace it looks like the simulator is loading the nib, and the 
>> view then tries to figure out where the data should come from, and 
>> apparently has a fallback to some Interface Builder specific code that 
>> explodes?
> 
> View-based table views and outline views crash the IB simulator. This
> is a known issue.
> 
> r. 9442221


 Any chance of you posting this radar on http://openradar.me ? I'd love to 
learn more about this issue.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de




___

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

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

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

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


Re: -[NSOutlineView ibIsInDesignMode]: unrecognized selector (???)

2012-02-15 Thread Kyle Sluder
On Feb 15, 2012, at 1:18 AM, Uli Kusterer  wrote:

> Any chance of you posting this radar on http://openradar.me ? I'd love to 
> learn more about this issue.

That's really pretty much all there is to it. I suppose it might be worth 
posting so others know about it, but the entire bug is that view-based table 
views (which include the default Source List library object) + Simulate 
Document = Xcode crash.

Also, my radar was duped to this one, so I won't have the most up-to-date info.

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Sandbox - Security Scoped URLs (10.7.3)

2012-02-15 Thread Kyle Sluder
On Feb 14, 2012, at 11:13 PM, Seth Willits  wrote:

> So 10.7.3 added URLs you can restore in a sandboxed process after relaunch 
> (AKA, needed by tons of apps that will be sandboxed), but I can't get them to 
> work.
> 
> http://www.opensource.apple.com/source/CF/CF-635.19/CFURL.h
> 
> Whenever I try to create bookmark data with CFURLCreateBookmarkData passing 
> kCFURLBookmarkCreationWithSecurityScope, I get a NULL result and no error. 
> Anyone managed to figure this out?

I wonder if it's related to the reluctance of Apple employees to discuss this 
feature yet on the dev forums. Last official word is that the announcement of 
this feature was premature.

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Custom UIView drawing but can't figure out when/where it's loading

2012-02-15 Thread Matt Neuburg
On Tue, 14 Feb 2012 18:48:10 -0600, William Squires  said:
>So what's the correct place to put initialization code for a custom UIView 
>subclass?

Depends how it's instantiated. If in code, initWithFrame. But if from a nib, 
initWithFrame will never be called; instead, use initWithCoder or awakeFromNib:

http://www.apeth.com/iOSBook/ch07.html#_additional_initialization_of_nib_based_instances

It very often happens that I'll encapsulate the additional initialization in a 
single method and call that from initWithFrame *and* initWithCoder, so that it 
won't matter which way the view was instantiated. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
___

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

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

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

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


Re: Sandbox - Security Scoped URLs (10.7.3)

2012-02-15 Thread Mike Abdullah

On 15 Feb 2012, at 07:13, Seth Willits wrote:

> So 10.7.3 added URLs you can restore in a sandboxed process after relaunch 
> (AKA, needed by tons of apps that will be sandboxed), but I can't get them to 
> work.
> 
> http://www.opensource.apple.com/source/CF/CF-635.19/CFURL.h
> 
> Whenever I try to create bookmark data with CFURLCreateBookmarkData passing 
> kCFURLBookmarkCreationWithSecurityScope, I get a NULL result and no error. 
> Anyone managed to figure this out?

How were you trying to use this feature? Given that the API appears not to be 
exposed anywhere in 10.7.3's own headers.


___

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

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

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

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


[ Was NSReadPIxel ]

2012-02-15 Thread koko
Here is what I am trying to do.

My users may scan a thread color say Robinson Anton Poly 40, by wrapping the 
thread around some cardboard stock and then placing this on the scanner bed. As 
you might imagine there will  variations in the color due to the thread being 
wrapped … peaks , valleys, reflections, etc.

Now we want to bring that thread color into our embroidery program.  The 
scanned image may be on any connected display.

I want to capture a rect centered on the point where the user clicked so I can 
get a best fit for the color.

This is easy to do on Windows using the SetCapture() functions which directs 
all events to my app.

How do I get this accomplished on OSX?

-koko
 


___

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

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

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

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

Re: NSEvent locationInWindow undefined for non-mouse events, how to catch?

2012-02-15 Thread Sean McBride
On Tue, 14 Feb 2012 21:08:38 -0800, Kyle Sluder said:

>> Are you calling -type on the events you are receiving? Checking that
>value should make it clear whether the event you have received is a
>mouse event or not.  If not, and you need the mouse location, you can
>get if from NSEvent's +mouseLocation or a relevant window instance's -
>mouseLocationOutsideOfEventStream.
>
>The question is whether any debugging code can be added to catch
>instances where -type isn't being called before asking for the mouse location.

And since no one has said "yes", I've assumed it's "no" and filed 
 with the suggestion.

In the meantime, I'll create a category method that wraps locationInWindow and 
delegates to mouseLocation or similar otherwise.

Thanks to all who replied,

-- 

Sean McBride, B. Eng s...@rogue-research.com
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: copy & isEqual nightmares

2012-02-15 Thread Quincey Morris
On Feb 15, 2012, at 00:50 , Uli Kusterer wrote:

> Why would there ever be an object that is not -isEqual: to itself? Now you've 
> lost me.

Sorry, it was a poor choice of words. I was just acknowledging the difference 
between (say) a NSMutableDictionary whose internal state changes over time 
without affecting the objects it's isEqual to (just itself, in this case) and 
NSMutableString, whose internal state changes over time and does affect what 
it's isEqual to.

There are, of course, potentially, objects that aren't isEqual to themselves. 
An object representing the current (running) time might be designed to fail 
[timeNow isEqual: timeNow]. But I can't think of an example that isn't 
pathological, and such objects weren't what I had in mind earlier.


___

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

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

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

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


Re: NSEvent locationInWindow undefined for non-mouse events, how to catch?

2012-02-15 Thread Gary L. Wade
What it sounds like you're really asking in the latest part of this thread is 
for every object in a given runtime to track the messages called upon it with a 
time stamp in order to compare those for an exact ordering of calls conducive 
to your needs.

That COULD be useful, but it would be really resource-intensive, especially in 
a heavy-object-usage process if turned on for every object, but it could be 
turned on only for objects of a particular class in your scenario.
--
Gary L. Wade (Sent from my iPhone)
http://www.garywade.com/

On Feb 15, 2012, at 8:12 AM, Sean McBride  wrote:

> On Tue, 14 Feb 2012 21:08:38 -0800, Kyle Sluder said:
> 
>>> Are you calling -type on the events you are receiving? Checking that
>> value should make it clear whether the event you have received is a
>> mouse event or not.  If not, and you need the mouse location, you can
>> get if from NSEvent's +mouseLocation or a relevant window instance's -
>> mouseLocationOutsideOfEventStream.
>> 
>> The question is whether any debugging code can be added to catch
>> instances where -type isn't being called before asking for the mouse 
>> location.
> 
> And since no one has said "yes", I've assumed it's "no" and filed 
>  with the suggestion.
> 
> In the meantime, I'll create a category method that wraps locationInWindow 
> and delegates to mouseLocation or similar otherwise.
> 
> Thanks to all who replied,
> 
> -- 
> 
> Sean McBride, B. Eng s...@rogue-research.com
> 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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: NSEvent locationInWindow undefined for non-mouse events, how to catch?

2012-02-15 Thread Sean McBride
On Wed, 15 Feb 2012 09:56:33 -0800, Gary L. Wade said:

>What it sounds like you're really asking in the latest part of this
>thread is for every object in a given runtime to track the messages
>called upon it with a time stamp in order to compare those for an exact
>ordering of calls conducive to your needs.
>
>That COULD be useful, but it would be really resource-intensive,
>especially in a heavy-object-usage process if turned on for every
>object, but it could be turned on only for objects of a particular class
>in your scenario.

I'm only suggesting that locationInWindow be implemented like this:

- (NSPoint)locationInWindow
{
  if (NSDebugEnabled)
  {
NSEventType type = [self type];
assert ((type == NSLeftMouseDown) || ... );
  }
  ...
}

-- 

Sean McBride, B. Eng s...@rogue-research.com
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: NSEvent locationInWindow undefined for non-mouse events, how to catch?

2012-02-15 Thread Quincey Morris
On Feb 15, 2012, at 08:12 , Sean McBride wrote:

> In the meantime, I'll create a category method that wraps locationInWindow 
> and delegates to mouseLocation or similar otherwise.

Depending on how correct you want to be, you do have to be a bit cautious with 
this. +[NSEvent mouseLocation] isn't synchronized to the event stream, and 
therefore returns the "wrong" location if the event is significantly out of 
date (e.g. if the mouse is moving very fast, or if the app is lagging in 
dequeuing events). The mouseLocation result is also unsynchronized with the 
keyboard modifier flags. If, for example, an option-click on a certain control 
causes data to be deleted without a confirmation dialog, then using 
mouseLocation will eventually bite one of your users who *didn't* option-click 
on the control. :)

The only really safe solution is to throw an exception for accesses to 
locationInWindow for the wrong kind of event.

A third solution is to use +[NSEvent 
addLocalMonitorForEventsMatchingMask:handler:] (or subclass NSApplication and 
override sendEvent:) and keep the event-queue-synchronized values of the mouse 
location and the keyboard modifier flags globally. That makes the information 
available even when you don't have an event to refer to, which is a 
considerable convenience.


___

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

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

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

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


Re: copy & isEqual nightmares

2012-02-15 Thread Jonathan Hull
This reminded me of this blog post, which you may find interesting:
http://ridiculousfish.com/blog/posts/array.html

Thanks,
Jon


On Feb 14, 2012, at 8:35 AM, Quincey Morris wrote:

> NSDictionary may not use the value object hashes, but I don't see that 
> there's anything from preventing it from doing so if it proved beneficial to 
> the implementation (as well as, of course, using the hashes of the key 
> objects). But there's also NSSet, NSCountedSet and NSOrderedSet, where the 
> [un-copied] object *is* the key, as well as things like NSMapTable. And 
> there's nothing preventing NSArray from keeping a supplementary hash-based 
> index to assist in looking up objects, although I can't imagine it's ever 
> likely to be implemented that way.


___

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

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

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

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


receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Matt Neuburg
In Apple's delightful documentation of Chris Kane's Receptionist pattern (which 
I think of as a trampoline), the key method looks like this:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(void *)context {
[queue addOperationWithBlock:^{
task(keyPath, object, change);
}];
}

https://developer.apple.com/library/mac/#documentation/General/Conceptual/CocoaEncyclopedia/ReceptionistPattern/ReceptionistPattern.html

Typically, "queue" is [NSOperationQueue mainQueue], our goal being to get 
ourselves back on the main thread in response to receiving a KVO notification 
that might have been sent on a background thread.

My question is simply this: in a world that has GCD, is there any reason why we 
wouldn't have "queue" be a GCD dispatch queue (probably the main queue) and 
call dispatch_asynch? Putting it even more generally (and this is probably my 
*real* question), is there any reason why I'd ever use NSOperationQueue's 
addOperationWithBlock given the existence of GCD?

Thx for your thoughts - m.


--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


CGContextSaveGState

2012-02-15 Thread William Squires
Does this method store the context state in a stack, or just store it in a 
local variable (struct) somewhere (i.e. does calling this more than once 
overwrite the previously saved context info?)


___

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

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

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

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


Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Matt Neuburg
This might be another way of phrasing the same question: why does the new iOS 5 
method +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:] want 
an NSOperationQueue as its queue rather than a dispatch queue? m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Sandbox - Security Scoped URLs (10.7.3)

2012-02-15 Thread Seth Willits
On Feb 15, 2012, at 5:49 AM, Kyle Sluder wrote:

>> So 10.7.3 added URLs you can restore in a sandboxed process after relaunch 
>> (AKA, needed by tons of apps that will be sandboxed), but I can't get them 
>> to work.
>> 
>> http://www.opensource.apple.com/source/CF/CF-635.19/CFURL.h
>> 
>> Whenever I try to create bookmark data with CFURLCreateBookmarkData passing 
>> kCFURLBookmarkCreationWithSecurityScope, I get a NULL result and no error. 
>> Anyone managed to figure this out?
> 
> I wonder if it's related to the reluctance of Apple employees to discuss this 
> feature yet on the dev forums. Last official word is that the announcement of 
> this feature was premature.

That word was a couple days before 10.7.3 was released, so I understood it as 
being "10.7.3 isn't out yet, so this is premature." 

Turns out, with an extra mach service entitlement 
(com.apple.security.temporary-exception.mach-lookup.global-name / 
com.apple.scopedbookmarksagent.xpc) you can get it work, but given that, the 
lack of errors otherwise, and the fact that some of the API seems to be 
incorrect, it seems to me the API really isn't finished. I don't see how this 
March sandboxing deadline can be met.



--
Seth Willits

___

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

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

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

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


Block Behavior

2012-02-15 Thread koko
I need to know why a line of code that is OK outside a Block is invalid inside. 



=
[sp beginSheetModalForWindow:[self window] completionHandler:^(NSInteger 
result) 
{
if (result == NSFileHandlingPanelOKButton)
{
Str px("a");
prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- GIVES 
ERROR, NO MATCHING SET FUNCTION
}
 }];

Str px("a");
prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- SAME CODE 
OUTSIDE BLOCK IS OK
=
___

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

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

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

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


Re: CGContextSaveGState

2012-02-15 Thread David Duncan
On Feb 15, 2012, at 11:22 AM, William Squires wrote:

> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)


It stores it on a state stack that is associated with a CGContextRef. This is 
not the same stack as the call stack. This is discussed in the documentation 
for this function (and its associated function CGContextRestoreGState).
--
David Duncan


___

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

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

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

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


Re: CGContextSaveGState

2012-02-15 Thread Conrad Shultz
On 2/15/12 11:22 AM, William Squires wrote:
> Does this method store the context state in a stack, or just store it
> in a local variable (struct) somewhere (i.e. does calling this more
> than once overwrite the previously saved context info?)

It's a stack - a great many graphics operations would be vastly harder
if it weren't.

This is spelled out quite clearly in the documentation:

https://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html

https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html



-- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Seth Willits
On Feb 15, 2012, at 11:19 AM, Matt Neuburg wrote:

> My question is simply this: in a world that has GCD, is there any reason why 
> we wouldn't have "queue" be a GCD dispatch queue (probably the main queue) 
> and call dispatch_asynch?

I don't believe there's any difference in this example. 


> Putting it even more generally (and this is probably my *real* question), is 
> there any reason why I'd ever use NSOperationQueue's addOperationWithBlock 
> given the existence of GCD?


NSOperationQueue has support for dependencies between operations (which I take 
advantage of). You can also set max concurrency which can be useful. With some 
tweaks you can make NSOperationQueue serial, which when combined with 
inter-queue dependencies is useful.

This can all be done with GCD (NSOpQ is implemented with GCD after all), but 
with GCD it's more work and I'm more likely to make mistakes than with NSOpQ, 
so it's still useful in my experience.


--
Seth Willits

___

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

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

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

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


Re: How can I detect a mouse click outside a child window on Leopard?

2012-02-15 Thread Seth Willits
On Feb 15, 2012, at 1:14 AM, Uli Kusterer wrote:

> On 14.02.2012, at 14:39, Michael Crawford wrote:
>> I was just looking at the documentation for NSApplication and wondering if 
>> overriding sendEvent is the way to go?  I was thinking I could monitor 
>> events dispatched to my app and then, when one arrives that is not destined 
>> for the child window, dismiss the popover.  I can also dismiss the popover 
>> if the application loses focus.
> 
> Might be a bit hard to avoid dismissing on clicks in the menu bar though ... 
> but I might be mixing that up with Carbon. Does sendEvent: get menu bar 
> clicks?
> 
> But yeah, that's what I would use. I thought there was a way to install an 
> event filtering/monitoring callback on NSApplication, but I can't find the 
> call right now. Anyway, it's probably 10.7-only, at best 10.6.
> 
> Failing that, you could create a transparent, borderless window with a custom 
> content view that handles mouse clicks and closes your fake popover (and 
> itself), I suppose. Might have to call -preventWindowOrdering in there too, 
> in case someone uses Spaces or Exposé to select your blanking window or 
> otherwise screw up window ordering.


Unless I'm missing some requirement, this is all way way overly complicated.

Make the popover window key. Clicking anywhere outside of if will make the 
popover window lose key status. Just use that notification to know to close it. 
That's really all you need to do. 


--
Seth Willits

___

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

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

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

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

Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Sean McBride
On Wed, 15 Feb 2012 11:19:49 -0800, Matt Neuburg said:

>My question is simply this: in a world that has GCD, is there any reason
>why we wouldn't have "queue" be a GCD dispatch queue (probably the main
>queue) and call dispatch_asynch? Putting it even more generally (and
>this is probably my *real* question), is there any reason why I'd ever
>use NSOperationQueue's addOperationWithBlock given the existence of GCD?

NSOperationQueue is higher level, and Apple's always saying to use the highest 
level API available.  Another minor reason: NSOperationQueue is available on 
10.5, and GCD is not.

-- 

Sean McBride, B. Eng s...@rogue-research.com
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

__block __weak - am I doing this right?

2012-02-15 Thread Matt Neuburg
This appears to be working from all points of view (thank you, Instruments!):

MyMandelbrotOperation* op = 
[[MyMandelbrotOperation alloc] initWithSize:self.bounds.size 
 center:center zoom:1];
__block __weak id observer = [[NSNotificationCenter defaultCenter] 
  addObserverForName:@"MyMandelbrotOperationFinished" 
  object:op queue:[NSOperationQueue mainQueue] 
  usingBlock:^(NSNotification *note) {
MyMandelbrotOperation* op2 = note.object;
CGContextRef context = [op2 bitmapContext];
if (self->bitmapContext)
CGContextRelease(self->bitmapContext);
self->bitmapContext = (CGContextRef) context;
CGContextRetain(self->bitmapContext);
[self setNeedsDisplay];
[[NSNotificationCenter defaultCenter] removeObserver:observer 
name:@"MyMandelbrotOperationFinished" object:op2];
}];
[self.queue addOperation:op];

This is delightful. I'm not leaking self, my operations are being dealloced in 
good order, I'm successfully registering and deregistering, I'm trampolining to 
the main thread without writing a trampoline method, I'm avoiding the nightmare 
of storing my observers in an instance variable, op and op2 are the same object 
- everything about it seems to be okay. My questions are:

* Is this really an okay way to talk?

* Why was I crashing until I said __block?

m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: CGContextSaveGState

2012-02-15 Thread Fritz Anderson
On 15 Feb 2012, at 1:22 PM, William Squires wrote:

> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)

It's stacked. From the first sentence of the documentation for the function 
(not a method — best to be precise):

> PUSHES a copy of the current graphics state onto the graphics state STACK for 
> the context.

(Caps added)

— F


___

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

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

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

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

Re: [ Was NSReadPIxel ]

2012-02-15 Thread Seth Willits
On Feb 15, 2012, at 7:32 AM, koko wrote:

> I want to capture a rect centered on the point where the user clicked so I 
> can get a best fit for the color.


Here's a thought:

[NSEvent addGlobalMonitorForEventsMatchingMask:NSMouseMovedMask 
handler:^(NSEvent * event){
if (event.type == NSMouseMoved) {
NSPoint point = [NSEvent mouseLocation];
CGRect mainDisplayBounds = 
CGDisplayBounds(CGMainDisplayID());
CGPoint cgDisplayPoint = CGPointMake(point.x, 
mainDisplayBounds.size.height - point.y);
CGRect rect = CGRectMake(cgDisplayPoint.x - 10, 
cgDisplayPoint.y - 10, 20, 20);

CGImageRef imageRef = CGWindowListCreateImage(rect, 
kCGWindowListOptionOnScreenOnly, kCGNullWindowID, kCGWindowImageDefault);
magnifierView.image = [[[NSImage alloc] 
initWithCGImage:imageRef size:rect.size] autorelease];
CGImageRelease(imageRef);

} else if (event.type == NSLeftMouseDown) {
if (this is supposed to be a color selection click) {
grab the pixel color from the image
}
}
}];



--
Seth Willits

___

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

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

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

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


Re: CGContextSaveGState

2012-02-15 Thread Seth Willits
On Feb 15, 2012, at 11:22 AM, William Squires wrote:

> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)

It's a stack. Save pushes, Restore pops.


/* Push a copy of the current graphics state onto the graphics state stack.
   Note that the path is not considered part of the graphics state, and is
   not saved. */

CG_EXTERN void CGContextSaveGState(CGContextRef c)
CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);

/* Restore the current graphics state from the one on the top of the
   graphics state stack, popping the graphics state stack in the process. */

CG_EXTERN void CGContextRestoreGState(CGContextRef c)
CG_AVAILABLE_STARTING(__MAC_10_0, __IPHONE_2_0);



--
Seth Willits

___

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

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

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

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


Re: CGContextSaveGState

2012-02-15 Thread Mike Abdullah

On 15 Feb 2012, at 19:22, William Squires wrote:

> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)

To quote the docs:

"Each graphics context maintains a stack of graphics states"


___

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

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

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

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


Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Matt Neuburg

On Feb 15, 2012, at 12:53 PM, Sean McBride wrote:

> Apple's always saying to use the highest level API available

We must be watching different versions of the WWDC videos... :)))

Backwards compatibility is a good reason on the desktop, but I'm on iOS and on 
iOS if you've got blocks you've got GCD. m.

--
matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
pantes anthropoi tou eidenai oregontai phusei
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
TidBITS, Mac news and reviews since 1990, http://www.tidbits.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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Mike Abdullah
Because it's a higher-level API answers pretty much all your questions. You 
have a little more easy flexibility with what you can do to an NSOperationQueue 
compared to raw GCD.

To put it another way, what downside are you seeing to using NSOperationQueue?

On 15 Feb 2012, at 19:32, Matt Neuburg wrote:

> This might be another way of phrasing the same question: why does the new iOS 
> 5 method +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:] 
> want an NSOperationQueue as its queue rather than a dispatch queue? m.
> 
> --
> matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.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:
> https://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
> 
> This email sent to cocoa...@mikeabdullah.net


___

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

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

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

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


Re: CGContextSaveGState

2012-02-15 Thread Gideon King
The documentation says it pushes it on to a stack:

"Pushes a copy of the current graphics state onto the graphics state stack for 
the context."

It also says:

"To restore your drawing environment to a previously saved state, you can use 
CGContextRestoreGState."

with the clear implication that you can have multiple of them. And it works in 
practice too… Kind of not sure why the question, since it is clearly stated in 
the documentation...

Regards

Gideon

On 16/02/2012, at 5:22 AM, William Squires wrote:

> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)
> 
> 


___

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

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

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

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

Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Kyle Sluder
On Wed, Feb 15, 2012 at 11:19 AM, Matt Neuburg  wrote:
> My question is simply this: in a world that has GCD, is there any reason why 
> we wouldn't have "queue" be a GCD dispatch queue (probably the main queue) 
> and call dispatch_asynch? Putting it even more generally (and this is 
> probably my *real* question), is there any reason why I'd ever use 
> NSOperationQueue's addOperationWithBlock given the existence of GCD?

NSOperationQueue exists at a higher conceptual level than GCD. You can
observe the status of NSOperations, add completion handlers or drive
multiple blocks with one operation, set priority and ordering
restrictions on them, limit the number of operations executing
concurrently on an NSOperationQueue, and cancel in-flight operations.

On iOS, NSOperationQueue doesn't use GCD at all. On Mac OS X 10.6 and
greater, block-based NSOperations are submitted to global
(asynchronous) dispatch queue.

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: CGContextSaveGState

2012-02-15 Thread Kyle Sluder
On Wed, Feb 15, 2012 at 11:22 AM, William Squires  wrote:
> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)

First line of the CGContextSaveGState documentation:

"Pushes a copy of the current graphics state onto the graphics state
stack for the context."

https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: copy & isEqual nightmares

2012-02-15 Thread Graham Cox

On 16/02/2012, at 4:39 AM, Quincey Morris wrote:

> There are, of course, potentially, objects that aren't isEqual to themselves.


Surely the first thing that -isEqual: does is to trivially accept the case 
where self == otherObject? Certainly when I've implemented -isEqual: I do that 
as a matter of course. It's only when the addresses differ that you then look 
deeper to see whether they are equal in some other sense.

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: [ Was NSReadPIxel ]

2012-02-15 Thread Graham Cox

On 16/02/2012, at 2:32 AM, koko wrote:

> Now we want to bring that thread color into our embroidery program.  The 
> scanned image may be on any connected display.
> 
> I want to capture a rect centered on the point where the user clicked so I 
> can get a best fit for the color.
> 
> This is easy to do on Windows using the SetCapture() functions which directs 
> all events to my app.
> 
> How do I get this accomplished on OSX?


By breaking the problem down. If you can load an image, you can sample its 
colours. If you can create an image from the scanner, you have a way to capture 
the image. I believe there is a framework for acquiring images, including from 
scanners. I haven't used it so I can't help there, but why not just work on the 
sampling a colour from an image part? That way you can simply open an image 
from disk and develop that part of the code.

I don't see what screens/displays have to do with this problem at all.

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: CGContextSaveGState

2012-02-15 Thread Nick Zitzmann

On Feb 15, 2012, at 12:22 PM, William Squires wrote:

> Does this method store the context state in a stack, or just store it in a 
> local variable (struct) somewhere (i.e. does calling this more than once 
> overwrite the previously saved context info?)


CoreGraphics state save/load operations are always pushed to/popped from a 
stack.

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Re: Block Behavior

2012-02-15 Thread Mike Abdullah
Give us the full details. What specific error are you seeing?

On 15 Feb 2012, at 20:14, koko wrote:

> I need to know why a line of code that is OK outside a Block is invalid 
> inside. 
> 
> 
> 
> =
>[sp beginSheetModalForWindow:[self window] completionHandler:^(NSInteger 
> result) 
>{
>if (result == NSFileHandlingPanelOKButton)
>{
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- GIVES 
> ERROR, NO MATCHING SET FUNCTION
>}
> }];
> 
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- SAME CODE 
> OUTSIDE BLOCK IS OK
> =
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/cocoadev%40mikeabdullah.net
> 
> This email sent to cocoa...@mikeabdullah.net


___

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

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

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

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


Re: Block Behavior

2012-02-15 Thread David Duncan
Which compiler are you using?

On Feb 15, 2012, at 12:14 PM, koko wrote:

> I need to know why a line of code that is OK outside a Block is invalid 
> inside. 
> 
> 
> 
> =
>[sp beginSheetModalForWindow:[self window] completionHandler:^(NSInteger 
> result) 
>{
>if (result == NSFileHandlingPanelOKButton)
>{
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- GIVES 
> ERROR, NO MATCHING SET FUNCTION
>}
> }];
> 
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- SAME CODE 
> OUTSIDE BLOCK IS OK
> =
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

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

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

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

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


Re: Block Behavior

2012-02-15 Thread Greg Parker
On Feb 15, 2012, at 12:14 PM, koko  wrote:
> I need to know why a line of code that is OK outside a Block is invalid 
> inside. 
> 
> =
>[sp beginSheetModalForWindow:[self window] completionHandler:^(NSInteger 
> result) 
>{
>if (result == NSFileHandlingPanelOKButton)
>{
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- GIVES 
> ERROR, NO MATCHING SET FUNCTION
>}
> }];
> 
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- SAME CODE 
> OUTSIDE BLOCK IS OK
> =

What compiler and version are you using? What is the exact text of the error 
message?


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



___

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

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

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

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


Re: Make Custom Struct Key-Value Coding Compliant

2012-02-15 Thread Richard Somers
SOLVED - Thanks for all the comments.


On Feb 11, 2012, at 11:56 PM, Graham Cox wrote:

> Making it an object is easy and usually it turns out that the desire to 
> resist doing that is misguided, based on some faulty assumptions.

I decided to resist no longer and make my custom strut an object. I made an 
object that had individual properties corresponding to the struct members. 
Unfortunately this created to many problems elsewhere.

But the story has a happy ending. Arbitrary structs are Key-Value Coding 
compliant and work fine with Core Data, they do not need to be stored in the 
managed object as an object. The documentation is in error on this point.


On Feb 12, 2012, at 2:18 AM, Joar Wingfors wrote:

> Please file a bug report on the documentation:

Filed bug report Bug ID# 10872122.


On Feb 12, 2012, at 6:50 AM, John Joyce wrote:

> But the best advice, don't fight the framework.

Agreed. Originally I thought that custom structs were not compatible with Core 
Data. But this is not true. They can work very well with the framework.


Thanks again.

--Richard


___

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

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

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

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


Re: __block __weak - am I doing this right?

2012-02-15 Thread Greg Parker
On Feb 15, 2012, at 12:58 PM, Matt Neuburg  wrote:
> This appears to be working from all points of view (thank you, Instruments!):
> 
>MyMandelbrotOperation* op = 
>[[MyMandelbrotOperation alloc] initWithSize:self.bounds.size 
> center:center zoom:1];
>__block __weak id observer = [[NSNotificationCenter defaultCenter] 
>  addObserverForName:@"MyMandelbrotOperationFinished" 
>  object:op queue:[NSOperationQueue mainQueue] 
>  usingBlock:^(NSNotification *note) {
>MyMandelbrotOperation* op2 = note.object;
>CGContextRef context = [op2 bitmapContext];
>if (self->bitmapContext)
>CGContextRelease(self->bitmapContext);
>self->bitmapContext = (CGContextRef) context;
>CGContextRetain(self->bitmapContext);
>[self setNeedsDisplay];
>[[NSNotificationCenter defaultCenter] removeObserver:observer 
>name:@"MyMandelbrotOperationFinished" object:op2];
>}];
>[self.queue addOperation:op];
> 
> This is delightful. I'm not leaking self, my operations are being dealloced 
> in good order, I'm successfully registering and deregistering, I'm 
> trampolining to the main thread without writing a trampoline method, I'm 
> avoiding the nightmare of storing my observers in an instance variable, op 
> and op2 are the same object - everything about it seems to be okay. My 
> questions are:
> 
> * Is this really an okay way to talk?

Are you using GC or ARC? I think this is safe with GC but not safe with ARC, 
but I'm not an expert in the NSNotificationCenter machinery.


> * Why was I crashing until I said __block?

Without __block, the block object snapshots the value of the observer variable 
when the block object is created. But in your code the block object is created 
before the call to -addObserverForName:..., and at that point the observer 
variable is not yet initialized. Boom.

With __block, the block object always uses the current value of the observer 
variable. The variable is initialized before the block object actually 
executes, so everything works.


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



___

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

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

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

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


Re: __block __weak - am I doing this right?

2012-02-15 Thread Roland King
I had a similar one the other week, same idea, notification I wanted to remove 
in its handler. 

I assume that before you added __block you were getting an exception in the 
block handler, EACCESS was mine I think. 

I also changed to a block variable and it started working. My presumption was 
that observer was being captured as nil, or some unassigned value into the 
block as the method was entered and thus was rubbish when the callback came and 
as it was not a block variable the later assignment did not change the value 
captured in the block.  I also assumed that making it a block variable allowed 
the captured observer to be changed to the result of addObserver:.. at the end 
of the method call and be available to the block. 

And yes I now love blocks too, especially with all the asynchronous methods 
icloud uses. It's great in an open callback for a document to throw a block on 
the main queue to close it again on the next cycle, and do something else when 
the close callback comes. 

On 16 Feb, 2012, at 4:58, Matt Neuburg  wrote:

> This appears to be working from all points of view (thank you, Instruments!):
> 
>MyMandelbrotOperation* op = 
>[[MyMandelbrotOperation alloc] initWithSize:self.bounds.size 
> center:center zoom:1];
>__block __weak id observer = [[NSNotificationCenter defaultCenter] 
>  addObserverForName:@"MyMandelbrotOperationFinished" 
>  object:op queue:[NSOperationQueue mainQueue] 
>  usingBlock:^(NSNotification *note) {
>MyMandelbrotOperation* op2 = note.object;
>CGContextRef context = [op2 bitmapContext];
>if (self->bitmapContext)
>CGContextRelease(self->bitmapContext);
>self->bitmapContext = (CGContextRef) context;
>CGContextRetain(self->bitmapContext);
>[self setNeedsDisplay];
>[[NSNotificationCenter defaultCenter] removeObserver:observer 
>name:@"MyMandelbrotOperationFinished" object:op2];
>}];
>[self.queue addOperation:op];
> 
> This is delightful. I'm not leaking self, my operations are being dealloced 
> in good order, I'm successfully registering and deregistering, I'm 
> trampolining to the main thread without writing a trampoline method, I'm 
> avoiding the nightmare of storing my observers in an instance variable, op 
> and op2 are the same object - everything about it seems to be okay. My 
> questions are:
> 
> * Is this really an okay way to talk?
> 
> * Why was I crashing until I said __block?
> 
> m.
> 
> --
> matt neuburg, phd = m...@tidbits.com, http://www.apeth.net/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.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:
> https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
> 
> This email sent to r...@rols.org

___

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

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

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

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


Re: __block __weak - am I doing this right?

2012-02-15 Thread Wim Lewis

On 15 Feb 2012, at 12:58 PM, Matt Neuburg wrote:
> * Why was I crashing until I said __block?


Without __block, the value of the variable is copied into the block 
(effectively as a const local variable) when the block is created. With 
__block, both the code inside and outside the block reference the same 
variable, and each can see each others' modifications (almost like a closure in 
languages that have that).

The block is created before 'observer' is initialized (it has to be, so that it 
can be passed to -addOberver...), so the value of 'observer' it captures when 
it is created is the value of the uninitialized stack variable. It's as if you 
were doing this:

  id observer = createObserverStuff(observer);

instead of this, which is kinda sorta what happens with __block variables:

  id observer = createObserverStuff(&observer);



___

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

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

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

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


Re: [ Was NSReadPIxel ]

2012-02-15 Thread Kyle Sluder
On Wed, Feb 15, 2012 at 7:32 AM, koko  wrote:
> Here is what I am trying to do.
>
> My users may scan a thread color say Robinson Anton Poly 40, by wrapping the 
> thread around some cardboard stock and then placing this on the scanner bed. 
> As you might imagine there will  variations in the color due to the thread 
> being wrapped … peaks , valleys, reflections, etc.
>
> Now we want to bring that thread color into our embroidery program.  The 
> scanned image may be on any connected display.
>
> I want to capture a rect centered on the point where the user clicked so I 
> can get a best fit for the color.

Wait, you're trying to color-match against a specimen by _reading
color values from the screen?_

Does this not strike you as unnecessarily circuitous? Or fragile? Or
prone to unwanted interference from monitor color calibration?

Why not use ImageCapture to actually get the images straight from the
input device? Or if the user already has an image (preferably with an
embedded color profile), let them import the image file directly. Then
you can present your color sampling interface without any silly
screen-reading trickery.

--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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Block Behavior

2012-02-15 Thread koko
Apple llvm 3.0

No matching member function for call to 'Set'

Candidate function not viable: 'this' argument has type 'const BPreferences', 
but method is not marked const


As you can see from what I included this error is not generated if the function 
being called is outside the block


On Feb 15, 2012, at 4:55 PM, Greg Parker wrote:

> On Feb 15, 2012, at 12:14 PM, koko  wrote:
>> I need to know why a line of code that is OK outside a Block is invalid 
>> inside. 
>> 
>> =
>>   [sp beginSheetModalForWindow:[self window] completionHandler:^(NSInteger 
>> result) 
>>   {
>>   if (result == NSFileHandlingPanelOKButton)
>>   {
>>   Str px("a");
>>   prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- GIVES 
>> ERROR, NO MATCHING SET FUNCTION
>>   }
>>}];
>> 
>>   Str px("a");
>>   prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- SAME CODE 
>> OUTSIDE BLOCK IS OK
>> =
> 
> What compiler and version are you using? What is the exact text of the error 
> message?
> 
> 
> -- 
> Greg Parker gpar...@apple.com Runtime Wrangler
> 
> 
> 


___

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

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

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

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


Re: Block Behavior

2012-02-15 Thread Dave Zarzycki
Koko,

Are you using C++? (Probably.) If you are, then do you have a "const" version 
of Set? (Probably not.)

If the above is not true, then what is the exact compiler error, and can you 
reduce this down to a test case?

Thanks!

davez


On Feb 15, 2012, at 3:14 PM, koko  wrote:

> I need to know why a line of code that is OK outside a Block is invalid 
> inside. 
> 
> 
> 
> =
>[sp beginSheetModalForWindow:[self window] completionHandler:^(NSInteger 
> result) 
>{
>if (result == NSFileHandlingPanelOKButton)
>{
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- GIVES 
> ERROR, NO MATCHING SET FUNCTION
>}
> }];
> 
>Str px("a");
>prefs.Set((char*)"Designer1", (char*)"savepath", px ); <-- SAME CODE 
> OUTSIDE BLOCK IS OK
> =
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/zarzycki%40apple.com
> 
> This email sent to zarzy...@apple.com


___

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

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

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

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


Re: receptionist pattern question: NSOperationQueue vs. GCD

2012-02-15 Thread Preston Sumner
On Feb 15, 2012, at 12:32 PM, Matt Neuburg wrote:

> This might be another way of phrasing the same question: why does the new iOS 
> 5 method +[NSURLConnection sendAsynchronousRequest:queue:completionHandler:] 
> want an NSOperationQueue as its queue rather than a dispatch queue? m.

In OS X 10.6 and up, NSOperationQueue is implemented using GCD, and I assume 
the same is true in iOS 5. It's typically best to go with the highest level API 
available unless you have a specific reason not to.

Preston
___

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

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

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

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


Re: Custom UIView drawing but can't figure out when/where it's loading

2012-02-15 Thread H. Miersch
>> Or is my installation of Xcode screwed up?
> 
> Probably not. Why would you think that. 

It's not as unlikely as it sounds. i had an issue where xcode would crash so 
often it became impossible to get anything done. even loading a workspace would 
be enough to make it crash. reinstalling xcode thing fixed the problem. for 
good, i hope.
___

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

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

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

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


Re: ARC + return of autoreleased CFType

2012-02-15 Thread Matt Neuburg
On Thu, 20 Oct 2011 17:38:03 -0400, Bill Cheeseman  said:
>
>Specifically, if your Cocoa method returns a CFTypeRef object retained, and 
>you don't put "Copy" or "Create" in the method name, Analyze reports a 
>"potential" memory leak. Go back and insert "Copy" or "Create" into the method 
>name, and Analyze no longer reports a potential memory leak. To me, it makes 
>all the sense in the world to apply the "create rule" to Cocoa methods that 
>return Core Foundation CFTypeRef objects.

I just tried that it and it didn't help:

- (CGContextRef) bitmapContextCreate:(CGSize)size {
int bitmapBytesPerRow = (size.width * 4);
bitmapBytesPerRow += (16 - bitmapBytesPerRow%16)%16;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef context = NULL;
context = CGBitmapContextCreate(NULL, size.width, size.height, 
8, bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
return context;
}

As long as I am returning a context obtained with CGBitmapContextCreate and not 
autoreleased, it doesn't matter what I name the method: the analyzer is 
unhappy. And under ARC it isn't clear what I can do about this, since I can't 
autorelease anything and I can't invite ARC to do so (and anyway I don't want 
to). Only adding CF_RETURNS_RETAINED quieted the analyzer. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 5! http://shop.oreilly.com/product/0636920023562.do
___

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

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

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

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


Re: Block Behavior

2012-02-15 Thread Jens Alfke

On Feb 15, 2012, at 4:41 PM, koko wrote:

> Candidate function not viable: 'this' argument has type 'const BPreferences', 
> but method is not marked const

Blocks can’t modify variables in the enclosing scope unless the variables are 
marked ‘__block’. In C++ code, I suppose that extends to interpreting those 
variables as ‘const’, which makes sense, otherwise you could call a method from 
the block that could mutate the variable.

If ‘prefs’ is a local variable, try prefixing the declaration with ‘__block’.

—Jens

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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


Creating a file using NSURL

2012-02-15 Thread Quincey Morris
Am I missing something obvious here?

I'm trying to create an empty file (prior to using a NSFileHandle to write its 
contents), and I have a URL for the place to create it, and I want to avoid 
path-based API where possible, and I'm targeting 10.6. The only URL-based file 
creation API I know of is in NSData (NSFileManager can create directories from 
a URL, not files AFAICT.)

If the file can't be created (e.g. I tried to create it on a DVD that happened 
to show up in the Save panel), -[NSData writeToURL:error:] correctly fails, but 
it returns an error that looks like this:

> Error Domain=NSCocoaErrorDomain Code=4 "The file “[…]” doesn’t exist." 
> UserInfo=0x400f252c0 {NSFilePath=/Volumes/[…], NSUnderlyingError=0x400f25140 
> "The operation couldn’t be completed. No such file or directory"}

IOW, NSData is reporting the "wrong" error, as this message isn't helpful to 
present to the user.

Is there another API I should be using that will producing an error saying that 
the file couldn't be created -- or better still saying *why* the file couldn't 
be created? Does the misleading error message count as a bug in -[NSData 
writeToURL:error:]?




___

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

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

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

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