Re: NSXMLParser and character entities?

2008-09-14 Thread Nathan Kinsinger


On Sep 12, 2008, at 3:56 PM, Kai wrote:

When NSXMLParser hits a character entity like ä (-> German  
umlaut 'ä'), it sends parser:resolveExternalEntityName:systemID: to  
its delegate and if this is not implemented or returns nil,  
parser:parseErrorOccurred: is called with  
NSXMLParserUndeclaredEntityError.


Am I supposed to resolve all these character entities myself? And if  
so, what should the NSData object returned by  
parser:resolveExternalEntityName:systemID: contain? Unicode? Which  
Unicode encoding?


But this can’t be, can it? I must be missing something simple.

Thanks for any hints
Kai



The main problem is that entities like ä are defined by HTML and  
have nothing to do with XML or NSXMLParser.


I haven't dealt with this problem myself but I was curious so I tried  
a few things.




My first attempt was using NSAttributedString to convert the HTML  
entity to a UTF8 string.


- (NSData *)parser:(NSXMLParser *)parser resolveExternalEntityName: 
(NSString *)entityName systemID:(NSString *)systemID

{   
	NSAttributedString *entityString = [[[NSAttributedString alloc]  
initWithHTML:[[NSString stringWithFormat:@"&%@;", entityName]  
dataUsingEncoding:NSUTF8StringEncoding] documentAttributes:NULL]  
autorelease];


NSLog(@"resolved entity name: %@", [entityString string]);

return [[entityString string] dataUsingEncoding:NSUTF8StringEncoding];
}

This works, parser:foundCharacters: gets the ä but for some reason  
parser:parseErrorOccurred: is still being called with the same error  
you received: "Operation could not be completed.  
(NSXMLParserErrorDomain error 26.)"


The parser does continue and parse the file correctly (with the ä), it  
just makes it hard to tell when you have real errors. I'm really  
curious as to why this doesn't work (running 10.5.4 on Intel). And the  
fact that the parser keeps parsing after the error, when the  
documentation says it will stop, is odd too.




Another option is to add an XHTML DocType DTD to the file and set  
setShouldResolveExternalEntities: to YES (default is NO). This works  
with no errors because the DTD defines the entities.


However NSXMLParser will download the DTD (over the net) every time  
you parse a file. So you probably want to copy one of the DTD's (say http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd 
 ) locally. Although I didn't try it, you could copy the entity  
definitions into your own DTD to make the file smaller and parsing it  
faster.




Of course if the content really is XHTML you should really be using an  
HTML parser and not an XML one.


--Nathan


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: mailbundle info

2008-09-14 Thread Mark Munz
On Wed, Sep 10, 2008 at 3:00 PM, Stephane Huaulme
<[EMAIL PROTECTED]> wrote:
> where can i find info on how to create a mailbundle?
>

Log a bug/enhancement request with Apple via http://bugreport.apple.com

After 7+ years, it really is time for them to provide a public plug-in
API for Mail. The more developers that log enhancement requests, the
better chance Apple might finally take notice and provide a real
plug-in API instead features like "stationery", notes,  or "new icons"
for Mail.

Of course, I'm not holding my breath.

-- 
Mark Munz
unmarked software
http://www.unmarked.com/
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: mailbundle info

2008-09-14 Thread Kyle Sluder
On Sun, Sep 14, 2008 at 2:32 PM, Mark Munz <[EMAIL PROTECTED]> wrote:
> Log a bug/enhancement request with Apple via http://bugreport.apple.com

rdar://problem/6218715

Will probably be marked as duplicate, but it doesn't hurt.

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


NameAndPassword Sample Code

2008-09-14 Thread Patrick Neave

Hi List,

I am getting back into Cocoa after a 2-3 year break and diving  
straight in to the Security Frameworks. I had some help a couple of  
weeks ago from this list (thanks Charles :-)) when trying to get the  
bannersample example working and am hoping for the same again.


In looking at the Security Framework documentation and reading this  
list it seems that the SFAuthorizationPluginView provided with 10.5  
does exactly what I require, that is, add an extra field to the login  
screen. The sample code for this is called NameAndPassword but I  
cannot seem to get this working correctly.


