Re: log file in apple system log

2011-05-16 Thread Ben Gollmer
On May 16, 2011, at 7:23 PM, Rainer Standke wrote:

> Hello,
> 
> I am trying to have my Mac app log info in such a way that a log file will be 
> visible in the Console app, and the logfile is managed by syslogd.
> 
> I am playing with asl_log and friends, and I can make things appear in the 
> system log. How do I cause the creation of a distinct log file for the app, 
> and its appearance in Console?

This doesn't have much to do with Cocoa, but it sounds like you want 
asl_add_log_file(). From asl(3):

> asl_add_log_file(asl, fd) adds the file descriptor fd to the a set of
> file descriptors associated with the client handle asl.  Each log message
> sent by that client handle is also written to these file descriptors.
> Returns 0 on success, non-zero on failure.

-- 
Ben


___

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

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

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

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


Scrolling to a point in WebView

2011-05-16 Thread Venkat
Hi,

I have a webview in my application. I have a requirement to search for a word 
in the WebView and then dynamically scroll to the found text. I am able to find 
the text in the WebView using the - (BOOL)searchFor:(NSString *)string 
direction:(BOOL)forward caseSensitive:(BOOL)caseFlag wrap:(BOOL)wrapFlag 
method. But I am not able to scroll to the text. 

Any suggestions on how to handle this? 

Thanks and Regards,
Venkat Suraj S___

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

Please do not post 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: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Greg Parker
On May 16, 2011, at 7:15 PM, Nick Zitzmann wrote:
> On May 16, 2011, at 8:05 PM, Greg Parker wrote:
>> 
>> Don't bother. The menu zone is gone as of Snow Leopard. -setMenuZone: does 
>> nothing, and -menuZone always returns the default malloc zone.
> 
> Really? Good to know. I filed bug #9450065 on this issue.

Good idea; IMO +menuZone should be deprecated. For what it's worth, NSMenu.h 
says this:
/* Returns the zone used to allocate NSMenu objects.  This is left in for 
compatibility and always returns NSDefaultMallocZone().  It is not necessary to 
use this - menus can be allocated the usual way. */
+ (NSZone *)menuZone;


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


___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Nick Zitzmann

On May 16, 2011, at 8:05 PM, Greg Parker wrote:

>> That's not true with NSMenu; the OP actually had it right: 
>> 
> 
> Don't bother. The menu zone is gone as of Snow Leopard. -setMenuZone: does 
> nothing, and -menuZone always returns the default malloc zone.

Really? Good to know. I filed bug #9450065 on this issue.

Nick Zitzmann




___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Greg Parker
On May 16, 2011, at 6:16 PM, Nick Zitzmann wrote:
> On May 16, 2011, at 5:49 PM, Conrad Shultz wrote:
>> 
>> On 5/16/11 4:04 PM, Martin Batholdy wrote:
>>> Hi,
>>> 
>>> I create an NSMenu by myself;
>>> 
>>> menu = [[NSMenu allocWithZone:menuZone] init];
>> 
>> What Nick said.
>> 
>> Plus, you almost never want to use -allocWithZone:.  Zones are a
>> particularly arcane subject and explicit determination of a zone is best
>> avoided.
> 
> That's not true with NSMenu; the OP actually had it right: 
> 

Don't bother. The menu zone is gone as of Snow Leopard. -setMenuZone: does 
nothing, and -menuZone always returns the default malloc zone.


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


___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 5/16/11 6:16 PM, Nick Zitzmann wrote:
>> Plus, you almost never want to use -allocWithZone:.  Zones are a 
>> particularly arcane subject and explicit determination of a zone is
>> best avoided.
> 
> That's not true with NSMenu; the OP actually had it right:
> 

I know that one CAN specify zones (and that NSMenu has methods to
support that), but why is it desirable/necessary to use them in this
case?  My assumption, absent documentation to the contrary, is that
framework classes have overridden -alloc to set appropriate zones
internally.

Consistent with my previous assumption, searching through the
"Application Menu and Pop-up List Programming Topics" reveals no mention
of zones at all, and all code samples therein simply use -alloc (whether
in the case of NSMenu or NSMenuItem).  It looks like the "MenuMadness"
sample application uses allocWithZone, but no comment is made in the
code as to why.

I would appreciate for my own edification some deeper explanation.
Every third-party treatise I've seen (particularly Hillegass' intro book
and Buck's "Cocoa Design Patterns") discourages working with zones, as
does (albeit weakly) Apple's own memory performance docs ("In reality,
the overhead of zones often eliminates the performance advantages
associated with the zone.").

If I've been doing things wrong I want to fix them.

- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFN0dXAaOlrz5+0JdURAqbvAJ995F07WSJnzEJ1jfnx7s/Cj9OhkgCcCtG+
OSY61cOkly1Bh5yONwyGhr4=
=6iH0
-END PGP SIGNATURE-
___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Nick Zitzmann

On May 16, 2011, at 5:49 PM, Conrad Shultz wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
> 
> On 5/16/11 4:04 PM, Martin Batholdy wrote:
>> Hi,
>> 
>> I create an NSMenu by myself;
>> 
>> menu = [[NSMenu allocWithZone:menuZone] init];
> 
> What Nick said.
> 
> Plus, you almost never want to use -allocWithZone:.  Zones are a
> particularly arcane subject and explicit determination of a zone is best
> avoided.

That's not true with NSMenu; the OP actually had it right: 


Nick Zitzmann




___

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

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

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

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


Re: Asynchronous Notification Failed

2011-05-16 Thread Graham Cox

On 17/05/2011, at 10:43 AM, Graham Cox wrote:

> 
> On 17/05/2011, at 7:19 AM, Bing Li wrote:
> 
>> I was told I should implement a RunLoop in
>> the code. How to do that?
> 
> 
> you call [NSApp run];


Actually, correction - you don't. You just call NSApplicationMain(...), which 
creates the app and runs it for you. Even easier. The fact that I'd forgotten 
exactly what was in main.m just goes to show, you never need to know or look at 
this if you let Xcode set up your project for you.

--Graham


___

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

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

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

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


Re: Asynchronous Notification Failed

2011-05-16 Thread Graham Cox

On 17/05/2011, at 7:19 AM, Bing Li wrote:

> I was told I should implement a RunLoop in
> the code. How to do that?


you call [NSApp run];


Which requires that you have initialised NSApplication, which a default Xcode 
Cocoa project does for you (and where the above method is also called for you). 
Look at the default main.m file.

To NOT have a run loop available takes much more work than to have one, so just 
let Xcode set up your project and it's ready to go. You don't need to know 
anything much about run loops to write Cocoa apps, but if you don't have it 
there, lots of stuff won't work.

--Graham


___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 5/16/11 4:44 PM, Martin Batholdy wrote:
> Is this how you would do it properly:
> 
> newItem = [[NSMenuItem alloc]  initWithTitle:aTitle action:@selector(show:)  
> keyEquivalent:@""];
> 
> [menu addItem:newItem];
> // with the addItem command newItem gets retained by 1. So I can release it:
> 
> [newItem release];

Much better, but try to think in terms of ownership, not retain counts.
 If you need something to stick around, take ownership: -retain it (or
- -init, -copy, etc., per the rules Nick sent you to).  When you are
finished, -release it (relinquish ownership).

If you start thinking in terms of retain counts you run the risk of
trying to interpret -retainCount as a number that is somehow useful.
(It's not, for a reasonable definition of "useful.)  Worse, you might
try to use strategic -retain and -release calls to shim the retain count
to what you expect (don't do this).

Just beat the memory management rules into your head and follow them
assiduously.  Trust that NSObject is managing the retain count for you
properly.

So, in the case above, if you needed to access newItem later on, don't
release it (yet).  Release it when you are finished.  In the case of
ivars, this means retaining when the ivar is set and releasing in
- -dealloc (and not ignoring XCode's warning that you failed to call
[super dealloc]... you'll get my reference in the future if you don't
already).

> and [menu removeItemAtIndex: x]; should destroy the object newItem points to 
> because the retain count decreases to 0.

Or, restated, trust that -removeItemAtIndex: will obey its contract with
you vis-a-vis memory management and that the object will go away at an
appropriate time.

Note that, in general, deallocation does NOT nil out the object.  So at
some point you will inevitably crash with the infamous EXC_BAD_ACCESS,
which almost certainly means that you tried to send a message to an
object that has been deallocated.  Just wanted to let you know this in
advance so you have somewhere to start when you run into this.

Finally, when you think you finally understand the rules, run your
application through Leaks and make liberal use of the heapshot tool to
understand what's going on.  Fixing the leaks will do wonders for
cementing your understanding.  Bill Bumgarner has a nice post on this point:

http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/

- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFN0b5CaOlrz5+0JdURAi64AJ4js6ieIlie9s3l+O08XV0ieLH/swCeMmIW
KUeZExnh6PDj7esTklHdS9I=
=nFPf
-END PGP SIGNATURE-
___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Conrad Shultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 5/16/11 4:04 PM, Martin Batholdy wrote:
> Hi,
> 
> I create an NSMenu by myself;
> 
> menu = [[NSMenu allocWithZone:menuZone] init];

What Nick said.

Plus, you almost never want to use -allocWithZone:.  Zones are a
particularly arcane subject and explicit determination of a zone is best
avoided.

There are (few) situations where you might actually want
- -allocWithZone:, but at this stage in your learning I advise you just
pretend zones don't exist.

- -- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iD8DBQFN0bgHaOlrz5+0JdURAh85AJ9VYe/7+hajavGYrtPz22IjvifkwACghPGm
1gRKOl8slESkEZqrOnI3dgM=
=MxJd
-END PGP SIGNATURE-
___

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

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

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

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


Re: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Martin Batholdy
> Also, you are double-initializing the object, and under no circumstances 
> should you ever do that.

Ok, thanks for pointing that out ... I still overlook these things ...


Ok ... now I tried to reread the official documents ...


Is this how you would do it properly:

newItem = [[NSMenuItem alloc]  initWithTitle:aTitle action:@selector(show:)  
keyEquivalent:@""];

[menu addItem:newItem];
// with the addItem command newItem gets retained by 1. So I can release it:

[newItem release];


and [menu removeItemAtIndex: x]; should destroy the object newItem points to 
because the retain count decreases to 0.






On 17.05.2011, at 01:13, Nick Zitzmann wrote:

> 
> On May 16, 2011, at 5:04 PM, Martin Batholdy wrote:
> 
>> Hi,
>> 
>> I create an NSMenu by myself;
>> 
>> menu = [[NSMenu allocWithZone:menuZone] init];
>> 
>> And depending on some data NSMenuItems get created.
>> 
>> 
>> Now these menuItems get deleted and redrawn depending on some actions of the 
>> user with
>> 
>> [menu removeItemAtIndex: x];
>> 
>> 
>> I create the menu items like this:
>> 
>> newItem = [[NSMenuItem alloc] init];
>> [newItem initWithTitle:aTitle
>>  action:@selector(show:)  
>>   keyEquivalent:@""];
>> [menu addItem:newItem];
>> 
>> 
>> Now is this a memory leak?
> 
> Yes, unless you turned on GC. Also, you are double-initializing the object, 
> and under no circumstances should you ever do that.
> 
>> Because I don't release it anywhere. However the menu sometimes gets updated.
>> So this code ([[NSMenuItem alloc] init]) is invoked several times without a 
>> release call anywhere.
>> 
>> 
>> Is this better:
>> 
>> NSMenuItem *newItem = [menu addItemWithTitle:aTitle action:@selector(show:) 
>> keyEquivalent:@""];
>> ...
>> 
>> since I don't own newItem it should get autoreleased, right?
> 
> Please re-read the memory management rules I sent you last time. The answer 
> is in there.
> 
> Nick Zitzmann
> 
> 

___

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

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

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

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


Re: selectionIndexesForProposedSelection on mouse Up or mouse Down

2011-05-16 Thread Corbin Dunn

On May 13, 2011, at 10:56 AM, Quincey Morris wrote:

> On May 13, 2011, at 10:36, Corbin Dunn wrote:
> 
>> On May 12, 2011, at 1:42 PM, Brad Stone wrote:
>> 
>>> I put in NSLog calls to show me when "proposed" and "didChange" get called. 
>>>  NSTableView's delegate gets called on mouseDown while NSOutlineView on 
>>> mouseUp.
>> 
>> That shouldn't be true...and I'm not sure I believe it. Do you have a 
>> backtrace showing this case?
> 
> I was able to confirm the difference in behavior that Brad observed, but I 
> didn't try to find the cause.
> 
> In the example I looked at, there were two implementation differences between 
> the table and outline view:
> 
> -- The outline view data source implements 
> 'outlineView:writeItems:toPasteboard:' (etc), while the table view data 
> source does not implement 'tableView:writeRowsWithIndexes:toPasteboard:' 
> (etc).
> 
> -- The outline view delegate implements 
> 'outlineView:selectionIndexesForProposedSelection:', while the table view 
> (which dates back to older code) uses 'tableView:shouldSelectRow:'.
> 
> I'm guessing one of these causes the difference in behavior, most likely the 
> first.
> 

That is correct -- if you implement drag, then things are delayed slightly to 
allow the drag to start. But, the ordering is identical for tableview and 
outlineview, if implement the same delegate/datasource methods.

corbin


___

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

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

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

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


log file in apple system log

2011-05-16 Thread Rainer Standke
Hello,

I am trying to have my Mac app log info in such a way that a log file will be 
visible in the Console app, and the logfile is managed by syslogd.

I am playing with asl_log and friends, and I can make things appear in the 
system log. How do I cause the creation of a distinct log file for the app, and 
its appearance in Console?

Any pointers would be appreciated.

Rainer___

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

Please do not post 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: how to create a NSMenuItem without memory leaks

2011-05-16 Thread Nick Zitzmann

On May 16, 2011, at 5:04 PM, Martin Batholdy wrote:

> Hi,
> 
> I create an NSMenu by myself;
> 
> menu = [[NSMenu allocWithZone:menuZone] init];
> 
> And depending on some data NSMenuItems get created.
> 
> 
> Now these menuItems get deleted and redrawn depending on some actions of the 
> user with
> 
> [menu removeItemAtIndex: x];
> 
> 
> I create the menu items like this:
> 
> newItem = [[NSMenuItem alloc] init];
> [newItem initWithTitle:aTitle
>   action:@selector(show:)  
>keyEquivalent:@""];
> [menu addItem:newItem];
> 
> 
> Now is this a memory leak?

Yes, unless you turned on GC. Also, you are double-initializing the object, and 
under no circumstances should you ever do that.

> Because I don't release it anywhere. However the menu sometimes gets updated.
> So this code ([[NSMenuItem alloc] init]) is invoked several times without a 
> release call anywhere.
> 
> 
> Is this better:
> 
> NSMenuItem *newItem = [menu addItemWithTitle:aTitle action:@selector(show:) 
> keyEquivalent:@""];
> ...
> 
> since I don't own newItem it should get autoreleased, right?

Please re-read the memory management rules I sent you last time. The answer is 
in there.

Nick Zitzmann


___

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

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

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

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


how to create a NSMenuItem without memory leaks

2011-05-16 Thread Martin Batholdy
Hi,

I create an NSMenu by myself;

menu = [[NSMenu allocWithZone:menuZone] init];

And depending on some data NSMenuItems get created.


Now these menuItems get deleted and redrawn depending on some actions of the 
user with

[menu removeItemAtIndex: x];


I create the menu items like this:

newItem = [[NSMenuItem alloc] init];
[newItem initWithTitle:aTitle
action:@selector(show:)  
 keyEquivalent:@""];
[menu addItem:newItem];


Now is this a memory leak?

Because I don't release it anywhere. However the menu sometimes gets updated.
So this code ([[NSMenuItem alloc] init]) is invoked several times without a 
release call anywhere.


Is this better:

NSMenuItem *newItem = [menu addItemWithTitle:aTitle action:@selector(show:) 
keyEquivalent:@""];
...

since I don't own newItem it should get autoreleased, right?

___

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

Please do not post 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: Asynchronous Notification Failed

2011-05-16 Thread Wim Lewis

On 16 May 2011, at 2:19 PM, Bing Li wrote:
> An application, AppController, which is interested in the asynchronous
> notification, is as follows. I put sleep(5) deliberately to test if the
> asynchronous notification works.

As far as the run loop is concerned, when you are in sleep(5) you are busy. In 
order for other events to be processed (including NSNotificationQueues) you 
need to return to the run loop (or recursively run the run loop again, but 
that's not usually the right thing to do).

If you're using a run loop, you should structure your program like this:
  1. Set up the run loop, creating input sources etc. to call your code when 
things happen.
  2. Start running the run loop, trusting it to call you when something happens.
 (If you're writing a GUI application, NSApplication does most of this for 
you.)
  3. Whenever your code is invoked, handle the event and return to the run 
loop. Never wait for anything! Instead, tell the run loop to call you when the 
thing happens, or after a delay if the thing doesn't happen.


If you have an operation that takes a long time, like a complex computation, 
then doing it when called from the run loop will make your application 
unresponsive while the operation is working. This is usually undesired. It's 
better to spawn a thread (or dispatch a block/function/method/NSOperation on a 
dispatch queue) to handle that computation and then pass the results back to 
the run loop when it is done. If you're waiting for network operations, don't 
block in read(): instead, create run loop sources for your socket (or use a 
higher level API such as NSURLConnection).


It's not necessary to use a run loop for non-GUI Cocoa programming. You can 
choose whether or not to, depending on what your program does. If your program 
will have a GUI, then it must use Cocoa's run loop.


___

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

Please do not post 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: Why RunLoop?

2011-05-16 Thread Bill Bumgarner
In short, do **not** poll.  Not ever.

If you are doing something like this:

while (stillDontGotIt) {
  sleepForAMomentAndHopeWeGetIt();
}

(or the obvious spin-and-try-lock variant).

Then you are doing it wrong.

It eats CPU, makes your app less responsive, eats battery life, and is less 
efficient.   Far far more efficient is to set up various triggers or points of 
coordination -- queues, callbacks, run loop events, etc… -- through which your 
app will be notified when something is ready to be processed.

b.bum___

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

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

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

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


Asynchronous Notification Failed

2011-05-16 Thread Bing Li
Dear all,

I am learning how to program an asynchronous notification system. But it
only works as a synchronous one. I was told I should implement a RunLoop in
the code. How to do that? I am not familiar with RunLoop. The sample code is
listed as follows. Could you please help me how to solve the problem?

Thanks so much!
Bing

The code, WorkingApp, did something and invoked an asynchronous notification
after the job was done.


@implementation WorkingApp

- (void) Print
{
NSLog(@"I am doing a tough job!");
// The commented line works. But it gets a synchronous notification.
// [[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification: [NSNotification notificationWithName:@"Done"
object:self] postingStyle:NSPostNow];
// The notification does NOT work.
[[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification: [NSNotification notificationWithName:@"Done"
object:self] postingStyle:NSPostWhenIdle];
NSLog(@"I need to leave!");
}


A delegate, MonitorDelegate, is implemented as follows.


@class Monitor;

@protocol MonitorDelegate

@optional
- (void) IHaveDone: (Monitor *) app;

@end



An object, Monitor, is implemented. Through it, other code can be notified
asynchronously.

@implementation Monitor

@synthesize delegate;

- (void) IHaveDone: (NSNotification *) notification
{
NSLog(@"OK");
if ([self.delegate respondsToSelector:@selector(IHaveDone:)])
{
[self.delegate IHaveDone:self];
}
}

- (void) setUpNotification: (NSString *) notification withSelector:
(SEL) methodName
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:methodName name:notification object:nil];
}