Following the instructions the code is compiled and the resulting  
bundle installed in "/System/Library/CoreServices/ 
SecurityAgentPlugins/". I want to replace the login screen so I add a  
line to "/etc/authorization" to call the mechanism:  
NameAndPassword:invoke. This is placed just above the  
smartcard-sniffer entry.


I an invoke the mechanism either by using the Fast User Switching  
"Login Window..." menu option or running the AskForRight code fragment  
provided with the sample code in the readme.


Now the problem, the window is displayed but my password is never  
accepted, I have added a few strategically placed NSLogs and am sure  
that everything is correct but still no luck. After trying  
unsuccessfully, and hitting return a couple of times I am returned to  
the regular login window. So I guess the NameAndPassword UI is exiting  
and the next mechanism in "/etc/authorization" is run.


I have been through the code in an attempt to understand what is going  
on. There are two nib files, and which is used depends on whether the  
login window is displayed as a list of users or a name and password.  
There are lots of checks in the code to ensure that the correct nib is  
loaded, however, when enter or the login button is pressed we end up  
calling - (void)buttonPressed:(SFButtonType)inButtonType. This  
function gets the password from "mIPPasswordSecureTextField"  
regardless of the nib loaded, which looks like a bug to me as  
"mPPasswordSecureTextField" is the field used for the list of users  
login nib. So I tried changing the fields, but still the same problem.


Sorry for the long post, but I have been stuck on this for a while now  
and not sure how to proceed. Looking forward to your replies.



Regards,

Patrick



___

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

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

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

This email sent to [EMAIL PROTECTED]


NSOutlineView: Which row is selected.

2008-09-14 Thread John Cebasek

Hi All:

Noobie question follows:

I've got an NSOutlineView and am trying to determine which row is  
selected. I thought [super selectedRow]; (calling NSTableView's  
selectedRow method) would do the trick, but all I'm getting back from  
that call is -1.


How does one determine which row is selected in an outline view?

Thanks in advance for your time


John
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NameAndPassword Sample Code

2008-09-14 Thread Jason Coco


On Sep 14, 2008, at 16:30 , Patrick Neave wrote:


Sorry for the long post, but I have been stuck on this for a while  
now and not sure how to proceed. Looking forward to your replies.




Hi Patrick,

I haven't read this yet, so I'm not sure if it will be useful or not,  
but it may... assuming you have two computers that you can use, anyway.


HTH, J

http://developer.apple.com/technotes/tn2008/tn2108.html



smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: NSUInteger in for-loop?

2008-09-14 Thread Nathan Kinsinger

On Sep 14, 2008, at 10:15 PM, Alex Reynolds wrote:


NSLog(@"NSUInteger: %d", counter);



The correct type modifier for unsigned integers is %u not %d. Switch  
it and try again to see what's really happening.


--Nathan
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Alex Reynolds

The %lu with casting seems to run into the same issue as %u:

...
2008-09-14 21:43:07.241 NSUIntTest[19779:10b] NSUInteger: 2
2008-09-14 21:43:07.259 NSUIntTest[19779:10b] NSUInteger: 1
2008-09-14 21:43:07.260 NSUIntTest[19779:10b] NSUInteger: 0
2008-09-14 21:43:07.261 NSUIntTest[19779:10b] NSUInteger: 4294967295
2008-09-14 21:43:07.262 NSUIntTest[19779:10b] NSUInteger: 4294967294
...

Interesting.

-Alex

On Sep 14, 2008, at 9:38 PM, j o a r wrote:


NSUInteger runs from 0 -> NSUIntegerMax.

This is how you print a NSUInteger:

NSLog(@"NSUInteger: %lu", ((unsigned long)counter));

j o a r




___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Brett Powley


On 15/09/2008, at 2:15 PM, Alex Reynolds wrote:

I'm wondering if I'm using unsigned integers (specifically  
NSUInteger) properly or not.


I was under the impression that unsigned integers run from 0 to  
MAX_INT, but when I use them in a "for" loop within these bounds,  
the loop does not seem to always obey these constraints.


For example:

for (NSUInteger counter = 5; counter >= 0; --counter)
{
NSLog(@"NSUInteger: %d", counter);
}

keeps running well after the "counter" variable turns negative:


First problem:  %d is for signed integers; if you want to see the  
value, you want %u.
Second problem (which you'll see if you change the NSLog):  counter is  
unsigned, so it *never* "turns negative".


The values of counter in your loop will be 5,4,3,2,1,0,MAX_UINT,  
MAX_UINT-1, etc


(Note that the range of values for unsigned integers is 0..MAX_UINT,  
not MAX_INT.)


However, the following does *not* run, starting from a negative  
integer (as I would expect):


for (NSUInteger counter = -5; counter <= 0; ++counter)
{
NSLog(@"NSUInteger: %d", counter);
}


counter can't have a value of -5 because it's unsigned; the value you  
are getting here will be MAX_UINT-5.  And that's not <=0, so the loop  
invariant fails the first time.



Also, the following works properly:

for (NSUInteger counter = 0; counter <= 5; ++counter)
{
NSLog(@"NSUInteger: %d", counter);
}


That works properly because this time you're not assigning values that  
you think should be negative to an unsigned int.



___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Clark Cox
On Sun, Sep 14, 2008 at 9:44 PM, Alex Reynolds <[EMAIL PROTECTED]> wrote:
> The %lu with casting seems to run into the same issue as %u:
>
> ...
> 2008-09-14 21:43:07.241 NSUIntTest[19779:10b] NSUInteger: 2
> 2008-09-14 21:43:07.259 NSUIntTest[19779:10b] NSUInteger: 1
> 2008-09-14 21:43:07.260 NSUIntTest[19779:10b] NSUInteger: 0
> 2008-09-14 21:43:07.261 NSUIntTest[19779:10b] NSUInteger: 4294967295
> 2008-09-14 21:43:07.262 NSUIntTest[19779:10b] NSUInteger: 4294967294

The results will be very different in a 64-bit program :)

The general point is that the NSLog is irrelevant. You are testing
that an unsigned variable is >= 0. An unsigned variable is *always*
>=0 ... it's *unsigned*. This is the reason that your loop isn't
performing to your expectations; it's doing what you said, not what
you meant :).

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

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Jason Coco


On Sep 15, 2008, at 00:44 , Alex Reynolds wrote:


The %lu with casting seems to run into the same issue as %u:

...
2008-09-14 21:43:07.241 NSUIntTest[19779:10b] NSUInteger: 2
2008-09-14 21:43:07.259 NSUIntTest[19779:10b] NSUInteger: 1
2008-09-14 21:43:07.260 NSUIntTest[19779:10b] NSUInteger: 0
2008-09-14 21:43:07.261 NSUIntTest[19779:10b] NSUInteger: 4294967295
2008-09-14 21:43:07.262 NSUIntTest[19779:10b] NSUInteger: 4294967294
...

Interesting.


It does this because your building a 32-bit app. The NSUInteger will  
change size in a 64-bit app which is why using %lu and typecasting to  
(unsigned long) is recommended (this will ensure that you don't get  
warnings if you build a 64-bit app from the same code). Too  
demonstrate, recompile your app as such:


gcc -o  myapp.m -arch x86_64 -framework Foundation

(this assumes an Intel processor... if you're using a PPC then use  
ppc64 instead of x86_64 for the arch).


Jason

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: NSUInteger in for-loop?

2008-09-14 Thread Jason Coco


On Sep 15, 2008, at 00:45 , Brett Powley wrote:



On 15/09/2008, at 2:15 PM, Alex Reynolds wrote:

I'm wondering if I'm using unsigned integers (specifically  
NSUInteger) properly or not.


I was under the impression that unsigned integers run from 0 to  
MAX_INT, but when I use them in a "for" loop within these bounds,  
the loop does not seem to always obey these constraints.


For example:

for (NSUInteger counter = 5; counter >= 0; --counter)
{
NSLog(@"NSUInteger: %d", counter);
}

keeps running well after the "counter" variable turns negative:


First problem:  %d is for signed integers; if you want to see the  
value, you want %u.
Second problem (which you'll see if you change the NSLog):  counter  
is unsigned, so it *never* "turns negative".


The values of counter in your loop will be 5,4,3,2,1,0,MAX_UINT,  
MAX_UINT-1, etc


(Note that the range of values for unsigned integers is 0..MAX_UINT,  
not MAX_INT.)


Just to quickly reiterate, since NSUInteger changes size based on the  
architecture, it's important that you compare it to NSUIntegerMax...


Jason

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: NSUInteger in for-loop?

2008-09-14 Thread Graff
On Sep 14, 2008, at 9:15 PM, Alex Reynolds <[EMAIL PROTECTED]>  
wrote:



I'm wondering if I'm using unsigned integers (specifically NSUInteger)
properly or not.

I was under the impression that unsigned integers run from 0 to
MAX_INT, but when I use them in a "for" loop within these bounds, the
loop does not seem to always obey these constraints.

For example:

for (NSUInteger counter = 5; counter >= 0; --counter)
{
NSLog(@"NSUInteger: %d", counter);
}

keeps running well after the "counter" variable turns negative:

2008-09-14 21:03:12.056 NSUIntTest[19579:10b] NSUInteger: 5
2008-09-14 21:03:12.059 NSUIntTest[19579:10b] NSUInteger: 4
2008-09-14 21:03:12.063 NSUIntTest[19579:10b] NSUInteger: 3
2008-09-14 21:03:12.068 NSUIntTest[19579:10b] NSUInteger: 2
2008-09-14 21:03:12.072 NSUIntTest[19579:10b] NSUInteger: 1
2008-09-14 21:03:12.077 NSUIntTest[19579:10b] NSUInteger: 0
2008-09-14 21:03:12.081 NSUIntTest[19579:10b] NSUInteger: -1
2008-09-14 21:03:12.085 NSUIntTest[19579:10b] NSUInteger: -2


First of all, unsigned int ranges from 0 to UINT_MAX.  NSUInteger  
ranges from 0 to NSUIntegerMax, int ranges from INT_MIN TO INT_MAX.   
These are defined in limits.h.


Secondly, as Nathan said you are using the incorrect format  
specifier.  When you use %d it will interpret the bit pattern passed  
in as if it were a signed integer.


When you decrement an unsigned integer (or a NSUInteger) it will wrap- 
around at 0.  This means that decrementing 0 by 1 will set your value  
at the maximum value for your variable type.  This corresponds to the  
same bit pattern as a value of -1 for a signed integer.  Thus since  
you are displaying the unsigned integer as a signed integer you see  
-1, -2, -3, ...


Last, when you run your loop you are ending your loop when counter is  
less than 0.  Since an unsigned integer can never be less than 0 you  
get an infinite loop.  You should either be using a signed integer and  
break when counter is less than 0 or use a signed integer and break  
when counter equals 0, accounting for the fact that you'll get 1 less  
run through the loop.


Hope this helps!

- Graff
___

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

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

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

This email sent to [EMAIL PROTECTED]


NSUInteger in for-loop?

2008-09-14 Thread Alex Reynolds

Thanks all for your quick insight!

-Alex
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Jason Coco


On Sep 15, 2008, at 00:42 , Alex Reynolds wrote:


Interesting:

...
2008-09-14 21:38:56.311 NSUIntTest[19750:10b] NSUInteger: 2
2008-09-14 21:38:56.329 NSUIntTest[19750:10b] NSUInteger: 1
2008-09-14 21:38:56.341 NSUIntTest[19750:10b] NSUInteger: 0
2008-09-14 21:38:56.344 NSUIntTest[19750:10b] NSUInteger: 4294967295
2008-09-14 21:38:56.344 NSUIntTest[19750:10b] NSUInteger: 4294967294
2008-09-14 21:38:56.346 NSUIntTest[19750:10b] NSUInteger: 4294967293
2008-09-14 21:38:56.354 NSUIntTest[19750:10b] NSUInteger: 4294967292
...

I will say that the NSLog was done for this particular example, just  
to see what's going on.


The loop otherwise keeps rolling along, with or without an NSLog, %d  
or %u.


Going without an NSLog is how I initially found out about this  
issue, in that my program would run into other problems related to  
this loop going past its bounds.


NSUInteger is an unsigned integer... thus, it can't be negative and  
your variable is underflowing. The various uint types are the same...  
unsigned integers. Disassemble your code in the debugger :) you'll see  
that since an unsigned integer ALWAYS evaluates to >= 0 by definition,  
the compiler has optimized out the comparison and simply generated an  
infinite loop.