- (void) registerNotifications
{
[self setUpNotification:@"Done" withSelector:@selector(IHaveDone:)];
}

- (id) init
{
if (self = [super init])
{
[self registerNotifications];
}
return self;
}

@end

An application, AppController, which is interested in the asynchronous
notification, is as follows. I put sleep(5) deliberately to test if the
asynchronous notification works.

@implementation AppController

@synthesize monitor;

- (void) IHaveDone:(Monitor *)app
{
NSLog(@"I know you have done!");
sleep(5);
NSLog(@"You are a good guy!");
}

- (void) sayHi
{
NSLog(@"Hi");
}

- (id) init
{
self.monitor = [[Monitor alloc] init];
self.monitor.delegate = self;
[self.monitor.delegate sayHi];
return self;
}

@end

A main code is implemented to start the test. I put a console input into the
code to avoid the asynchronous notification being terminated.


NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

WorkingApp *app = [[WorkingApp alloc] init];
AppController *controller = [[AppController alloc] init];

[app Print];

char s[100];
scanf("%s", s);

[app release];
[controller release];
[pool drain];
return 0;

___

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

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

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

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


Re: RunLoop Tutorials

2011-05-16 Thread Gary L. Wade
Read this and use the examples referenced at the bottom of each method
description:




On 05/16/2011 1:07 PM, "Bing Li"  wrote:

>Dear Alex and Matt,
>
>Since I need to implement a peer-to-peer TCP model, I think the system
>level
>programming is required.
>
>Unfortunately, I have got any books giving enough explanations to RunLoop.
>Most books even never talk about it.
>
>Apple provides a document. However, the sample code is not complete. I
>cannot understand well. RunLoop code looks weird.
>
>I am not sure if you have some better resources for me to follow?
>
>Best,
>Bing
>
>On Tue, May 17, 2011 at 3:44 AM, Alex Kac  wrote:
>
>> To be fair, a new Cocoa developer doesn't need to worry about runloops.
>> Cocoa handles all that for you in most cases. Its good to understand
>>when
>> you understand all the rest of the basics, but its like learning how to
>> drive a car and asking about the specifics of drivetrain operation.
>>
>> On May 16, 2011, at 2:32 PM, Matt Neuburg wrote:
>>
>> > On Mon, 16 May 2011 21:31:18 +0800, Bing Li  said:
>> >>
>> >> although I have
>> >> got to know the term, RunLoop, when starting to learn Cocoa for two
>> months,
>> >> until now I have not seen a sample code about RunLoop in any
>>resources.
>> So I
>> >> don't know how to program with it.
>> >>
>> >
>> > When I search on NSRunLoop in Xcode, I get 50 or 60 sample code
>>projects.
>> I'm not saying that all of these would show you what you want to know
>>(most
>> of them are about adding a timer or a stream), but to claim that there
>>is
>> *no* sample code involving run loops seems a bit over the top. m.
>> >
>> > --
>> > matt neuburg, phd = m...@tidbits.com, 
>> > A fool + a tool + an autorelease pool = cool!
>> > Programming iOS 4!
>> >
>> 
>>http://www.apeth.net/matt/default.html#iosbook___
>>
>> >
>> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> >
>> > Please do not post 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/alex%40webis.net
>> >
>> > This email sent to a...@webis.net
>>
>> Alex Kac - President and Founder
>> Web Information Solutions, Inc.
>>
>> "Patience is the companion of wisdom."
>> --Anonymous
>>
>>
>>
>>
>>
>___
>
>Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
>Please do not post 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/garywade%40desisoftsystem
>s.com
>
>This email sent to garyw...@desisoftsystems.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: RunLoop Tutorials

2011-05-16 Thread Bing Li
In fact, I have rich experiences in Java and .NET. I use them to program a
lot of low level distributed systems.

However, I noticed that a lot of my past experiences could not be reused
when programming with Cocoa.

On Tue, May 17, 2011 at 4:13 AM, Alex Kac  wrote:

> There are tons of docs on runloops. Check out NSRunLoop and CFRunLoop. But
> still, if you use a good framework, you really don't need to deal with them
> directly much. For example, GCDAsyncSocket is a great network class (there
> are many others) that handle a lot of this for you. Most of the tutorials on
> Cocoa networking classes tell you what little you really need to know.
> Again, its good to understand them, but it sounds like you're asking to run
> before you can walk.
>
> I did a Google search and found tons of info:
>
> http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html
> http://www.mikeash.com/pyblog/friday-qa-2010-01-01-nsrunloop-internals.html
> http://www.cocoadev.com/index.pl?RunLoop
>
>
> On May 16, 2011, at 3:07 PM, Bing Li wrote:
>
> Dear Alex and Matt,
>
> Since I need to implement a peer-to-peer TCP model, I think the system
> level programming is required.
>
> Unfortunately, I have got any books giving enough explanations to RunLoop.
> Most books even never talk about it.
>
> Apple provides a document. However, the sample code is not complete. I
> cannot understand well. RunLoop code looks weird.
>
> I am not sure if you have some better resources for me to follow?
>
> Best,
> Bing
>
> On Tue, May 17, 2011 at 3:44 AM, Alex Kac  wrote:
>
>> To be fair, a new Cocoa developer doesn't need to worry about runloops.
>> Cocoa handles all that for you in most cases. Its good to understand when
>> you understand all the rest of the basics, but its like learning how to
>> drive a car and asking about the specifics of drivetrain operation.
>>
>> On May 16, 2011, at 2:32 PM, Matt Neuburg wrote:
>>
>> > On Mon, 16 May 2011 21:31:18 +0800, Bing Li  said:
>> >>
>> >> although I have
>> >> got to know the term, RunLoop, when starting to learn Cocoa for two
>> months,
>> >> until now I have not seen a sample code about RunLoop in any resources.
>> So I
>> >> don't know how to program with it.
>> >>
>> >
>> > When I search on NSRunLoop in Xcode, I get 50 or 60 sample code
>> projects. I'm not saying that all of these would show you what you want to
>> know (most of them are about adding a timer or a stream), but to claim that
>> there is *no* sample code involving run loops seems a bit over the top. m.
>> >
>> > --
>> > matt neuburg, phd = m...@tidbits.com, 
>> > A fool + a tool + an autorelease pool = cool!
>> > Programming iOS 4!
>> >
>> http://www.apeth.net/matt/default.html#iosbook___
>> >
>> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> >
>> > Please do not post 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/alex%40webis.net
>> >
>> > This email sent to a...@webis.net
>>
>> Alex Kac - President and Founder
>> Web Information Solutions, Inc.
>>
>> "Patience is the companion of wisdom."
>> --Anonymous
>>
>>
>>
>>
>>
>
> *Alex Kac - **President and Founder*
> *Web Information Solutions, Inc. *
>
> "If at first you don't succeed, skydiving is not for you."
>
> -- Francis Roberts
>
>
>
>
>
>
___

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

Please do not post 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: RunLoop Tutorials

2011-05-16 Thread Alex Kac
There are tons of docs on runloops. Check out NSRunLoop and CFRunLoop. But 
still, if you use a good framework, you really don't need to deal with them 
directly much. For example, GCDAsyncSocket is a great network class (there are 
many others) that handle a lot of this for you. Most of the tutorials on Cocoa 
networking classes tell you what little you really need to know. Again, its 
good to understand them, but it sounds like you're asking to run before you can 
walk.

I did a Google search and found tons of info:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html
http://www.mikeash.com/pyblog/friday-qa-2010-01-01-nsrunloop-internals.html
http://www.cocoadev.com/index.pl?RunLoop


On May 16, 2011, at 3:07 PM, Bing Li wrote:

> Dear Alex and Matt,
> 
> Since I need to implement a peer-to-peer TCP model, I think the system level 
> programming is required.
> 
> Unfortunately, I have got any books giving enough explanations to RunLoop. 
> Most books even never talk about it.
> 
> Apple provides a document. However, the sample code is not complete. I cannot 
> understand well. RunLoop code looks weird.
> 
> I am not sure if you have some better resources for me to follow?
> 
> Best,
> Bing
> 
> On Tue, May 17, 2011 at 3:44 AM, Alex Kac  wrote:
> To be fair, a new Cocoa developer doesn't need to worry about runloops. Cocoa 
> handles all that for you in most cases. Its good to understand when you 
> understand all the rest of the basics, but its like learning how to drive a 
> car and asking about the specifics of drivetrain operation.
> 
> On May 16, 2011, at 2:32 PM, Matt Neuburg wrote:
> 
> > On Mon, 16 May 2011 21:31:18 +0800, Bing Li  said:
> >>
> >> although I have
> >> got to know the term, RunLoop, when starting to learn Cocoa for two months,
> >> until now I have not seen a sample code about RunLoop in any resources. So 
> >> I
> >> don't know how to program with it.
> >>
> >
> > When I search on NSRunLoop in Xcode, I get 50 or 60 sample code projects. 
> > I'm not saying that all of these would show you what you want to know (most 
> > of them are about adding a timer or a stream), but to claim that there is 
> > *no* sample code involving run loops seems a bit over the top. m.
> >
> > --
> > matt neuburg, phd = m...@tidbits.com, 
> > A fool + a tool + an autorelease pool = cool!
> > Programming iOS 4!
> > http://www.apeth.net/matt/default.html#iosbook___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post 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/alex%40webis.net
> >
> > This email sent to a...@webis.net
> 
> Alex Kac - President and Founder
> Web Information Solutions, Inc.
> 
> "Patience is the companion of wisdom."
> --Anonymous
> 
> 
> 
> 
> 

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

"If at first you don't succeed, skydiving is not for you."
-- Francis Roberts





___

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

Please do not post 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


RunLoop Tutorials

2011-05-16 Thread Bing Li
Dear Alex and Matt,

Since I need to implement a peer-to-peer TCP model, I think the system level
programming is required.

Unfortunately, I have got any books giving enough explanations to RunLoop.
Most books even never talk about it.

Apple provides a document. However, the sample code is not complete. I
cannot understand well. RunLoop code looks weird.

I am not sure if you have some better resources for me to follow?

Best,
Bing

On Tue, May 17, 2011 at 3:44 AM, Alex Kac  wrote:

> To be fair, a new Cocoa developer doesn't need to worry about runloops.
> Cocoa handles all that for you in most cases. Its good to understand when
> you understand all the rest of the basics, but its like learning how to
> drive a car and asking about the specifics of drivetrain operation.
>
> On May 16, 2011, at 2:32 PM, Matt Neuburg wrote:
>
> > On Mon, 16 May 2011 21:31:18 +0800, Bing Li  said:
> >>
> >> although I have
> >> got to know the term, RunLoop, when starting to learn Cocoa for two
> months,
> >> until now I have not seen a sample code about RunLoop in any resources.
> So I
> >> don't know how to program with it.
> >>
> >
> > When I search on NSRunLoop in Xcode, I get 50 or 60 sample code projects.
> I'm not saying that all of these would show you what you want to know (most
> of them are about adding a timer or a stream), but to claim that there is
> *no* sample code involving run loops seems a bit over the top. m.
> >
> > --
> > matt neuburg, phd = m...@tidbits.com, 
> > A fool + a tool + an autorelease pool = cool!
> > Programming iOS 4!
> >
> http://www.apeth.net/matt/default.html#iosbook___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > Please do not post 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/alex%40webis.net
> >
> > This email sent to a...@webis.net
>
> Alex Kac - President and Founder
> Web Information Solutions, Inc.
>
> "Patience is the companion of wisdom."
> --Anonymous
>
>
>
>
>
___

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

Please do not post 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: Delegate & Notification

2011-05-16 Thread Alex Kac
To be fair, a new Cocoa developer doesn't need to worry about runloops. Cocoa 
handles all that for you in most cases. Its good to understand when you 
understand all the rest of the basics, but its like learning how to drive a car 
and asking about the specifics of drivetrain operation.

On May 16, 2011, at 2:32 PM, Matt Neuburg wrote:

> On Mon, 16 May 2011 21:31:18 +0800, Bing Li  said:
>> 
>> although I have
>> got to know the term, RunLoop, when starting to learn Cocoa for two months,
>> until now I have not seen a sample code about RunLoop in any resources. So I
>> don't know how to program with it.
>> 
> 
> When I search on NSRunLoop in Xcode, I get 50 or 60 sample code projects. I'm 
> not saying that all of these would show you what you want to know (most of 
> them are about adding a timer or a stream), but to claim that there is *no* 
> sample code involving run loops seems a bit over the top. m.
> 
> --
> matt neuburg, phd = m...@tidbits.com, 
> A fool + a tool + an autorelease pool = cool!
> Programming iOS 4!
> http://www.apeth.net/matt/default.html#iosbook___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post 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/alex%40webis.net
> 
> This email sent to a...@webis.net

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

"Patience is the companion of wisdom."
--Anonymous




___

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

Please do not post 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: Delegate & Notification

2011-05-16 Thread Matt Neuburg
On Mon, 16 May 2011 21:31:18 +0800, Bing Li  said:
>
> although I have
>got to know the term, RunLoop, when starting to learn Cocoa for two months,
>until now I have not seen a sample code about RunLoop in any resources. So I
>don't know how to program with it.
>

When I search on NSRunLoop in Xcode, I get 50 or 60 sample code projects. I'm 
not saying that all of these would show you what you want to know (most of them 
are about adding a timer or a stream), but to claim that there is *no* sample 
code involving run loops seems a bit over the top. m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

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

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

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

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


Re: Core Animation animations stop prematurely at random

2011-05-16 Thread Matt Neuburg
On Mon, 16 May 2011 08:11:36 -0400, Bill Cheeseman  said:
>My Mac OS X application has an borderless transparent overlay window with a 
>layer-hosting view. The view's layers add a bunch of animations in response to 
>a hot key. It all works correctly -- sometimes.
>
>What could account for sublayer animations prematurely stopping on random 
>application launches? I've tested everything I can think of.

Can you boil the problem down to minimal code and show it? I'm wondering 
whether you're accidentally removing the animation by adding another animation 
with the same key, for example; but that's a totally wild guess based on 
nothing (because there's nothing in your question to base it on)... m.

--
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

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

Please do not post 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: No more .ibplugins in Xcode 4, so now what...?

2011-05-16 Thread Scott Ribe
On May 16, 2011, at 8:04 AM, Roland King wrote:

> ...instead of having to drag on a generic class and then copy/paste 
> boilerplate code to make it work.

That is much more like most "code generator" style interface editors, and thus 
greatly reduces the unique advantage of the IB style of interface editing. I 
hope the right people at Apple realize what a step backward it is.

-- 
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: NSLayoutManager didCompleteLayout callback & NSFormFeedCharacter

2011-05-16 Thread Ross Carter
In my opinion, using layoutManager:didCompleteLayoutForTextContainer:atEnd is 
fraught with danger and should be avoided. Most of the time, it does not not 
provide truly useful information and you cannot rely on layout being complete 
even if the flag is YES.

If you open a new page-wrapped document in Text Edit and type returns until a 
second page is added, then press delete, the added page is not removed. Type 
any character, and the page is removed. That is because the method in question 
did not fire in response to the delete key.

I think it is far safer and more reliable to count the number of text 
containers by calling a method after every event that could affect layout, 
using the performSelector:withObject:afterDelay: wrapper to insure that layout 
is complete. Depending on your needs, it might be sufficient to override 
NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:.
 


On May 9, 2011, at 3:36 PM, Philip Dow wrote:

> I just submitted the following bug report and wanted to post it here as well 
> to see if anyone had a recommended workaround.
> 
> NSLayoutManager layoutManager:didCompleteLayoutForTextContainer:atEnd 
> callback is never called with atEnd flag set to YES if last character of text 
> is NSFormFeedCharacter.
> 
> Summary:
> The NSLayoutManager callback 
> layoutManager:didCompleteLayoutForTextContainer:atEnd: is called as layout is 
> completed for each text container in a multipage view. The atEnd flag is set 
> to YES when the last text container is layed out. This method is never called 
> with the atEnd flag set to YES if the last character in the text is the page 
> break (NSFormFeedCharacter) control character.
> 
> This is verifiable on Mac OS 10.6.7 through testing with TextEdit source code 
> that is included in the Xcode distro.
> 
> Steps to Reproduce:
> Create a multipage text document in TextEdit with text wrapping enabled. Add 
> a page break as the last character in the document and save the document. 
> Next time the document is opened, the layout manager callback never occurs 
> with the atEnd flag set to YES.
> 
> Expected Results:
> When the last container is layed out, the atEnd flag should be set to YES.
> 
> Actual Results:
> The didCompleteLayoutForTextContainer is correctly called a number of times 
> for each text container with the atEnd flag set to NO, but it is never 
> finally called with the atEnd flag set to YES for the last text container.
> 
> ~
> 
> I'm hoping someone might have some insight into this or a possible 
> workaround. I have some code that depends on a correct count of the number of 
> layed out pages and that count is determined when layout is completed, as 
> indicated by the atEnd flag set to YES.
> 
> ~Phil___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post 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/rosscarterdev%40me.com
> 
> This email sent to rosscarter...@me.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: Why RunLoop?

2011-05-16 Thread Kyle Sluder
On Mon, May 16, 2011 at 8:07 AM, Bing Li  wrote:
> Dear all,
>
> I am a new programmer of Cocoa. When learning RunLoop, I felt a little bit
> weird. Why should Cocoa provide such a technique? When programming on other
> environments, a while-true loop and wait/pulse lock can be used to achieve
> the same goal of RunLoop, right?

Yes, but Cocoa is a framework, not a library. Older APIs (Win32 and
classic Mac OS Carbon) required you to write your own busy loop and
call into the library to get new events to process. Cocoa inverts this
responsibility: your app lives within the framework, not vice versa.

> I notice that Cocoa threading can be programmed in the similar way. May I
> ignore RunLoop?

No. Every thread has at most one runloop, and the main thread must be
processing its runloop in order for your app to function. The
framework requires it.

--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: NSPostWhenIdle not doing its job?

2011-05-16 Thread Jonathan Taylor
Thanks again for your replies. I tried your various suggestions and they did 
not directly solve the problem, but trying them out gave me a lot more clues to 
help understand what was going wrong. It was in fact your mention of 
setNeedsDisplay that prompted me to look at the actual low-priority drawing 
code that I was using. The underlying problem turned out to be in some old 
drawing code that I wrote when I was first learning cocoa and had not touched 
since! It had not even occurred to me that that could be at the root of the 
problem.

I was locking and unlocking around a call to [NSImageView setImage], which I am 
pretty certain is unnecessary. This was presumably more than just inefficient - 
I suspect it was causing a bottleneck in the GUI update code when the code 
blocked on the "lock" call, and because this code was blocked there genuinely 
*were* spare CPU cycles available. It may be for this reason that many of the 
deprioritizing strategies I tried weren't very effective (possibly combined 
with the issues you were describing with exactly how the scheduler works).

So anyway, it may not come as a huge surprise to you that the underlying 
problem turned out to involve some code that I had NOT mentioned in my original 
email! It's great to have got to the bottom of the problem, anyway!

Jonny___

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

Please do not post 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: Why RunLoop?

2011-05-16 Thread Ken Thomases
On May 16, 2011, at 10:25 AM, Nick Zitzmann wrote:

> On May 16, 2011, at 9:07 AM, Bing Li wrote:
> 
>> I am a new programmer of Cocoa. When learning RunLoop, I felt a little bit
>> weird. Why should Cocoa provide such a technique? When programming on other
>> environments, a while-true loop and wait/pulse lock can be used to achieve
>> the same goal of RunLoop, right?
> 
> Well, yes, pre-Carbon Classic Mac OS forced programmers to write their own 
> run loops by polling for events, but why do that when there's code already 
> written for you?
> 
>> I notice that Cocoa threading can be programmed in the similar way. May I
>> ignore RunLoop?
> 
> Only if you're doing some task that will start and exit, and doesn't have to 
> handle events or timers or notifications. Otherwise, you need a run loop. 
> NSApplication and UIApplication will run the main thread's run loop 
> automatically. But if you, for instance, attach a timer to the run loop of 
> another thread, then you need to run that thread's run loop or the timer will 
> not trigger.

And this, in part, illustrates the "why" of run loops: the frameworks may 
install their own run loop sources into the main run loop.  The way that run 
loops are implemented means that the specific code to handle an input source's 
"readiness" is encapsulated with the run loop source itself, not in the client 
code.  So, the frameworks don't have to rely on the client code doing the right 
thing with their various different input sources.

In other words, a run loop can support a wide variety of different kinds of 
input sources without requiring client code to be updated to handle the new 
kinds of input.  And, so long as the client code does run the run loop, the 
client can't mess up and fail to do something that the frameworks need to have 
done.

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: NSPostWhenIdle not doing its job?

2011-05-16 Thread Ken Thomases
On May 16, 2011, at 4:50 AM, Jonathan Taylor wrote:

> Thanks very much for your reply Ken, very helpful indeed.

You're welcome.