NSUInteger is from 0 to NSUIntegerMax and NSInteger ranges between  
NSIntegerMin and NSIntegerMax. These types change size depending on  
whether you build a 64-bit app or a 32-bit app.


Jason

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: NSOutlineView: Which row is selected.

2008-09-14 Thread Nick Zitzmann


On Sep 14, 2008, at 9:58 AM, John Cebasek wrote:

I've got an NSOutlineView and am trying to determine which row is  
selected. I thought [super selectedRow]; (calling NSTableView's  
selectedRow method) would do the trick, but all I'm getting back  
from that call is -1.


How does one determine which row is selected in an outline view?



In this scenario, you shouldn't invoke the superclass unless you are  
overriding the method. If the outline view is "self", then call [self  
selectedRow] instead.


Nick Zitzmann


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread j o a r


On Sep 14, 2008, at 9:15 PM, Alex Reynolds wrote:

I'm wondering if I'm using unsigned integers (specifically  
NSUInteger) properly or not.


I was under the impression that unsigned integers run from 0 to  
MAX_INT, but when I use them in a "for" loop within these bounds,  
the loop does not seem to always obey these constraints.


For example:

for (NSUInteger counter = 5; counter >= 0; --counter)
{
NSLog(@"NSUInteger: %d", counter);
}

keeps running well after the "counter" variable turns negative:



NSUInteger runs from 0 -> NSUIntegerMax.

This is how you print a NSUInteger:

NSLog(@"NSUInteger: %lu", ((unsigned long)counter));

j o a r


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: brain-dead NSThread question ...

2008-09-14 Thread Jason Coco


On Sep 14, 2008, at 19:36 , John Michael Zorko wrote:



Julien et al,



sleep() is just blocking the thread, so no event is processed. Use  
run loops instead.


Try to replace sleep() with [[NSRunLoop currentRunLoop]  
runMode:beforeDate:]


You mean the NSURLConnection callbacks are not callbacks in the C / C 
++ sense i.e. they're more like dispatched messages instead?


They are like C callbacks but they get called from the RunLoop. The  
connection gets add as a run loop source and when data is ready, the  
call-back will get invoked.


The other problem that you have with your current implementation is  
that your main thread will completely block too. If this is a console  
app, that's not really a problem, but if this is a GUI app, it will  
stop responding to events and give the user a beach-ball... they will  
probably think that something is wrong and may kill the application,  
so you should watch out for that.


J

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: brain-dead NSThread question ...

2008-09-14 Thread John Michael Zorko


Julien et al,



sleep() is just blocking the thread, so no event is processed. Use  
run loops instead.


Try to replace sleep() with [[NSRunLoop currentRunLoop]  
runMode:beforeDate:]


You mean the NSURLConnection callbacks are not callbacks in the C / C+ 
+ sense i.e. they're more like dispatched messages instead?


Regards,

John

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



___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: brain-dead NSThread question ...

2008-09-14 Thread Julien Jalon
sleep() is just blocking the thread, so no event is processed. Use run loops
instead.
Try to replace sleep() with [[NSRunLoop currentRunLoop] runMode:beforeDate:]

-- 
Julien
___

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

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

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

This email sent to [EMAIL PROTECTED]


NSUInteger in for-loop?

2008-09-14 Thread Alex Reynolds
I'm wondering if I'm using unsigned integers (specifically NSUInteger)  
properly or not.


I was under the impression that unsigned integers run from 0 to  
MAX_INT, but when I use them in a "for" loop within these bounds, the  
loop does not seem to always obey these constraints.


For example:

for (NSUInteger counter = 5; counter >= 0; --counter)
{
NSLog(@"NSUInteger: %d", counter);
}