>> Still, that won't help if Function B is not being called as often as you 
>> expect because NSPostASAP doesn't work like you thought.  I suspect that it 
>> is only being called when something else tickles the run loop, like user 
>> events.  I wonder if you click-and-hold in your window (not necessarily on a 
>> button or any active control) and just keep dragging the mouse back and 
>> forth, if that helps keep the backlog clear.  (Simple mouse moves without 
>> the mouse button don't send events unless your window has specifically 
>> subscribed to them using NSTrackingArea or -setAcceptsMouseMovedEvents:.)
> I've got to be honest, I was very skeptical of this but that is indeed 
> exactly what happens. Bizarre! I wonder if this then suggests a workaround 
> (admittedly a hideous one) of manually posting "user" events to the main 
> loop!?

Well, it's not so hideous and it wouldn't necessarily be simulating user events 
(mouse clicks, key presses, or the like).  NSEvent supports application-defined 
events, which you can use for this purpose.  The -postEvent:atStart: method is 
even safe to call from background threads; the posted events are still received 
on the main thread.


> - I am not aware of a way of running code *on*the*main*thread* at low 
> priority (i.e. will not run unless there are "spare" cycles). While GCD has a 
> concept of low priority queues this applies to custom queues, not the main 
> thread where GUI-related code must (I think...) run.

Well, you can submit a block to a low-priority queue whose only work is to 
submit a block to the main queue:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 
NULL), ^{
dispatch_async(dispatch_get_main_queue(), ^{
// Do some work
});
});

This doesn't do coalescing for you, but you can handle that manually.  Or, if 
you're only going to do something like -setNeedsDisplay:, that's coalescing by 
nature.


> It would not be too hard for me to write my own scheduler which could 
> prioritize the "important" work over the GUI updates, but this really does 
> seem like it shouldn't be necessary! This feels like a fairly common problem 
> to me, so I can't help feeling there must be a standard solution in the cocoa 
> APIs that I am missing...

I think the usual is to just set views as needing display when they do, and the 
framework and the Window Server will effectively throttle the update frame 
rate.  That is, I don't think there's such a thing as calling -setNeedsDisplay: 
"too frequently".  You just call it when the view is out-of-date with respect 
to internal state and let things take care of themselves.  On the other hand, 
that does assume that redrawing your view is kept as inexpensive as possible.  
You shouldn't be doing much computation or hard work in -drawRect:.

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: Why RunLoop?

2011-05-16 Thread Nick Zitzmann

On May 16, 2011, at 9:07 AM, Bing Li wrote:

> Dear all,
> 
> I am a new programmer of Cocoa. When learning RunLoop, I felt a little bit
> weird. Why should Cocoa provide such a technique? When programming on other
> environments, a while-true loop and wait/pulse lock can be used to achieve
> the same goal of RunLoop, right?

Well, yes, pre-Carbon Classic Mac OS forced programmers to write their own run 
loops by polling for events, but why do that when there's code already written 
for you?

> I notice that Cocoa threading can be programmed in the similar way. May I
> ignore RunLoop?

Only if you're doing some task that will start and exit, and doesn't have to 
handle events or timers or notifications. Otherwise, you need a run loop. 
NSApplication and UIApplication will run the main thread's run loop 
automatically. But if you, for instance, attach a timer to the run loop of 
another thread, then you need to run that thread's run loop or the timer will 
not trigger.

Nick Zitzmann


___

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

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

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

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


Why RunLoop?

2011-05-16 Thread Bing Li
Dear all,

I am a new programmer of Cocoa. When learning RunLoop, I felt a little bit
weird. Why should Cocoa provide such a technique? When programming on other
environments, a while-true loop and wait/pulse lock can be used to achieve
the same goal of RunLoop, right?

I notice that Cocoa threading can be programmed in the similar way. May I
ignore RunLoop?

Thanks so much!
Bing
___

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

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

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

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


Question regarding GameKit

2011-05-16 Thread Eric E. Dolecki
I have 2 iOS devices and I would like one of them to send data to the other
(1-way really). When I put the same app on the two iOS devices & used
GameKit, things worked great.



Recently I made a second app in the hopes to have it send data to the 1st
iOS device. I used the exact same GK code and I get this every time I try to
connect with the 2nd app:

BTM: attaching to BTServer
<<< Session >>> +[GKBluetoothSupport _determineBluetoothStatus]: BT
not available - try again later.
BTM: posting notification BluetoothAvailabilityChangedNotification



I don't know why when I try to connect with the second device (launch the
app on 2nd device 1st and hit a connect button) it won't work. This is how I
am invoking the picker:

-(IBAction) btnConnect:(id) sender {
picker = [[GKPeerPickerController alloc] init];
picker.delegate = self;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[connect setHidden:YES];
[disconnect setHidden:NO];
[picker show];
}

- (void)peerPickerController:(GKPeerPickerController *)picker
  didConnectPeer:(NSString *)peerID
   toSession:(GKSession *) session {
self.currentSession = session;
session.delegate = self;
[session setDataReceiveHandler:self withContext:nil];
picker.delegate = nil;
[picker dismiss];
[picker autorelease];
}

- (void)session:(GKSession *)session
   peer:(NSString *)peerID
 didChangeState:(GKPeerConnectionState)state {
switch (state)
{
case GKPeerStateConnected:
NSLog(@"connected");
break;
case GKPeerStateDisconnected:
NSLog(@"disconnected");
[self.currentSession release];
currentSession = nil;
[connect setHidden:NO];
[disconnect setHidden:YES];
break;
case GKPeerStateAvailable:
case GKPeerStateConnecting:
case GKPeerStateUnavailable:
break;
}
}



That's problem one. It doesn't seem to matter what iOS device (touch/iPhone)
I put it on, I get that weird BT not available in the console.



Problem two... since the apps are different and will have different ids,
does anything special need to be done to get them to communicate over BT?
___

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

Please do not post 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: Delegate & Notification

2011-05-16 Thread Michael Babin
On May 16, 2011, at 8:31 AM, Bing Li wrote:

> You are right. There is no RunLoop in the code. Actually, although I have got 
> to know the term, RunLoop, when starting to learn Cocoa for two months, until 
> now I have not seen a sample code about RunLoop in any resources. So I don't 
> know how to program with it.
> 
> I have one question. If I put the synchronous notification posts into a 
> NSOperationQueue, it must also get asynchronous notification, right? Is the 
> solution proper?

If you don't understand run loops (what they are, how they work, under what 
circumstances they are created and run for you, when you need to explicitly run 
them yourself), then you need to spend some time learning about them, 
especially before departing from the standard Cocoa application template. I 
wouldn't worry about more advanced topics like NSOperation or NSOperationQueue 
until mastering a bit more of the basics.

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html%23//apple_ref/doc/uid/1057i-CH16-SW1

http://www.mikeash.com/pyblog/friday-qa-2010-01-01-nsrunloop-internals.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: No more .ibplugins in Xcode 4, so now what...?

2011-05-16 Thread Roland King

On 16-May-2011, at 9:50 PM, Alexander Zvyagin wrote:

>> Thanks for the clarification.  But the developer still had to transition
>> _his code_ from non-GC to either 1) GC-only and drop 32 bit (likely not
>> desirable) or 2) dual mode.
> 
>> I think most developers would have accepted a loss of _binary_
>> compatibility of their ibplugins, after all the target users of
>> ibplugins are developers themselves.  Refactoring to support dual mode
>> and rebuilding would not be a big burden.
> 
>> (In my case, my code is GC-only and 64 bit only.  I had to go backwards
>> and make it support non-GC to get my ibplugin working.)
> In my case, ibplugins are fully custom animated controls used from inside IB 
> to safe coding time, and only one
> application source and bundle must be compatible with three OSX versions at 
> the same time: 10.5 + 10.6 + 10.7
> 
> There are typical requirements for developers making big projects instead of 
> home maded iPhone games.


Very good. Some of us writing homemade iPhone games would also rather 
appreciate the ability to make plugins too, we would have appreciated it in 
XCode 3.x and we'd (well I would) still appreciate it in 4.x too. I have some 
standard controls I've written which I'd really prefer to be able to set up in 
IB instead of having to drag on a generic class and then copy/paste boilerplate 
code to make it work. If you haven't filed a bug report against XCode 4, please 
do so, I filed one against 3 for iOS plugins and one against 4 for plugins in 
general. I wait expectantly. ___

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

Please do not post 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: No more .ibplugins in Xcode 4, so now what...?

2011-05-16 Thread Alexander Zvyagin
> Thanks for the clarification.  But the developer still had to transition
> _his code_ from non-GC to either 1) GC-only and drop 32 bit (likely not
> desirable) or 2) dual mode.

> I think most developers would have accepted a loss of _binary_
> compatibility of their ibplugins, after all the target users of
> ibplugins are developers themselves.  Refactoring to support dual mode
> and rebuilding would not be a big burden.

> (In my case, my code is GC-only and 64 bit only.  I had to go backwards
> and make it support non-GC to get my ibplugin working.)
In my case, ibplugins are fully custom animated controls used from inside IB to 
safe coding time, and only one
application source and bundle must be compatible with three OSX versions at the 
same time: 10.5 + 10.6 + 10.7

There are typical requirements for developers making big projects instead of 
home maded iPhone games.

___

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

Please do not post 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: Delegate & Notification

2011-05-16 Thread Bing Li
Dear Michael,

You are right. There is no RunLoop in the code. Actually, although I have
got to know the term, RunLoop, when starting to learn Cocoa for two months,
until now I have not seen a sample code about RunLoop in any resources. So I
don't know how to program with it.

I have one question. If I put the synchronous notification posts into a
NSOperationQueue, it must also get asynchronous notification, right? Is the
solution proper?

Best regards,
Bing

On Mon, May 16, 2011 at 7:01 PM, Michael Babin  wrote:

> On May 16, 2011, at 3:49 AM, Bing Li wrote:
>
> - (void) Print
> {
> NSLog(@"I am doing a tough job!");
> //  [[[NSNotificationQueue alloc]
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
> enqueueNotification: [NSNotification notificationWithName:@"Done"
> object:self] postingStyle:NSPostNow]; // This is also sychronous.
> [[[NSNotificationQueue alloc]
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
> enqueueNotification: [NSNotification notificationWithName:@"Done"
> object:self] postingStyle:NSPostWhenIdle];
> NSLog(@"I need to leave!");
> }
>
> The commented line is the same as a synchronous notification. It works. But
> the later line must be an asynchronous notification. However, the
> AppController does not get notified. I don't understand what's wrong with
> the code.
>
>
> There is another current thread on this list ("NSPostWhenIdle not doing its
> job") which is also discussing NSNotificationQueue and how it works. You
> might refer to it for more information, including a link to one of Mike
> Ash's Friday Q&A blog entries on NSNotificationQueue:
> http://www.mikeash.com/pyblog/friday-qa-2010-01-08-nsnotificationqueue.html
> .
>
> Since NSPostWhenIdle posts the event when the run loop is idle, the first
> question would be: do you have a runloop? Your original post included the
> following:
>
> In the main code, the above objects are utilized as follows.
>
>WorkingApp *app = [[WorkingApp alloc] init];
>AppController *controller = [[AppController alloc] init];
>
>[app Print];
>
>char s[100];
>scanf("%s", s);
>[app release];
>[controller release];
>
>
> Which seems to indicate that you don't have a runloop in your sample code.
>
>
>
___

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

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

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

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


Core Animation animations stop prematurely at random

2011-05-16 Thread Bill Cheeseman
My Mac OS X application has an borderless transparent overlay window with a 
layer-hosting view. The view's layers add a bunch of animations in response to 
a hot key. It all works correctly -- sometimes.

When I quit and relaunch the application, the animations sometimes don't run 
for the full specified duration when I hit the hot key. During any given run of 
the application, the animations either work correctly every time I hit the hot 
key, or they stop prematurely every time I hit the hot key.

Whether a given launch yields good animations or bad animations is apparently 
random. All of the animations in sublayers always start running correctly in 
both good and bad launches, but in a bad launch they then instantly stop 
running (after 1 millisecond instead of the specified half-second duration), as 
reported by the -animationDidStart: and -animationDidStop:finished: delegate 
methods. Except that the animation in the root layer always completes in the 
specified half-second duration even on a bad launch.

I am not calling -removeAllAnimations or -removeAnimationForKey: anywhere in 
the application.

What could account for sublayer animations prematurely stopping on random 
application launches? I've tested everything I can think of.

-- 

Bill Cheeseman - b...@cheeseman.name

___

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

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

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

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


Re: Delegate & Notification

2011-05-16 Thread Michael Babin
On May 16, 2011, at 3:49 AM, Bing Li wrote:

> - (void) Print
> {
> NSLog(@"I am doing a tough job!");
> //  [[[NSNotificationQueue alloc] 
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]] 
> enqueueNotification: [NSNotification notificationWithName:@"Done" 
> object:self] postingStyle:NSPostNow]; // This is also sychronous.
> [[[NSNotificationQueue alloc] 
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]] 
> enqueueNotification: [NSNotification notificationWithName:@"Done" 
> object:self] postingStyle:NSPostWhenIdle];
> NSLog(@"I need to leave!");
> }
> 
> The commented line is the same as a synchronous notification. It works. But 
> the later line must be an asynchronous notification. However, the 
> AppController does not get notified. I don't understand what's wrong with the 
> code.