keeps running well after the "counter" variable turns negative:

2008-09-14 21:03:12.056 NSUIntTest[19579:10b] NSUInteger: 5
2008-09-14 21:03:12.059 NSUIntTest[19579:10b] NSUInteger: 4
2008-09-14 21:03:12.063 NSUIntTest[19579:10b] NSUInteger: 3
2008-09-14 21:03:12.068 NSUIntTest[19579:10b] NSUInteger: 2
2008-09-14 21:03:12.072 NSUIntTest[19579:10b] NSUInteger: 1
2008-09-14 21:03:12.077 NSUIntTest[19579:10b] NSUInteger: 0
2008-09-14 21:03:12.081 NSUIntTest[19579:10b] NSUInteger: -1
2008-09-14 21:03:12.085 NSUIntTest[19579:10b] NSUInteger: -2
...

However, the following does *not* run, starting from a negative  
integer (as I would expect):


for (NSUInteger counter = -5; counter <= 0; ++counter)
{
NSLog(@"NSUInteger: %d", counter);
}

Also, the following works properly:

for (NSUInteger counter = 0; counter <= 5; ++counter)
{
NSLog(@"NSUInteger: %d", counter);
}

I noticed that "uint" works the same way. Is this expected behavior?

Thanks,
Alex
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: brain-dead NSThread question ...

2008-09-14 Thread Shawn Erickson
On Sun, Sep 14, 2008 at 4:12 PM, John Michael Zorko <[EMAIL PROTECTED]> wrote:
>
> Hello, all ...
>
> I'm trying to launch a thread to connect to a server and stream some data.
>  What i'm seeing is that, while my thread launches, the NSURLConnection
> callbacks are never called, and it's probably some silly thing i'm not
> understanding about ObjC / Cocoa (being an old C / C++ developer):

The API you are using supports async "callbacks" so really don't need
to be firing off a thread as you are. You likely could just use NSApp
managed runloop in the main thread (assuming this is an NSApplication
based application). Just convert things to be event driven.

-Shawn
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Jerry Krinock


On 2008 Sep, 14, at 21:31, Nathan Kinsinger wrote:


On Sep 14, 2008, at 10:15 PM, Alex Reynolds wrote:


NSLog(@"NSUInteger: %d", counter);



The correct type modifier for unsigned integers is %u not %d. Switch  
it and try again to see what's really happening.


Ah, I believe he'll probably see all positive numbers.

Look at it this way.  By definition, an NSUInteger or a unit is always  
>= 0.  I believe that explains all the results.


From a more practical perspective, think of that most significant bit  
as a 'carry' bit or 'overflow' indicator.  You need it to tell when  
you're greater than all 's.  Bottom line, I suppose, is to always  
use signed integers in this type of situation.  It seems unfair to be  
cutting your available range in half, but remember it's only one bit!


___

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

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

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

This email sent to [EMAIL PROTECTED]


brain-dead NSThread question ...

2008-09-14 Thread John Michael Zorko


Hello, all ...

I'm trying to launch a thread to connect to a server and stream some  
data.  What i'm seeing is that, while my thread launches, the  
NSURLConnection callbacks are never called, and it's probably some  
silly thing i'm not understanding about ObjC / Cocoa (being an old C /  
C++ developer):


int keepRunningThread = 0;

- (void)playStream:(Song *)streamToPlay
{
// if a player thread is running, tell it to stop ...

keepRunningThread = 0;  // tell thread to stop

while(myData.playing == YES)// wait for it to stop
{
sleep(0);
}

// ... and start a new one with the new stream to play

	NSLog(@"starting thread to play mp3 stream %s", [streamToPlay.mp3  
UTF8String]);


	[NSThread detachNewThreadSelector:@selector(connectAndPlayStream:)  
toTarget:self withObject:streamToPlay];


}