There is another current thread on this list ("NSPostWhenIdle not doing its 
job") which is also discussing NSNotificationQueue and how it works. You might 
refer to it for more information, including a link to one of Mike Ash's Friday 
Q&A blog entries on NSNotificationQueue: 
http://www.mikeash.com/pyblog/friday-qa-2010-01-08-nsnotificationqueue.html.

Since NSPostWhenIdle posts the event when the run loop is idle, the first 
question would be: do you have a runloop? Your original post included the 
following:

> In the main code, the above objects are utilized as follows.
> 
>WorkingApp *app = [[WorkingApp alloc] init];
>AppController *controller = [[AppController alloc] init];
> 
>[app Print];
> 
>char s[100];
>scanf("%s", s);
>[app release];
>[controller release];

Which seems to indicate that you don't have a runloop in your sample code.


___

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

Please do not post 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: NSPostWhenIdle not doing its job?

2011-05-16 Thread Jonathan Taylor
Thanks very much for your reply Ken, very helpful indeed.

>> The problem can be summarised as: in spite of having a backlog of 
>> notifications building up on the main thread, NSPostWhenIdle-qualified 
>> notifications do seem to be making it through. This is causing me problems 
>> because this idle work is swallowing up main thread time, making the backlog 
>> even worse! I am trying to understand why this is happening and whether I 
>> can do anything to alleviate the situation.
> 
> I suspect you have assumed things about NSPostWhenIdle and NSPostASAP which 
> just aren't true.  In particular, you think that the former is "prioritized" 
> lower than the latter.  However, they just indicate different points during a 
> run loop's execution when the notifications are delivered.
> 
> Notifications queued with NSPostWhenIdle are posted when the run loop is idle 
> -- when it would otherwise put the thread to sleep waiting for something to 
> happen.  Those queued with NSPostASAP are posted after an input source or 
> timer is serviced (when it's handling function or method returns).
> 
> If no input sources or timers are firing, then notifications posted with 
> NSPostASAP may not fire soon.  Unfortunately, operations being queued or run 
> in the main queue don't count, it would seem.  At least, I think that's 
> what's happening.

The (indirect) references I was working from were:

http://www.gnu.org/software/gnustep/resources/OpenStepSpec/FoundationKit/Classes/NSNotificationQueue.html
Admittedly not OS X, but presumably very closely related? Describes a usage 
scenario for NSPostWhenIdle that seems exactly analogous to mine.
http://www.mikeash.com/pyblog/friday-qa-2010-01-08-nsnotificationqueue.html
Again, describes an analogous situation in my view. The only difference in both 
cases to my situation is that their example scenarios are user-event driven, 
which may from what you say make a difference for some reason?


> You may also be running into this issue, somehow: 
> .  NSOperationQueue's 
> +mainQueue presumably uses dispatch_get_main_queue() under the hood.
Hmm. That's an interesting one - if I read it correctly there are some 
outstanding issues with the scheduler that might be relevant to what I'm doing.

> One obvious improvement to your scheme is, since Function C should not do 
> anything unless and until Function B has processed a new frame image, post 
> its notification (notification 2) from Function B, not Function A.  (Or 
> otherwise arrange for Function C to be triggered by Function B's completion.)
Hmm, well spotted!

> Still, that won't help if Function B is not being called as often as you 
> expect because NSPostASAP doesn't work like you thought.  I suspect that it 
> is only being called when something else tickles the run loop, like user 
> events.  I wonder if you click-and-hold in your window (not necessarily on a 
> button or any active control) and just keep dragging the mouse back and 
> forth, if that helps keep the backlog clear.  (Simple mouse moves without the 
> mouse button don't send events unless your window has specifically subscribed 
> to them using NSTrackingArea or -setAcceptsMouseMovedEvents:.)
I've got to be honest, I was very skeptical of this but that is indeed exactly 
what happens. Bizarre! I wonder if this then suggests a workaround (admittedly 
a hideous one) of manually posting "user" events to the main loop!?


I guess (as is so often the case!) I should also be asking the broader question 
- how can I achieve the result I want? I have CPU-intensive code that must keep 
up with the rate at which data is arriving, and I also have GUI-related code 
that it would be nice to execute if there are any spare cycles. My 
understanding is:

- Although I thought notifications were a nice tool to use for what I am doing, 
they don't seem to be designed for quite what I am using them for. No doubt 
somebody somewhere knows a good reason why the specific behaviour I am seeing 
was chosen!

- I am not aware of a way of running code *on*the*main*thread* at low priority 
(i.e. will not run unless there are "spare" cycles). While GCD has a concept of 
low priority queues this applies to custom queues, not the main thread where 
GUI-related code must (I think...) run.

It would not be too hard for me to write my own scheduler which could 
prioritize the "important" work over the GUI updates, but this really does seem 
like it shouldn't be necessary! This feels like a fairly common problem to me, 
so I can't help feeling there must be a standard solution in the cocoa APIs 
that I am missing...

Thanks again
Jonny___

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

Please do not post 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/op

Re: Why are properties access through NSURLProtocol class method rather than NSURLRequest instance method?

2011-05-16 Thread Mike Abdullah

On 16 May 2011, at 03:57, Larry Campbell wrote:

> Seems odd to me that setting and getting properties of an NSURLRequest 
> involve an NSURLProtocol class method:
> 
>+[NSURLProtocol setProperty:forKey:inRequest:]
> 
> rather than what seems to me the much more straightforward:
> 
>-[NSMutableURLRequest setProperty:forKey:]
> 
> Is there a reason for this?

This facility is provided for people creating custom URL protocols. I think 
it's assumed that if you need custom request properties, you'll write something 
like:

@implementation NSURLRequest (MyProtocol)
- (NSString *)myFoo;
{
  return [NSURLProtocol propertyForKey:@"myFoo" inRequest:self];
}
@end

@implementation NSMutableURLRequest (MyProtocol)
- (void)setMyFoo:(NSString *)foo
{
  if (foo)
  {
[NSURLProtocol setProperty:foo forKey:@"myFoo" inRequest:self];
  }
  else
  {
[NSURLProtocol removePropertyForKey:@"myFoo" inRequest:self];
  }
}

___

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

Please do not post 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: Delegate & Notification

2011-05-16 Thread Bing Li
Dear all,

Sorry to send the email again!

I forget mentioning that Monitor was also changed. The notification is
registered to defaultCenter instead of NSWorkspace notificationCenter.

Could you help me what's wrong with the asynchronous notification?

Thanks so much!
Bing


On Mon, May 16, 2011 at 4:49 PM, Bing Li  wrote:

> Dear Michael, Chase, Seth and all,
>
> I appreciate so much for your help! After changing the WorkingApp as
> follows, the notification works. One of the reasons I made such a mistake is
> that I could not get sufficient materials to learn the techniques although I
> have got more than 10 books about Cocoa. I hope Apple could improve on this.
>
> import "WorkingApp.h"
> @implementation WorkingApp
>
> - (void) Print
> {
> NSLog(@"I am doing a tough job!");
> [[NSNotificationCenter defaultCenter] postNotificationName:@"Done"
> object:self];
> }
> @end
>
> However, when trying to use asynchronous notification, I got problems
> again. Now WorkingApp is updated as follows.
>
> import "WorkingApp.h"
>
>@implementation WorkingApp
>
> - (void) Print
> {
> NSLog(@"I am doing a tough job!");
> //  [[[NSNotificationQueue alloc]
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
> enqueueNotification: [NSNotification notificationWithName:@"Done"
> object:self] postingStyle:NSPostNow]; // This is also sychronous.
> [[[NSNotificationQueue alloc]
> initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
> enqueueNotification: [NSNotification notificationWithName:@"Done"
> object:self] postingStyle:NSPostWhenIdle];
> NSLog(@"I need to leave!");
> }
>
> The commented line is the same as a synchronous notification. It works. But
> the later line must be an asynchronous notification. However, the
> AppController does not get notified. I don't understand what's wrong with
> the code.
>
> Could you give me some hints?
>
> Best regards,
> Bing
>
> @end
>
>
>
> On Mon, May 16, 2011 at 7:47 AM, Michael Babin wrote:
>
>> On May 15, 2011, at 5:31 PM, Bing Li wrote:
>>
>> An object, WorkingApp, prints a line and posts a notification as follows.
>>
>>import "WorkingApp.h"
>>
>>@implementation WorkingApp
>>
>>- (void) Print
>>{
>>NSLog(@"I am doing a tough job!");
>>[[NSNotificationCenter defaultCenter] postNotificationName:@"Done"
>> object:self];
>>}
>>
>>@end
>>
>>
>>
>>   - (void) setUpNotification: (NSString *) notification withSelector:
>> (SEL) methodName
>>{
>>[[[NSWorkspace sharedWorkspace] notificationCenter]
>> addObserver:self
>> selector:methodName name:notification object:nil];
>>}
>>
>>
>> Why are you adding the observer to NSWorkspace's notification center, as
>> opposed to NSNotificationCenter's default center (where you are posting the
>> notification)?
>>
>>
>>
>
___

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

Please do not post 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: Delegate & Notification

2011-05-16 Thread Bing Li
Dear Michael, Chase, Seth and all,

I appreciate so much for your help! After changing the WorkingApp as
follows, the notification works. One of the reasons I made such a mistake is
that I could not get sufficient materials to learn the techniques although I
have got more than 10 books about Cocoa. I hope Apple could improve on this.

import "WorkingApp.h"
@implementation WorkingApp

- (void) Print
{
NSLog(@"I am doing a tough job!");
[[NSNotificationCenter defaultCenter] postNotificationName:@"Done"
object:self];
}
@end

However, when trying to use asynchronous notification, I got problems again.
Now WorkingApp is updated as follows.

import "WorkingApp.h"

   @implementation WorkingApp

- (void) Print
{
NSLog(@"I am doing a tough job!");
//  [[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification: [NSNotification notificationWithName:@"Done"
object:self] postingStyle:NSPostNow]; // This is also sychronous.
[[[NSNotificationQueue alloc]
initWithNotificationCenter:[NSNotificationCenter defaultCenter]]
enqueueNotification: [NSNotification notificationWithName:@"Done"
object:self] postingStyle:NSPostWhenIdle];
NSLog(@"I need to leave!");
}

The commented line is the same as a synchronous notification. It works. But
the later line must be an asynchronous notification. However, the
AppController does not get notified. I don't understand what's wrong with
the code.

Could you give me some hints?

Best regards,
Bing

@end



On Mon, May 16, 2011 at 7:47 AM, Michael Babin  wrote:

> On May 15, 2011, at 5:31 PM, Bing Li wrote:
>
> An object, WorkingApp, prints a line and posts a notification as follows.
>
>import "WorkingApp.h"
>
>@implementation WorkingApp
>
>- (void) Print
>{
>NSLog(@"I am doing a tough job!");
>[[NSNotificationCenter defaultCenter] postNotificationName:@"Done"
> object:self];
>}
>
>@end
>
>
>
>   - (void) setUpNotification: (NSString *) notification withSelector:
> (SEL) methodName
>{
>[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
> selector:methodName name:notification object:nil];
>}
>
>
> Why are you adding the observer to NSWorkspace's notification center, as
> opposed to NSNotificationCenter's default center (where you are posting the
> notification)?
>
>
>
___

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

Please do not post 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