- (void)connectAndPlayStream:(Song *)streamToPlay
{
myData.playing = YES;

keepRunningThread = 1;

NSString *url = @"http://some_host.com/";;
url = [url stringByAppendingString:streamToPlay.mp3];
	NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL  
URLWithString:[url  
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]  
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
	NSURLConnection *connection = [[NSURLConnection alloc]  
initWithRequest:request delegate:self];


if (connection)
{
receivedData = [[NSMutableData data] retain];
}
else
{
NSLog(@"can't connect to server");
}

// I suspect this loop is the problem.  How do I wait for all  
data to be received without blocking the NSURLConnection callbacks?


while (keepRunningThread)
{
sleep(1);
}

myData.playing = NO;
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse: 
(NSURLResponse *)response

{
[receivedData setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData: 
(NSData *)data

{
unsigned int length = [data length];

NSLog(@"recv'd %d bytes", length);
[receivedData appendData:data];
}

- (void)connection:(NSURLConnection *)connection
  didFailWithError:(NSError *)error
{
// release the connection, and the data object
[connection release];
// receivedData is declared as a method instance elsewhere
[receivedData release];

// inform the user
NSLog(@"Connection failed! Error - %@ %@",
  [error localizedDescription],
  [[error userInfo] objectForKey:NSErrorFailingURLStringKey]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// do something with the data
// receivedData is declared as a method instance elsewhere
NSLog(@"Succeeded! Received %d bytes of data",[receivedData  
length]);


// release the connection, and the data object
[connection release];
[receivedData release];
}

Regards,

John

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



___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: brain-dead NSThread question ...

2008-09-14 Thread Ken Thomases

On Sep 14, 2008, at 6:36 PM, John Michael Zorko wrote:

sleep() is just blocking the thread, so no event is processed. Use  
run loops instead.


Try to replace sleep() with [[NSRunLoop currentRunLoop]  
runMode:beforeDate:]


You mean the NSURLConnection callbacks are not callbacks in the C / C 
++ sense i.e. they're more like dispatched messages instead?


How would you imagine that "callbacks in the C / C++ sense" would be  
called during sleep()?  sleep() always causes nothing to be done.   
This isn't specific to Objective-C or Cocoa.


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


Re: mailbundle info

2008-09-14 Thread Mark Munz
On Sun, Sep 14, 2008 at 12:47 PM, Kyle Sluder
<[EMAIL PROTECTED]> wrote:
> rdar://problem/6218715
> Will probably be marked as duplicate, but it doesn't hurt.

Actually, most definitely will be marked as duplicate (I know I've put
in a few requests over the years), but I am told that if enough people
do report a similar bug, it does get noticed. If it doesn't do
anything to report duplicate buts, it would make the entire bug
tracking system a complete joke from 3rd party developer's
perspective.


-- 
Mark Munz
unmarked software
http://www.unmarked.com/
___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: NSUInteger in for-loop?

2008-09-14 Thread Alex Reynolds

Interesting:

...
2008-09-14 21:38:56.311 NSUIntTest[19750:10b] NSUInteger: 2
2008-09-14 21:38:56.329 NSUIntTest[19750:10b] NSUInteger: 1
2008-09-14 21:38:56.341 NSUIntTest[19750:10b] NSUInteger: 0
2008-09-14 21:38:56.344 NSUIntTest[19750:10b] NSUInteger: 4294967295
2008-09-14 21:38:56.344 NSUIntTest[19750:10b] NSUInteger: 4294967294
2008-09-14 21:38:56.346 NSUIntTest[19750:10b] NSUInteger: 4294967293
2008-09-14 21:38:56.354 NSUIntTest[19750:10b] NSUInteger: 4294967292
...

I will say that the NSLog was done for this particular example, just  
to see what's going on.


The loop otherwise keeps rolling along, with or without an NSLog, %d  
or %u.


Going without an NSLog is how I initially found out about this issue,  
in that my program would run into other problems related to this loop  
going past its bounds.


-Alex

On Sep 14, 2008, at 9:31 PM, Nathan Kinsinger wrote:


On Sep 14, 2008, at 10:15 PM, Alex Reynolds wrote:


NSLog(@"NSUInteger: %d", counter);



The correct type modifier for unsigned integers is %u not %d. Switch  
it and try again to see what's really happening.


--Nathan


___

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

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

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

This email sent to [EMAIL PROTECTED]