Re: odd problem with NSMutableDictionary and initWithContentsOfFile

2008-05-29 Thread Jason Coco


On May 29, 2008, at 10:47 , Jens Alfke wrote:



On 29 May '08, at 6:41 AM, Leslie Smith wrote:


I found out what I was doing wrong:  rather than

[SimParamnames initWithContentsOfFile: aFile];

I should have had

SimParamnames = [SimParamnames initWithContentsOfFile: aFile];


No. As two people have said already, *you can't initialize an object  
more than once*. The only time an init method is to be called is  
right after -alloc, when the object is first created. Calling it  
again will unexpectedly reset part of the object's state, and  
probably mess it up.


What you should do instead of the above line is
[SimParamnames release];// to get rid of the old object
	SimParamnames = [[NSDictionary alloc] initWithContentsOfFile:  
aFile];  // new object


If for some reason you absolutely want/need to use the  
NSMutableDictionary that you originally allocated, you can do  
something like this:


[SimParamnames removeAllObjects];
[SimParamnames addEntriesFromDictionary:[NSDictionary  
dictionaryWithContentsOfFile:aFile]];


That should work as expected without releasing the original mutable  
dictionary (assuming you really do need it for something you cut in  
the example).

___

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: CoreData file format stability

2008-06-03 Thread Jason Coco


On Jun 3, 2008, at 23:03 , Michael Ash wrote:


On Wed, Jun 4, 2008 at 12:48 AM, Kyle Sluder
<[EMAIL PROTECTED]> wrote:


This is extremely unlikely to occur in practice.  Apple is sensible
enough to, in these sorts of circumstances, make these changes
depending on which SDK you're compiling against or, since Core Data
has versioning support now, silently upgrade files upon opening them.


Note that silently upgrading files when opening is the last thing
you'd want in this case. A file saved using FooApp 1.2 on 10.6 should
still work in FooApp 1.2 on 10.5. If you destroy my files so that they
no longer work on 10.5 without even asking me then I'll get upset.


Ben Trumbull specifically stated that as long as FooApp 1.2 targets  
10.5,

this scenario won't happen.

Jason
___

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: Where to start looking to fix hang?

2008-06-04 Thread Jason Coco
You can use the Spin Control application (/Developer/Applications/ 
Performance Tools/Spin Control.app) to start... that will let you know  
what's going on when it starts to hang (this application profiles  
everything, so just start it before you launch your application,  
launch your app and reproduce the bug). This will give you a decent  
idea as to where to put your initial break point and then you can  
probably just step through from there–at least until you narrow down  
what's going on.


HTH, Jason

On Jun 5, 2008, at 00:17 , Graham Cox wrote:

In my app I'm getting a hang when my main document window is asked  
to close. This occurs only if there are unsaved changes, but it  
hangs before the "unsaved changes" sheet is presented.


If I link against the 10.4u SDK (but still run on 10.5), this does  
not occur, but if I link against the 10.5 SDK, I get the problem.  
Obviously something changed between the two implementations.


Where should I start to look to debug/fix this? I just can't see  
where I need to set a breakpoint to begin with.


___

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: warning: return makes pointer from integer without cast

2008-06-10 Thread Jason Coco

Hey Steve,

In this case, you are returning a regular integer (count returns just  
a regular, scalar type). But you've declared your return value as id,  
which is a typedef for a type of pointer. You either have to return an  
actual integer, or wrap the return of count in an object like NSNumber.


/jason

On Jun 10, 2008, at 08:32 , Steven Hamilton wrote:


Hi folks, newbie here.

A quickie query on a warning.

Both returns in the following code give a 'warning: return makes  
pointer from integer without cast'


- (id)outlineView:(NSOutlineView *)outlineView  
numberOfChildrenOfItem:(id)item

{
if (!item) {
return [outlineTree count];
}
return [[outlineTree objectForKey:item] count];

I can't work out why. "count" returns an integer which I should be  
able to return or does the return only send back a pointer to the  
integer of which I should be casting earlier on?

___

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


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Confused about AuthorizationExecuteWithPrivileges and suid

2008-06-11 Thread Jason Coco
The documentation is talking about using  
AuthorizationExecuteWithPrivleges() to repair a setuid tool that you  
may have already created. It is also suggesting that you use the  
setuid tool method rather than using  
AuthorizationExecuteWithPrivleges(). In this way, the setuid tool can  
limit itself to only doing a specific task. It can also ensure that  
its caller is authorized to call it and abort in any other circumstance.


All that said, you don't need any setuid bit in order to call  
AuthorizationExecuteWithPrivleges() (neither on the calling  
application nor on the target application).


/jac

On Jun 11, 2008, at 21:34 , Eyal Redler wrote:


Hi All,

I need to access some files in the Applications folder and in order  
to do so I did the following:


1. I've created a tool that copies the files into the Applications  
folder (using NSFileManager)

2. I'm invoking the tool using AuthorizationExecuteWithPrivileges()
3. In the tool I'm calling setuid(geteuid()) at the begining
4. The tool does not have its setuid bit set

This setup seems to work fine without doing anything regarding the  
setuid bit yet the (very unclear and confusing) documentation seems  
to refer to AuthorizationExecuteWithPrivileges as something you use  
to run a setuid tool.


Should I set the setuid bit? Why?

TIA

Eyal Redler

"If Uri Geller bends spoons with divine powers, then he's doing it  
the hard way."

--James Randi
www.eyalredler.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/jason.coco 
%40gmail.com


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: argument checks

2008-06-11 Thread Jason Coco

#include 

/* ... */

NSNumber *myNum = nil;

// Lots of code where you've forgotten to actually do anything with  
myNum


assert( myNum != nil );
results = [myClass someCalculationUsing: myNum];

// lots more code

to remove the assertion in the release build, compile with -DNDEBUG

HTH, /jason

On Jun 12, 2008, at 01:50 , Ashley Perrien wrote:

Noob question: I'm putting together a small code library and I'm  
trying to include some error checking in the methods; what I want to  
protect against is the following:


NSNumber *myNum;

// Lots of code where I've forgotten to actually do anything with  
myNum


results = [myClass someCalculationUsing: myNum];

myNum in this case is an object and does exist but it's not a valid,  
usable argument. So in the implementation I'd like to have something  
along the lines of:


if (myNum == nil)
NSLog(@"some error message");

but can't figure out what to check for that would get me into the  
error message condition. Any suggestions?


Ashley Perrien
___

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


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: argument checks

2008-06-12 Thread Jason Coco
Just a note, the NSAssert() Foundation function should only be called  
from inside an Objective-C method... if your code is somewhere in an  
Object-C class, this is fine, but if you're calling from inside a C- 
callback function or another C helper function (since you're creating  
a Library, this may be the case), and you want to use the Foundation  
method instead of the libc method (that I described earlier), make  
sure you use NSCAssert(myNum != nil, @"blah blah blah");


Also, to disable assertions in these cases, compile with - 
DNS_BLOCK_ASSERTIONS


/jason

On Jun 12, 2008, at 02:51 , Graham Cox wrote:


NSNumber* myNum = nil;

/* stuff */


NSAssert( myNum != nil, @"some error message");

[myClass calc:myNum];



Messages to nil are safe - it will treat your number as having a  
value of 0. Thus as long as you initialise it to nil, your code will  
run without crashing though of course may give incorrect results. If  
you don't initialise it to anything, it will almost certainly crash.  
The compiler should be warning you about this - if not, make it do so.


G.

On 12 Jun 2008, at 3:50 pm, Ashley Perrien wrote:

Noob question: I'm putting together a small code library and I'm  
trying to include some error checking in the methods; what I want  
to protect against is the following:


NSNumber *myNum;

// Lots of code where I've forgotten to actually do anything with  
myNum


results = [myClass someCalculationUsing: myNum];

myNum in this case is an object and does exist but it's not a  
valid, usable argument. So in the implementation I'd like to have  
something along the lines of:


if (myNum == nil)
NSLog(@"some error message");

but can't figure out what to check for that would get me into the  
error message condition. Any suggestions?


Ashley Perrien
___

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/graham.cox%40bigpond.com

This email sent to [EMAIL PROTECTED]


___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jason.coco 
%40gmail.com


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: argument checks

2008-06-12 Thread Jason Coco
I agree with Graham, although I misread the initial question as  
well... if the person is passing a garbage pointer, there's really not  
much you can do. All you can really do is assert that the object you  
expected is not nil.


Why is it unsafe to pass nil? Many API in Cocoa tell you to pass nil  
for various default behaviors.


/jason

On Jun 12, 2008, at 03:29 , Graham Cox wrote:



On 12 Jun 2008, at 5:03 pm, Chris Suter wrote:

In the original example, myNum was being passed as a argument  
rather than having a message to sent to it and it’s often not safe  
to pass nil objects as arguments.



Hmmm... well, what's the function it's passed to going to do with  
it, other than call a method on it? If it's doing anything else,  
it's breaking other (much stronger) rules. If it tries to access its  
ivars directly, that's breaking encapsulation. If it tried to  
release it, that breaks memory management rules... etc. So I think  
in general it's quite safe to pass nil arguments where an object is  
expected - I certainly do it all the time, and haven't found any  
real problem with that so far.


Contractually, nil is defined as type id, and type id can be passed  
for any object type, so this is not even a hack - it's entirely  
permitted by design. NULL on the other hand, is another story.


Code that does not allow a nil argument should assert that. If it  
doesn't it is implicitly allowing nil, unless it is specifically  
documented otherwise.


Can you give me a counter-example?

G.___

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


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: argument checks

2008-06-13 Thread Jason Coco
You can use either... I tend to use #include when I'm calling C  
libraries and #import when I'm including things that are Objective-C.  
It's just my habit but it's really just

a style issue.

On Jun 12, 2008, at 21:37 , William Squires wrote:

I thought ObjC used "#import", not "#include", so that multiple  
copies of a header wouldn't appear, but maybe that's just for Cocoa  
stuff, and not for "ordinary" C?


On Jun 12, 2008, at 1:05 AM, Jason Coco wrote:


#include 

/* ... */

___

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: looking for a crc code

2008-06-15 Thread Jason Coco

There is:

uLong crc32(uLong crc, const Bytef *buf, uInt len);

On Jun 14, 2008, at 20:04 , Michael Vannorsdel wrote:


I thought I saw a CRC32 implementation in zlib at one time.


On Jun 14, 2008, at 9:25 AM, Jens Alfke wrote:


On 14 Jun '08, at 4:59 AM, Ilan Volow wrote:

No mention at all I can find (in the 20 seconds I scanned the  
first two result pages) of any cocoa CRC implementations. If a  
newbie were to do a search like this and turned up such a  
fruitless list of leads, I wouldn't be surprised in the least   
that they came to the list and asking for a personal  
recommendation of some hard-to-find Cocoa framework from  
experienced Cocoa programmers.


Yes, but what does CRC have to do with Cocoa? It's just a function  
that takes a pointer and a length and returns an int. It'd be  
trivial to use any C implementation in a Cocoa app, so there's no  
reason to restrict the search by adding "cocoa" as a keyword.


___

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


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Agent tutorial help needed.

2008-06-16 Thread Jason Coco

Have you read this Technical Article yet?

http://developer.apple.com/technotes/tn2005/tn2083.html

It's very good and has some code examples as well as many references  
to other material...


On Jun 16, 2008, at 15:40 , christian giacomi wrote:


Hi all,I am new to Cocoa and Objective-C so I hope you will forgive my
question if it sounds stupid.

I am looking for some tutorials or demos on Cocoa Agents. I do not  
have to
write a daemon, and I have found a few articles discussing the  
differences
between daemons and agents on a Mac, but no real tutorial discussing  
HOW you

write an Agent.

Could anyone be so kind as to point me in the right direction.
Thank you in advance,

Chris

--
I would rather be ashes than dust
A spark burnt out in a brilliant blaze, than to be stifled in dry rot
For man's chief purpose is to live, not to exist;
I shall not waste my days trying to prolong them,
I shall use my time
/Jack London 1876-1916
___

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


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: SSCrypto Framework

2008-06-20 Thread Jason Coco
You could use the keychain for this... I think it would be the easiest  
way to support your application. Either install your certificate into  
the system keychain or provide a keychain file that your application  
accesses exclusively.


On Jun 20, 2008, at 11:45 , Trygve Inda wrote:


I am considering using the SSCrypto Framework:

http://septicus.com/products/opensource/

I would embed a public key in my app and encrypt a data file on our  
site
that the software needs to download periodically. This is mostly to  
ensure

that file can not be modified or substituted except by us.

Has anyone used this in a shipping app? Any thoughts or comments  
about how
well it is implemented and how robust it will be going into the  
future?


I am trying to avoid a support nightmare.

Thanks,

Trygve


___

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: SSCrypto Framework

2008-06-20 Thread Jason Coco
Yeah, I understand that... you don't need to actually buy a  
certificate for that. You can just install your certificate that you  
generate yourself and then use it internally to check the integrity of  
your data files or whatever else you'd like to do with it.


On Jun 20, 2008, at 12:04 , Trygve Inda wrote:

You could use the keychain for this... I think it would be the  
easiest

way to support your application. Either install your certificate into
the system keychain or provide a keychain file that your application
accesses exclusively.


Except I don't want to buy a certificate - rather I just need to  
generate a
public/private key on my end and embed the public key. The concern  
is not
that the users know the file is really from us, the concern is from  
our

point of view, that the user can't modify the file.

Trygve




___

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: SSCrypto Framework

2008-06-20 Thread Jason Coco
There would be a couple of ways that you could do it... you could  
place your certificate in the System keychain and then add it so that  
it can be read by your application anytime. This should work okay and  
if you do this during installation, the user should only have to  
authenticate then. But, the user could mess with this... delete the  
certificate or remove your application from the list of applications  
that can read it without authenticating...


The other option is to just create a private keychain that you put  
anything you want into and lock it yourself. It would get deployed  
with your application bundle and only your application would ever  
access it. Don't even give the user the key so they can't mess with it  
at all (Microsoft uses this strategy with its distribution of Office  
2008).


/jason

On Jun 20, 2008, at 15:06 , Trygve Inda wrote:


Yeah, I understand that... you don't need to actually buy a
certificate for that. You can just install your certificate that you
generate yourself and then use it internally to check the integrity  
of

your data files or whatever else you'd like to do with it.



How would I go about doing this... And does the user have to do  
anything
(like authorize with a password)? I want to sign/encrypt on my end  
and have

my app decrypt with no user action required - so it is completely
transparent.

Thanks,

Trygve




___

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: zlib in 10.4 and 10.5

2008-06-22 Thread Jason Coco
Yes... everything since OS X 10.4.3 uses zlib 1.2.3... but even before  
that, everything used 1.2.x. zlib has been very stable for a very long  
time so you won't really run into any issues...


/j

On Jun 22, 2008, at 06:41 , Trygve Inda wrote:




No. The library will return Z_VERSION_ERROR if you try to
inflate something that the working zlib library doesn't understand.

That said, zlib has been stable for years. If you're just now
getting started with compression, you should't have version
problems (that you can't manage).


Are all zlibs shipped in 10.4 and 10.5 mutually compatible? If I  
compress

something on 10.5.3, can 10.4.0 uncompress it?

Thanks,

Trygve


___

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


This email sent to [EMAIL PROTECTED]


___

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

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

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

This email sent to [EMAIL PROTECTED]


Re: Interesting Problem Code worked in 10.4 but not in 10.5

2008-06-22 Thread Jason Coco
There should be crash reports in ~/Library/Logs/CrashReporter – that  
should give you the register state, thread stack, and information on  
which thread crashed.


On Jun 22, 2008, at 18:38 , Clayton Leitch wrote:


Well, the only thing I get from the debugger is:
[Session started at 2008-06-22 18:35:23 -0400.]
Loading program into debugger…
GNU gdb 6.3.50-20050815 (Apple version gdb-956) (Wed Apr 30 05:08:47  
UTC 2008)

Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and  
you are
welcome to change it and/or distribute copies of it under certain  
conditions.

Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for  
details.

This GDB was configured as "i386-apple-darwin".Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/leitchc/Documents/Coding Efforts/ 
SoftCopyContract 2.0/build/Release/SoftCopyContract 2.0.app/Contents/ 
MacOS/SoftCopyContract 2.0', process 408.

Program received signal:  “EXC_BAD_ACCESS”.

I tried all sorts of different settings, because in the past I have  
gotten a stack.

On Jun 22, 2008, at 5:43 PM, Jean-Daniel Dupas wrote:


Launch it with the debugger and check the stack when it crash.
Without any hint about the stack, we cannot really help you, but  
just give you some guess.


Le 22 juin 08 à 23:26, Clayton Leitch a écrit :

See code below.  Get a error of “EXC_BAD_ACCESS” when I make  
entries in the GUI.  Code used to work with no problems.  It  
appears that it is doing an illegal substraction, which I think  
means the objects are not being initialized with a value of 0.  At  
least that is my guess.

#import "MonthlyReport.h"


@implementation MonthlyReport
+ (void)initialize
{
if (self == [MonthlyReport class])
{
		NSArray *keys = [NSArray arrayWithObjects:  
@"reportCumActualCost", @"reportActualCost",  
@"reportPredictedCost", @"reportCumPredictedCost",  
@"reportCumlativeInvoiceTotal", @"reportMonthlyInvoiceAmount", nil];
		[self setKeys:keys  
triggerChangeNotificationsForDependentKey:@"reportCumDifference"];
		[self setKeys:keys  
triggerChangeNotificationsForDependentKey 
:@"reportCurrentDifference"];
		[self setKeys:keys  
triggerChangeNotificationsForDependentKey 
:@"reportPercentDifferenceMonth"];
		[self setKeys:keys  
triggerChangeNotificationsForDependentKey 
:@"reportPercentDifferenceCum"];
		[self setKeys:keys  
triggerChangeNotificationsForDependentKey 
:@"reportInvoiceMonthlyDifference"];
		[self setKeys:keys  
triggerChangeNotificationsForDependentKey 
:@"reportInvoiceCumlativeDifference"];

}
}

//Calculate differences
- (NSDecimalNumber *)reportCurrentDifference;
{
	return [[self valueForKey:@"reportActualCost"]  
decimalNumberBySubtracting: [self  
valueForKey:@"reportPredictedCost"]];

}
- (NSDecimalNumber *)reportCumDifference;
{
	return [[self valueForKey:@"reportCumActualCost"]  
decimalNumberBySubtracting: [self  
valueForKey:@"reportCumPredictedCost"]];

}
- (NSDecimalNumber *)reportInvoiceMonthlyDifference;
{
	return [[self valueForKey:@"reportMonthlyInvoiceAmount"]  
decimalNumberBySubtracting:[self valueForKey:@"reportActualCost"]];

}
- (NSDecimalNumber *)reportInvoiceCumlativeDifference;
{
	return [[self valueForKey:@"reportCumlativeInvoiceTotal"]  
decimalNumberBySubtracting:[self  
valueForKey:@"reportCumActualCost"]];

}

//Calculate percents
- (NSDecimalNumber *)reportPercentDifferenceMonth;
{
	return [[[self valueForKey:@"reportCurrentDifference"]  
decimalNumberByDividingBy: [self  
valueForKey:@"reportPredictedCost"]]  
decimalNumberByMultiplyingByPowerOf10: (short)2];

}
- (NSDecimalNumber *)reportPercentDifferenceCum;
{
	return [[[self valueForKey:@"reportCumDifference"]  
decimalNumberByDividingBy: [self  
valueForKey:@"reportCumPredictedCost"]]  
decimalNumberByMultiplyingByPowerOf10: (short)2];

}



@end

___

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/devlists%40shadowlab.org

This email sent to [EMAIL PROTECTED]





___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jason.coco 
%40gmail.com


This email sent to [EMAIL PROTECTED]


___

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

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

Help/Unsubscribe/Update your Subscription:
http://li

Re: Interesting Problem Code worked in 10.4 but not in 10.5

2008-06-22 Thread Jason Coco
Is it possible that your NSDecimalNumber is no longer a valid object  
reference?


On Jun 22, 2008, at 19:08 , Clayton Leitch wrote:


Well, thanks to the list I now have a back trace below:
#0  0x96cd5564 in NSDecimalCopy ()
#1  0x96d854f9 in NSDecimalSubtract ()
#2  0x96dadad8 in -[NSDecimalNumber  
decimalNumberBySubtracting:withBehavior:] ()

#3  0x96dada47 in -[NSDecimalNumber decimalNumberBySubtracting:] ()
[...]

___

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: Working with Notifications and NSFileHandle

2008-06-27 Thread Jason Coco


On Jun 27, 2008, at 20:11 , Ken Thomases wrote:


On Jun 27, 2008, at 3:32 PM, Wan, Nathan (CIV) wrote:

I'm new to Objective-C and Cocoa and I am having trouble with the  
notifications system.  This I thought was just a small project to  
write a native mac program to continuously read and write data from  
a serial port to a file.  It was suggested I use NSFileHandle to  
maintain safe threads, as it can read the serial port  
asynchronously; I had hoped this program would read the text file,  
and as I changed it, there would be an output to the console.   
Something simple to see the notification system in action:


//CODE

#import 
#import 
#import 
#import 


Once you've imported Cocoa.h, I don't think you need to explicitly  
import these Foundation headers.


You don't... if you're using AppKit, you should just include Cocoa.h>, if you're using Foundation,

you should just include 




#import 


If you were to use NSLog rather than printf, you wouldn't need this  
either.


This is included for you when you include the main Cocoa or Foundation  
header (actually, it's
included in CoreFoundation.h which gets included by Foundation.h which  
gets included by

Cocoa.h.

Unless you define CF_EXCLUDE_CSTD_HEADERS, you get the following  
headers every

time you use Cocoa, Foundation, or CoreFoundation:





















The Foundation/Foundation.h file includes all the Foundation headers  
as well as CoreFoundation/CoreFoundation.h, the AvailabilityMacros.h  
and the objc header files. So you never have to explicitly #include  
these if you use any of the high-level frameworks.

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: exec(uting) Safari - How (newbie)

2008-07-01 Thread Jason Coco
You could also use /usr/bin/open -- then you wouldn't have to know  
where safari lives.


execl("/usr/bin/open", "/usr/bin/open", "-a", "Safari", 0);

On Jul 1, 2008, at 11:19 , Kristopher Matthews wrote:


Try executing "/Applications/Safari.app/Contents/MacOS/Safari".

/Applications/Safari.app identifies a bundle, not the actual  
application (and execv() is not aware of bundles).


--Kris

On Jul 1, 2008, at 10:15 AM, Barrie Green wrote:


Hi all,

I want to write a quick little cocoa app that fires off Safari.

I started with something like

int main(int argc, char* argv[]) {
...
...
if(execv("/Applications/Safari.app", someArgs) == -1) {
  NSLog(@"execv failed with %s", strerror(errno));
}
}

It always fails with 'Permission denied', OK I kinda expect that. But
how do I fix it?

Would authorization would help? I've looked a the docs a little and  
it

would appear that I should do a
AuthorizationCreate/AuthorizationCopyRights shuffle but if so what
rights should I use?

Ideally I would like to run the app without it asking me for my
password, how could I achieve that?

TIA

bg


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: exec(uting) Safari - How (newbie)

2008-07-01 Thread Jason Coco
What env pollution? I agree that exec* isn't really the way to go, but  
that's what the OP was using... I just suggested that /usr/bin/open is  
a better option than hard-coding the path to some arbitrary  
application. It's also a lot easier to use than the LaunchServices  
API... although if I were gonna use it, I'd definitely do so from an  
NSTask object as others have already suggested.


On Jul 1, 2008, at 23:44 , Kyle Sluder wrote:

On Tue, Jul 1, 2008 at 8:17 PM, Kevin Elliott <[EMAIL PROTECTED]>  
wrote:
Of course, they're both bad choices.  As several people have  
pointed out,
NSWorkspace launchApplication or openURL depending on the  
requirements.  If
it's not possible to use NSWorkspace (i.e. because you can't link  
against
AppKit) consider NSTask or using LaunchServices.  But unless you  
have a

SPECIFIC, low level requirement exec is the wrong API.


I was even more concerned about the env pollution necessary for exec
to work as described ("not needing to know where Safari lives").  exec
is just a bad idea all around for anything outside of the BSD
environment.

--Kyle Sluder




smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: exec(uting) Safari - How (newbie)

2008-07-02 Thread Jason Coco
Yeah, to me it is... although I still agree that it's not an ideal  
solution for a Cocoa application...


By the way, assuming you change char *args[] = { "-a", "Safari",  
NULL }; to char *args[] = { "/usr/bin/open", "-a", "Safari", NULL };  
the exec* example actually works while the LaunchServices example  
fails with kLSApplicationNotFoundError.


After playing around with it a little, I discovered that you need to  
actually call it CFSTR("Safari.app") in this case to get it to work  
correctly... so like anything else in life, since I'm much more  
familiar with the POSIX/BSD API (and since pretty much every operating  
system I've ever worked with treats exec* similar) it's a lot easier  
*for me* than using LaunchServices.


On Jul 2, 2008, at 03:30 , Jean-Daniel Dupas wrote:


"a lot easier than Launch Services" ?

extern char **environ;
char *args[] = { "-a", "Safari", NULL};
execve("/usr/bin/open", args, environ);

versus:

FSRef app;
if (noErr == LSFindApplicationForInfo(kLSUnknownCreator, NULL,  
CFSTR("Safari"), &app, NULL))

LSOpenFSRef(&app, NULL);



Le 2 juil. 08 à 06:45, Jason Coco a écrit :

What env pollution? I agree that exec* isn't really the way to go,  
but that's what the OP was using... I just suggested that /usr/bin/ 
open is a better option than hard-coding the path to some arbitrary  
application. It's also a lot easier to use than the LaunchServices  
API... although if I were gonna use it, I'd definitely do so from  
an NSTask object as others have already suggested.


On Jul 1, 2008, at 23:44 , Kyle Sluder wrote:

On Tue, Jul 1, 2008 at 8:17 PM, Kevin Elliott <[EMAIL PROTECTED]>  
wrote:
Of course, they're both bad choices.  As several people have  
pointed out,
NSWorkspace launchApplication or openURL depending on the  
requirements.  If
it's not possible to use NSWorkspace (i.e. because you can't link  
against
AppKit) consider NSTask or using LaunchServices.  But unless you  
have a

SPECIFIC, low level requirement exec is the wrong API.


I was even more concerned about the env pollution necessary for exec
to work as described ("not needing to know where Safari lives").   
exec

is just a bad idea all around for anything outside of the BSD
environment.

--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/devlists%40shadowlab.org

This email sent to [EMAIL PROTECTED]






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: exec(uting) Safari - How (newbie)

2008-07-02 Thread Jason Coco


On Jul 2, 2008, at 11:36 , Jean-Daniel Dupas wrote:



Le 2 juil. 08 à 16:58, Jason Coco a écrit :

Yeah, to me it is... although I still agree that it's not an ideal  
solution for a Cocoa application...


By the way, assuming you change char *args[] = { "-a", "Safari",  
NULL }; to char *args[] = { "/usr/bin/open", "-a", "Safari",  
NULL }; the exec* example actually works while the LaunchServices  
example fails with kLSApplicationNotFoundError.




Mail is not a very good IDE ;-)


Nope, not at all :)



After playing around with it a little, I discovered that you need  
to actually call it CFSTR("Safari.app") in this case to get it to  
work correctly... so like anything else in life, since I'm much  
more familiar with the POSIX/BSD API (and since pretty much every  
operating system I've ever worked with treats exec* similar) it's a  
lot easier *for me* than using LaunchServices.


OK.

In fact, I never use LS with app name but with bundle ID instead.  
It's far more reliable.


LSFindApplicationForInfo(kLSUnknownCreator,  
CFSTR("com.apple.Safari"), NULL, &app, NULL)




That's actually really useful to know... by the way, I'm not actually  
convinced that the OP knows that exec* is gonna terminate his  
application...

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: exec(uting) Safari - How (newbie)

2008-07-02 Thread Jason Coco


On Jul 2, 2008, at 11:38 , Clark Cox wrote:


On 7/2/08, Jason Coco <[EMAIL PROTECTED]> wrote:

Yeah, to me it is... although I still agree that it's not an ideal
solution for a Cocoa application...

By the way, assuming you change char *args[] = { "-a", "Safari",
NULL }; to char *args[] = { "/usr/bin/open", "-a", "Safari", NULL };
the exec* example actually works while the LaunchServices example
fails with kLSApplicationNotFoundError.

After playing around with it a little, I discovered that you need to
actually call it CFSTR("Safari.app") in this case to get it to work
correctly... so like anything else in life, since I'm much more
familiar with the POSIX/BSD API (and since pretty much every  
operating

system I've ever worked with treats exec* similar) it's a lot easier
*for me* than using LaunchServices.


Easy or not, it's still wrong. Launching safari via exec will not, for
example, re-use an already/running instance.

Just don't use exec to launch GUI applications--period.


I don't think anyone disagrees with that... that's why the suggestion  
was to use /usr/bin/open if you were gonna use an exec* call. If you  
use /usr/bin/open it makes a proper connection to the window server as  
well as sending the proper apple event to an already-started  
application.

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: Learning How to Program in Objective-C

2008-07-11 Thread Jason Coco
Also, if you do choose to get Hillegass's book, keep in mind that the  
current edition (3rd Edition) is for Xcode 3.x/Obj-C 2.0... so if  
you're sticking to 2.5, I suggest trying to find a copy of the 2nd  
edition somewhere. If you print out the Obj-C 2.0 reference as was  
suggested, note that it's only valid on Leopard... you will not have  
access to certain things like garbage collection, properties, etc.– 
which may be very confusing if you're just trying to learn from scratch.


/jason

On Jul 11, 2008, at 10:17 , mmalc Crawford wrote:



On Jul 11, 2008, at 6:54 AM, Jon Buys wrote:


The best thing I can recommend is to buy the Cocoa
Programming book by Hillegass:
http://www.amazon.com/exec/obidos/ASIN/0321503619/bignerdranch-20

If you have no programming experience, this is probably too advanced  
a starting point.

Start with Kochan's book (Programming in Objective-C):




mmalc

___

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


This email sent to [EMAIL PROTECTED]




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: starting external program at runtime

2008-07-11 Thread Jason Coco
If your helper application is a console app, however, you should keep  
it with your main application bundle and use NSTask to run it and  
interact with it. (By console app I simply mean something that doesn't  
interact directly with the user).


On Jul 11, 2008, at 11:19 , Abernathy, Joshua wrote:


NSWorkspace can launch applications for you. Check out
http://theocacao.com/document.page/183 and
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/
Classes/NSWorkspace_Class/Reference/Reference.html.

-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
] On Behalf Of Daniel Richman
Sent: Friday, July 11, 2008 11:15 AM
To: Cocoa-dev List
Subject: starting external program at runtime

Hi All,

I want to start an application (it's bundled with my main app) in a
specific case. It was previously installed to a known location (it's a
helper app, so I put it in ~/Library/Application Support -- was that  
the


right thing to do?), so is there any class I can call upon, or is the
best thing just a system() call?

Daniel
___

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/jabernathy%40burrislogi
stics.com

This email sent to [EMAIL PROTECTED]
___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jason.coco 
%40gmail.com


This email sent to [EMAIL PROTECTED]




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: I don't understand why this is leaking...

2008-08-12 Thread Jason Coco


On Aug 12, 2008, at 07:49 , Phil wrote:


On Tue, Aug 12, 2008 at 10:25 PM, Gerriet M. Denkmann
<[EMAIL PROTECTED]> wrote:

Yes, I have.

1. Simple Test:
In IB create new window, add NSTextField with content  
"$null" (without the

quotes) save in 10.2 or later format. Close. Open again. Look at your
string.


[...]
Maybe this will work on Leopard. On Tiger it does not. (No crash,  
nor error

message either).



I tested this in Leopard, 2.x NIBs have this problem, but 3.X NIBs and
XIBs do not. It looks like it was a bug that's fixed in Leopard, but
preserved in some cases for backwards compatability.

Although, I wouldn't consider this bug much of a reason for not using
keyed archiving. Even though NS(Un)Archiver aren't deprecated, they
have been "replaced".


Just for fun I tested the example program built from the command line  
in Leopard (10.5.4 9E17) running
XCode 3.1 (latest build) and the current Foundation library... the  
problem as demonstrated by the example
code still exists... the string @"$null" gets decoded as a nil pointer  
instead of a string with the word "$null".


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: Determine who ran an application

2008-08-12 Thread Jason Coco


On Aug 12, 2008, at 12:01 , GARRISON, TRAVIS J. wrote:


I am new to Cocoa and Xcode, so please bear with me. I am editing an
existing application that we have. The application is set to run when
the user logs into the machine through a loginHook. We have to pass  
the

%USER% variable as an argument. I would like to pull the username from
directly in the application. I tried to Google for this but did not  
have

any luck. Any ideas?


If you just need the basic user id, you can use getuid(2). There are  
various API in the security frameworks and the directory services  
(10.5+) frameworks that map it to more useful Mac OS Specific user  
information.

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: I don't understand why this is leaking...

2008-08-12 Thread Jason Coco



On Aug 12, 2008, at 12:50 , Klaus Backert wrote:


About $Null:


It it were a reserved word, it would be documented so.



The "Archives and Serializations Programming Guide for Cocoa" says:

Keyed Archives
...
Naming Values
...
You should avoid using “$” as a prefix for your keys. The keyed  
archiver and unarchiver use keys prefixed with “$” for internal  
values. Although they test for and mangle user-defined keys that  
have a “$” prefix, this overhead slows down archiving performance.

...


In this case, however, it's the actual value being encoded... not the  
key name. Also, if you read it, it suggests that you shouldn't use it  
for performance reasons. It specifically states that it is supposed to  
properly mangle the $ in a key name (causing the performance loss)...

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: Accessing memory of another application?

2008-08-12 Thread Jason Coco


On Aug 13, 2008, at 01:51 , Graham Cox wrote:



On 13 Aug 2008, at 3:22 am, Josh wrote:

You have to be able to do this - I have seen applications do it -  
you just

have to type in your root password when you start the application.


LOL, thanks for the light entertainment :)



Basically like game trainers you see everywhere on windows - but I  
don't

find a lot of them on os x.



And people say Macs are only more secure because of their lower  
market share


Prior to the release of Leopard it was trivial to manipulate another  
process's memory space as long as the processes were owned by the same  
user. Now the user has to authorize against a specific right, run as  
root, or the application trying to accomplish this has to be signed in  
order for it to work. Aside from that, tho, the actual application or  
reading/writing another process's memory space is still pretty trivial  
using mach calls.

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: Accessing memory of another application?

2008-08-13 Thread Jason Coco


On Aug 13, 2008, at 09:27 , Kyle Sluder wrote:
On Tue, Aug 12, 2008 at 10:14 PM, Steve Byan <[EMAIL PROTECTED]>  
wrote:
Actually, the man-page is incomplete and doesn't tell you how to  
read and

write another process's memory.


The manpage also fails to mention the undocumented PT_DENY_ATTACH flag
that applications can pass to force ptrace to fail to attach.  Pro
Tools, for example, does this because the "programmers" who wrote it
spent twice as much time on the copy protection as on the actual
application.


My manpage for ptrace shows the PT_DENY_ATTACH flag. It's the second  
flag documented under requests...


Anyway, for what he wants to do (obviously not a commercial  
application), I think the mach traps are the easiest
way to achieve his goals. Spawning the application into memory and  
dealing with an execution interpreter, as was
suggested before, is IMO way overcomplicated to cheat at a game :)  
much easier to just beat the game...

smime.p7s
Description: S/MIME cryptographic signature
___

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

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

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

This email sent to [EMAIL PROTECTED]

Re: How to include a .c file in a loadable bundle?

2008-08-13 Thread Jason Coco
You can't use Foundation in a C file... it's an Objective-C framework.  
Use CoreFoundation instead... you're getting these errors because  
Foundation/Foundation.h includes many Object-C statements which won't  
compile in C.


HTH, Jason

On Aug 13, 2008, at 13:05 , Jesse Grosjean wrote:

Feeling pretty dumb here, but I can't seem to include a .c file in  
my loadable bundle target. I get a ton of errors. Is there some  
trick that I'm missing. Here's what I'm doing.


1. Create new Xcode "Cocoa Application" project.
2. Create new loadable bundle in that project.
3. Add new Carbon C file to the application. Compile. It works.
4. Add new Carbon C file to the bundle. Compile. And I get 1495  
errors starting with:


Building target “MyBundle” of project “TestApp” with configuration  
“Debug” — (1495 errors)

cd /Users/jesse/Desktop/TestApp
   /Developer/usr/bin/gcc-4.0 -x c-header -arch i386 -fmessage- 
length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks  
-O0 -Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/ 
MacOSX10.5.sdk -mfix-and-continue -mmacosx-version-min=10.5 - 
gdwarf-2 -iquote /Users/jesse/Desktop/TestApp/../builds/ 
TestApp.build/Debug/MyBundle.build/MyBundle-generated-files.hmap -I/ 
Users/jesse/Desktop/TestApp/../builds/TestApp.build/Debug/ 
MyBundle.build/MyBundle-own-target-headers.hmap -I/Users/jesse/ 
Desktop/TestApp/../builds/TestApp.build/Debug/MyBundle.build/ 
MyBundle-all-target-headers.hmap -iquote /Users/jesse/Desktop/ 
TestApp/../builds/TestApp.build/Debug/MyBundle.build/MyBundle- 
project-headers.hmap -F/Users/jesse/Desktop/TestApp/../builds/Debug - 
I/Users/jesse/Desktop/TestApp/../builds/Debug/include -I/Users/jesse/ 
Desktop/TestApp/../builds/TestApp.build/Debug/MyBundle.build/ 
DerivedSources -c /Developer/SDKs/MacOSX10.5.sdk/System/Library/ 
Frameworks/AppKit.framework/Headers/AppKit.h -o /var/folders/DI/ 
DIMbvaZQFpGmNuaJM2eybk+++TI/-Caches-/com.apple.Xcode.501/ 
SharedPrecompiledHeaders/AppKit-bawztsadvnkohkggpdwhgbqjwsmp/ 
AppKit.h.gch
In file included from /Developer/SDKs/MacOSX10.5.sdk/System/Library/ 
Frameworks/Foundation.framework/Headers/Foundation.h:12,
from /Developer/SDKs/MacOSX10.5.sdk/System/Library/ 
Frameworks/AppKit.framework/Headers/AppKit.h:10:
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/ 
Foundation.framework/Headers/NSObjCRuntime.h:124: error: syntax  
error before '@' token
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/ 
Foundation.framework/Headers/NSObjCRuntime.h:126: error: syntax  
error before '*' token
/Developer/SDKs/MacOSX10.5.sdk/System/Library/Frameworks/ 
Foundation.framework/Headers/NSObjCRuntime.h:127: error: syntax  
error before '*' token

...

Does anyone know what I should do if I want to use code from a .c  
file in my bundle?


Thanks,
Jesse___

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


This email sent to [EMAIL PROTECTED]




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]

Question about directory for Application Caches

2008-08-15 Thread Jason Coco

Hello All,

I'm a little unclear about this... maybe one of you has some ideas?

Currently, the call to

 NSSearchPathForDirectoriesInDomain(NSCachesDirectory,  
NSUserDomainMask, NO);


returns the path ~/Library/Caches. The FSFindFolder(...) call also  
returns the same thing. I noticed,
however, that a number of other applications (including XCode itself)  
are using the cache directory

returned by

 confstr(_CS_DARWIN_USER_CACHE_DIR, path, len);

instead of the old directory in ~/Library. In the XCode 3.1 release  
notes it even mentions that it now
uses this cache directory for "added security"... is there a  
recommended move to this directory
structure under /var/folders? Or do we listen to the return value of  
NSSearchPathForDirectoriesInDomain(...)?


I also noticed that NSTemporaryDirectory(...) returns the temp  
directory in /var/folders so I'm wondering
if there is a move to put all discardable files back into /var (where,  
IMO, they belong anyway... but hey). So...
do I use the result of the POSIX call or the Cocoa call? If Apple  
weren't starting to use the result of the
POSIX call themselves, I wouldn't care, but I'm curious now... any  
thoughts?


/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: Question about directory for Application Caches

2008-08-15 Thread Jason Coco


On Aug 15, 2008, at 11:11 , Jeff Johnson wrote:


Jason,

See the following threads for some discussion of these issues:

http://lists.apple.com/archives/Macnetworkprog/2008/Apr/msg00033.html

http://lists.apple.com/archives/Xcode-users/2008/Jul/msg00283.html


Interesting... thanks, Jeff. So I guess the answer is for speed/non- 
sensitive cache
data, maybe confstr(_CS_DARWIN_USER_CACHE_DIR, path, length) is the  
appropriate
call... and maybe for data that may need to actually reside in the  
filevault, regardless of
speed, the return value from the Cocoa call is more appropriate (~/ 
Library/Caches)?


I would like to point out a couple of interesting things, though...

1) ~/Library/Caches is world writable too... so as long as you're  
logged in, even if you have
your filevault armed, you're still gonna be somewhat vulnerable  
to cache attacks.
2) The new temporary directory (returned the same by  
confstr(_CS_DARWIN_USER_TEMP_DIR,...)
and NSTemporaryDirectory(...) is also outside the sphere of  
filevault /and/ your files there
are not necessarily erased on log-out. I think it's cleaned up  
with the computer boots (although it
may be deleted on shutdown, but I don't think so)... so if any  
sensitive information were written to
the temp dir and the application relied on it being cleaned by  
the OS, that could be an issue too if

your physical drive were compromised...

Too bad these aren't sysctl variables that could be set if security  
were more important to the user
than performance... I checked the darwin source and the directories  
returned by confstr(...) are

hard-coded into libc...

/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: Question about directory for Application Caches

2008-08-15 Thread Jason Coco


On Aug 15, 2008, at 12:21 , Jeff Johnson wrote:


On Aug 15, 2008, at 10:33 AM, Jason Coco wrote:


On Aug 15, 2008, at 11:11 , Jeff Johnson wrote:


Jason,

See the following threads for some discussion of these issues:

http://lists.apple.com/archives/Macnetworkprog/2008/Apr/ 
msg00033.html


http://lists.apple.com/archives/Xcode-users/2008/Jul/msg00283.html


Interesting... thanks, Jeff. So I guess the answer is for speed/non- 
sensitive cache
data, maybe confstr(_CS_DARWIN_USER_CACHE_DIR, path, length) is the  
appropriate
call... and maybe for data that may need to actually reside in the  
filevault, regardless of
speed, the return value from the Cocoa call is more appropriate (~/ 
Library/Caches)?


That sounds reasonable.


I would like to point out a couple of interesting things, though...

1) ~/Library/Caches is world writable too... so as long as you're  
logged in, even if you have
   your filevault armed, you're still gonna be somewhat vulnerable  
to cache attacks.


This is incorrect, FileVault or not. Where do you get that idea?


Oh my... I came to this conclusion because /my/ Caches directory was  
world-writeable. I checked
another local account on my machine and that Caches directory was also  
world-writeable. Finally,
I created a new account and checked, whereupon I discovered that it  
was read-write-exec only by
the owner. Hmm... seems like some dumb application is messing with my  
Caches directory permissions...

I'll have to check that out!

Thanks again, 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: creating files to write data to?

2008-08-15 Thread Jason Coco


On Aug 15, 2008, at 18:10 , FTB Accounts wrote:

Devon, thanks for your response. However, your suggestion still does  
not make the code work. No data is written to the file.



/* WRITE DATA TO FILE: THIS IS A TEST */
[fh writeData:@"THIS IS A TEST"];
[fh closeFile];


I simply was copying the advice given on a previous post. I have  
tried just about everything and can get nothing to work? has anyone  
on this list ever had success in writing to a local file, and if so  
can you show me the code you used?


Adding the @ just makes it an NSString constant... but writeData still  
requires (NSData *), not (NSString *). As was pointed out before, are  
you sure that you have
write permissions here? You should check your errors... also, try  
writing the location with basic system calls (just to test briefly)  
and check the return result and the

errno to see what might be the issue...?

Following up on what another poster suggested, is it possible to do  
this another way? For instance, if you are storing strings and binary  
data, is it possible to
write this file using an (NSMutableDictionary *)? You could write both  
your strings (NSString *) and data (NSData *) to a structure in memory  
(if you don't have keyed data, just use (NSMutableArray *) instead of  
(NSMutableDictionary *). If you're afraid of losing data or have to  
share the data through the file, maybe you could flush it every
time you make a change? Both the array and the dictionary respond to - 
(BOOL)writeToFile:(NSString *)path atomically:(BOOL)flag


/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: creating files to write data to?

2008-08-16 Thread Jason Coco


On Aug 15, 2008, at 19:35 , Andy Lee wrote:


On Aug 15, 2008, at 6:43 PM, Jason Coco wrote:
Adding the @ just makes it an NSString constant... but writeData  
still requires (NSData *), not (NSString *).


Argh!  Or perhaps, given the nature of this error, which I missed, I  
should say "Arg!"


Surely you got a compiler warning?  If you ignored that, surely a  
runtime error?


Check your errors, both at compile time and runtime (and treat  
warnings as errors).


Yeah... I was thinking the same thing... you /must/ have got  
warnings... eventually you would have gotten an Exception I think :)

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: creating files to write data to?

2008-08-17 Thread Jason Coco

Try this code... and then compare it to what you've written:

/* By the way: even this code will give you errors... PLEASE check  
your console... because you
are creating autorelease objects BEFORE you create an autorelease  
pool and that will ALWAYS
spam you console with warnings... methinks you're not looking in  
the right place if you say
the compiler didn't give you any warnings with your code and that  
you got no errors when you

ran your code... /jason */

#import 

int main (int argc, char const *argv[])
{
// path of the file to write to
NSString *path = @"/Users/cknorr/mytest/MYTEST/data.txt";

// contents of the file
NSString *data = @"THIS IS A TEST";

// write operation
NSError *error = nil;
	if( ![data writeToFile:path atomically:YES  
encoding:NSUTF8StringEncoding error:&error] ) {

NSLog(@"Error writing file: %@", [error localizedDescription]);
} else {
NSLog(@"File successfully written to %@", path);
}

return NSApplicationMain(argc, (const char**)argv);
}

On Aug 17, 2008, at 01:07 , FTB Accounts wrote:


Thanks, all for the responses.

First I changed the path to write to. The folder is writable. On  
GetInfo for the folder "MYTEST", I have set "Read & Write"  
permissions for:
You can, Owner, Group, & Others. Is there anything else I need to do  
to make it write to that folder?


As a side note, I am running an Apache server on the mac I am  
working on, and I can write PHP programs that will write to this  
directory.


However, this is still not working. I am not getting anything under   
"Errors and Warnings" in Xcode. Also the program loads. However,  
after running the Debugger does come up.


On debugger there are 5 listed.

0. asm objc_msgSend 0x90a594c0:1
1. ?
2. asm -[NSConcreteFileHandle initWithPath:flags:createMode:]  
0x92867509:1

3. asm +[NSFileHandle fileHandleForWritingAtPath:] 0x9287a5e6:1
4. THIS IS BROKEN DOWN IN SUB SECTIONS

[Arguments]
Value: 1
Variable: argc
Value: 0xba5c
Variable: argv
[Locals]
Value: 0x2cf58
Variable: fname
Summary: {(int)[$VAR length]} bytes
Value: 0x1f4c
Variable: fh
Summary: file descriptor: {(int)[$VAR fileDescriptor]}


Here is the current code I am running:

/* START CODE */

#import 

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

NSData *fname = "file:///Users/cknorr/mytest/MYTEST/data.txt";
NSFileHandle *fh=[NSFileHandle fileHandleForWritingAtPath:fname];
[fh writeData:@"THIS IS A TEST"];
    [fh closeFile];

   return NSApplicationMain(argc,  (const char **) argv);
}



--- On Sat, 8/16/08, Jason Coco <[EMAIL PROTECTED]> wrote:


From: Jason Coco <[EMAIL PROTECTED]>
Subject: Re: creating files to write data to?
To: "Andy Lee" <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED], cocoa-dev@lists.apple.com
Date: Saturday, August 16, 2008, 3:33 AM
On Aug 15, 2008, at 19:35 , Andy Lee wrote:


On Aug 15, 2008, at 6:43 PM, Jason Coco wrote:

Adding the @ just makes it an NSString constant...

but writeData

still requires (NSData *), not (NSString *).


Argh!  Or perhaps, given the nature of this error,

which I missed, I

should say "Arg!"

Surely you got a compiler warning?  If you ignored

that, surely a

runtime error?

Check your errors, both at compile time and runtime

(and treat

warnings as errors).


Yeah... I was thinking the same thing... you /must/ have
got
warnings... eventually you would have gotten an Exception I
think :)








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: What is Core Foundation, and other terminology/history questions.

2008-08-17 Thread Jason Coco


On Aug 18, 2008, at 01:09 , Sumner Trammell wrote:


Hi, can someone explain to me the philosophy/principles behind Core
Foundation? I'm just having a hard time seeing the overall
relationship between Carbon, Core Foundation, and Cocoa.


It's basically a C-language version of the Foundation Framework. For a
pretty good explanation of CoreFoundation, you can read this guide:

http://developer.apple.com/documentation/CoreFoundation/Conceptual/CFDesignConcepts/CFDesignConcepts.html#/ 
/apple_ref/doc/uid/1122



A few (stupid) questions I have are:

+ Why was Core Foundation invented?


It was created to help facilitate cross-platform application  
development as well as transitioning C applications to Foundation/ 
Objective-C. It's
also very useful if you're creating a library that is meant to be used  
both by Objective-C applications and C applications.



+ What did developers use BEFORE Core Foundation, back in the NEXTSTEP
days? There was no Core Foundation back then, correct? Everything was
pure Obj-C/Cocoa?



Yes, in those days you used NextStep's Object-C framework to develop.  
If you want to develop GUI's on Mac OS X you still have to use
either Cocoa or Carbon. CoreFoundation only provides functionality for  
things in the Foundation Framework for Cocoa. It also provides

some base classes to the CoreServices Framework for Carbon.


+ When Apple and NeXT merged, the Carbon and Cocoa (before they got
those names) APIs needed merging? And so a common base was created?
And it is Core Foundation?


Sort of... it's easiest just to think of it as the C version of the  
Foundation Framework (although I suppose that's a bit of an over- 
simplification
since there are some things you need to drop down to CoreFoundation to  
do even from the Foundation Framework... e.g., directly stopping

a RunLoop or adding a socket as a RunLoop source).

BTW, no questions are stupid when you're asking things like why, or  
please explain. For more good information, however, I suggest reading
the above guide and then checking out the CoreFoundation section of  
Apple's Developer Reference Library:


http://developer.apple.com/documentation/CoreFoundation/index.html#// 
apple_ref/doc/uid/TP3440-TP3421


HTH, /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: CF Network memory leak? Or false positive in Leaks?

2008-08-18 Thread Jason Coco


On Aug 17, 2008, at 22:40 , Lawrence Johnston wrote:


Hey everybody,

I've got a situation I'm kind of puzzling over. If I run my program  
though leaks, I'm getting a leak at a certain point, but where it's  
coming from is really confusing me.


I've pulled the urlRequest entirely out into a new dummy program and  
I'm still getting a leak here.


This is the code I'm using:
[snip]

and then if I run it using a leak I'm getting a leak, for example  
the last time I got a leak of size 3.58KB at 0.16 minutes (9.6  
seconds).


The leak is as follows:

#  Category   EventType  Timestamp   Address
SizeResponsible Library Responsible Caller
0  GeneralBlock -3584   Malloc 00:05.5380x83b200
3584CFNetwork httpWrFilterOpen
1  GeneralBlock -3584   Free00:14.5390x83b200   
-3584libSystem.B.dylib   _pthread_body
2  GeneralBlock -2048   Realloc00:14.7030x83b200
2048CFNetworksendDidReceiveDataCallback



The weird part is as far as I can tell the memory in question is  
actually getting released! (at 14 seconds)


So is this some sort of weird false positive? Or am I missing  
something?


It looks to me like the 3.58KB was released... that's number 1 on your  
list, so there is not leak. The memory you have
allocated (2048 bytes) looks like it's the read buffer that was  
created for you and which you either haven't read yet
or simply hasn't been released yet. CFNetwork may also keep the buffer  
around in case you call it again to avoid

allocating and reallocating memory all the time.

/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: Hex representation of NSString

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 07:18 , Robert Černý wrote:

Actually,I'm trying to debug some weird problems with clipboard. My  
problem
is that data copied into clipboard from legacy java application  
doesn't

match data pasted into Cocoa application. I've got data with accented
characters which gets converted through MacOS Roman encoding even  
the visual

representation in java is correct.



If you want to print the string as hexadecimal without any  
conversions, you can do
something like the following (keep in mind this is showing you  
basically the

UCS-2 version of the string):

void dumpString(NSString *str)
{
NSUInteger len = [str length];
unichar *chars = malloc(len * sizeof(unichar));
[str getCharacters:chars];
uint i;
printf("NSString at %08p = { ", str);
for( i = 0; i < len; i++ ) {
if( i % 7 == 0 && i > 0 )
printf("\n ");
printf("0x%04X ", chars[i]);
}
printf(" }\n");
free(chars);
}

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: Hex representation of NSString

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 10:18 , Clark Cox wrote:

On Mon, Aug 18, 2008 at 5:38 AM, Jason Coco <[EMAIL PROTECTED]>  
wrote:


On Aug 18, 2008, at 07:18 , Robert Černý wrote:


Actually,I'm trying to debug some weird problems with clipboard. My
problem
is that data copied into clipboard from legacy java application  
doesn't
match data pasted into Cocoa application. I've got data with  
accented
characters which gets converted through MacOS Roman encoding even  
the

visual
representation in java is correct.



If you want to print the string as hexadecimal without any  
conversions, you

can do
something like the following (keep in mind this is showing you  
basically the

UCS-2 version of the string):


Not UCS-2, UTF-16. (The distinction is important if the string
contains any characters outside of the BMP.


Yeah, my bad... UTF-16, not UCS-2


void dumpString(NSString *str)
{
  NSUInteger len = [str length];
  unichar *chars = malloc(len * sizeof(unichar));
  [str getCharacters:chars];
  uint i;


i should be NSUInteger as well.


I don't think that really matters all that much, just a matter of
style mostly. I think /should/ is strong. It could be NSUInteger
or just int or uint32_t or unsigned int or whatever... it's just
a counter for a simple debugging example, right :)


  printf("NSString at %08p = { ", str);


No need to use %08p, just use %p.


I wanted %08p... it was on purpose. I like my debugging messages
to line up properly :)



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: Hex representation of NSString

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 11:38 , Clark Cox wrote:

On Mon, Aug 18, 2008 at 7:38 AM, Jason Coco <[EMAIL PROTECTED]>  
wrote:


On Aug 18, 2008, at 10:18 , Clark Cox wrote:

On Mon, Aug 18, 2008 at 5:38 AM, Jason Coco <[EMAIL PROTECTED]>  
wrote:


On Aug 18, 2008, at 07:18 , Robert Černý wrote:

Actually,I'm trying to debug some weird problems with clipboard.  
My

problem
is that data copied into clipboard from legacy java application  
doesn't
match data pasted into Cocoa application. I've got data with  
accented
characters which gets converted through MacOS Roman encoding  
even the

visual
representation in java is correct.



If you want to print the string as hexadecimal without any  
conversions,

you
can do
something like the following (keep in mind this is showing you  
basically

the
UCS-2 version of the string):


Not UCS-2, UTF-16. (The distinction is important if the string
contains any characters outside of the BMP.


Yeah, my bad... UTF-16, not UCS-2


void dumpString(NSString *str)
{
NSUInteger len = [str length];
unichar *chars = malloc(len * sizeof(unichar));
[str getCharacters:chars];
uint i;


i should be NSUInteger as well.


I don't think that really matters all that much, just a matter of
style mostly. I think /should/ is strong. It could be NSUInteger
or just int or uint32_t or unsigned int or whatever...


If the length is an NSUInteger, then the counter should be as well.


it's just  a counter for a simple debugging example, right :)


Indeed, but unless there's a good reason, using different types for
the index and the limit is not a good idea.


This is true... I guess using good habits are important even when
building a quick & dirty little debugging example... it really does suck
when your debugging code has bugs that make you chase your tail :)




printf("NSString at %08p = { ", str);


No need to use %08p, just use %p.


I wanted %08p... it was on purpose. I like my debugging messages
to line up properly :)


Then what happens when you build 64-bit? :)


Cry? :)

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: Clearing a Memory Buffer?

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 09:19 , Dave wrote:


Hi All,

I'm fairly new to Cocoa and was wondering if there are OS functions  
to Copy and Clear/Fill Memory available?


I've tried searching for obvious names like MemoryZero, ZeroMemory,  
CopyMemory etc. but can't seem to find anything.


bzero(3), bcopy(3)

memset(3), memcpy(3), memmove(3)

strlcmp(3), strlcat(3)



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: NSString Question

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 10:54 , Dave wrote:


Hi,

I'm tring to create an NSString object from data contained within a  
file. The following code attempts to do this. The data is read from  
the file OK and all the size information etc. is OK.


Here is a code snippet:

myOSStatus = [self ReadUInt32LEFromPosition: myCurrentFilePosition +  
28 IntPtr:&myBufferSize];

myStringSize = (myBufferSize / 2) + 1;
myStringBufferPtr = malloc(myBufferSize + 2);
bzero(myStringBufferPtr,myBufferSize + 2);

myOSStatus = [self ReadFromPosition: myCurrentFilePosition + 40  
ForSize: myBufferSize BufferPtr:myStringBufferPtr];


[thePropertiesInfoPtr->mNameString initWithCharacters:  
myStringBufferPtr length:myStringSize];


-

thePropertiesInfoPtr pointer to a C Structure that contains the  
following member:


NSString*   mNameString;

When the initWithCharacters method is called, the variables are  
setup as follows:


myBufferSize = 54
myStringSize = 28
myStringBufferPtr is a pointer the following:

41 00 42 00 43 00 44 00 45 00 46 00 47 00 48 00
49 00 4A 00 4B 00 4C 00 4D 00 4D 00 4E 00 4F 00
50 00 51 00 52 00 53 00 54 00 55 00 56 00 57 00
58 00 59 00 5A 00 00 00

But I get an Access Error when I run it. Could someone tell me what  
I am doing wrong and how I can correct it?


Did you allocate your string first?

[[thePropertiesInfoPtr->mNameString alloc]  
initWithCharacters:myStringBufferPtr length:myStringSize];


If you haven't allocated your mNameString variable, chance are it  
points to 0x00 and that is why you

are getting an access violation...

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: Problem with fileAttributesAtPath

2008-08-18 Thread Jason Coco

If you're using 10.5 you can try the method:

-(NSDictionary *)attributesOfItemAtPath:(NSString *)path error: 
(NSError **)error


This way you will get a description of what is failing from the  
NSError object. You can use it like this:


NSError *theError;
NSDictionary *fileAttributes = [manager  
attributesOfItemAtPath:fullPath error:&theError];


if( fileAttributes != nil ) {
// do your things
} else {
	NSLog(@"Error retrieving file attributes for %@: %@", fullPath,  
[theError localizedDescription]);

}

That should help you track down what might be going wrong at least

On Aug 18, 2008, at 15:24 , Nicolas Goles wrote:

Hi guys, I am trying to get fileAttributesAtPath using this code:  
(files

contains the path to the directory that was enumerated )

   while(object = [dirEnumerator nextObject])
   {

   //First We craft the whole path for a single object

   NSString *fullPath = [files  
stringByAppendingString:object];


   NSLog(@"%@",fullPath); //Log the full path just to be  
sure it's

correct

   if(!fullPath)
   {
   NSLog(@"Error when appending strings");
   }

   //Try to obtain fileAttributes
   NSDictionary *fileAttributes = [manager
fileAttributesAtPath:fullPath traverseLink:NO];

   if( fileAttributes != nil)
   {

   NSString *filetype = [fileAttributes
objectForKey:NSFileType];
   NSLog(@"%@",filetype);
   }

   if(!fileAttributes)
   {
   NSLog(@"it's nill");
   }
}

The thing is that my fileAttributes it's always = nil so I always  
get "it's

nill"  on the console.

Could anyone point me at what I'm doing wrong ???

Thanks!! :)

--
-Nicolas Goles
___

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


This email sent to [EMAIL PROTECTED]




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: NSString Question

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 15:49 , Ken Thomases wrote:


On Aug 18, 2008, at 12:28 PM, Jason Coco wrote:

[[thePropertiesInfoPtr->mNameString alloc]  
initWithCharacters:myStringBufferPtr length:myStringSize];


Um, that's nonsensical.  I think you meant:

thePropertiesInfoPtr->mNameString = [[NSString alloc]  
initWithCharacters:myStringBufferPtr length:myStringSize];


Oh yes, yes I did... sorry about that, Dave! Not enough sleep last  
night, not enough caffeine this morning :)


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: Including frameworks in your app bundle

2008-08-18 Thread Jason Coco


On Aug 18, 2008, at 19:59 , Nick Pilch wrote:

I've been searching, but I can't find the documentation explaining  
how to include frameworks in your app bundle (third-party  
frameworks, for example), so that your user does not have to install  
these frameworks. Could someone point me at the correct  
documentation/build settings? Thanks.


This is probably better for the XCode group, but check out this  
document:


http://developer.apple.com/documentation/MacOSX/Conceptual/BPFrameworks/Tasks/CreatingFrameworks.html

It explains what you need to do to embed frameworks in your application.

HTH, 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: Best Way to Handle Properties?

2008-08-19 Thread Jason Coco


On Aug 19, 2008, at 13:02 , Dave wrote:


My specific questions are:

Is the NSString allocation and initWithCharacters code the best way  
to do this? If so, what would the setter look like in this case? If  
not what is a better way of doing it?


Hey Dave,

I don't think that initWithCharacters is what you want... that expects  
an array of unichar characters, which isn't what you said you had.  
Since you're doing the encoding in your other function, and you know  
what it is, just use the initWithBytes function and the specific  
encoding. For example (assuming your byte array was in UTF-16BE:


char *buf = /* initialized and filled somewhere else */
size_t buf_len = /* set somewhere else */

NSString *myString = [[NSString alloc] initWithBytes:buf  
length:buf_len encoding:NSUTF16BigEndianStringEncoding];


Just remember, the length is the actual number of bytes (including the  
0x00 bytes in the array), not the number of code points or the number  
of characters.


/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: Preventing windows from being dragged

2008-08-21 Thread Jason Coco

Wow, I hope not :) Why would you want to do this?

On Aug 21, 2008, at 21:10 , Mike wrote:

Is there any way to prevent a Cocoa window from being dragged while  
it is onscreen?


Thanks,

Mike
___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jason.coco 
%40gmail.com


This email sent to [EMAIL PROTECTED]




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: Preventing windows from being dragged

2008-08-21 Thread Jason Coco


On Aug 21, 2008, at 22:37 , Mike wrote:


For a Kiosk application.


Ah, that makes sense... well, I'm not really sure about Cocoa. I think  
you can override the drag method in Carbon, but not really sure about  
that either.


In case you haven't seen it yet, there is a technote about kiosk stuff  
here:


http://developer.apple.com/technotes/tn2002/tn2062.html

It may have what you need...

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: NSString and special characters

2008-08-22 Thread Jason Coco


On Aug 22, 2008, at 05:26 , Vladimir Sokolov wrote:


2008/8/22, Bill Bumgarner <[EMAIL PROTECTED]>:


On Aug 22, 2008, at 1:00 AM, Vladimir Sokolov wrote:


Hello All,

I am working on a command line tool. I use
NSArray *params = [[NSProcessInfo processInfo] arguments]
to get a list of command line parameters.
Then I use
NSString *param1 = [params objectAtIndex:1];
to get it.

But when I pass for example >...myapplication test$test
param1 got "testest" instead of  ""test$test"

It means as I understand that $ is interpreted as special character.

So my question is how to pass a parameter with $ inside?
And are there any other special characters which are interpreted as
special
one?



To be clear, this has nothing to do with NSString and everything to  
do with

how the shell parses command lines.

As Michael D alluded to, the shell is seeing $test and "expanding"  
the $t
to be the value of -- typically -- the environment variable 't',  
which

doesn't have a value and, thus, you end up with 'testest'.

That is, all argument processing has been completed long before your
command line tool is even launched.

Now, the syntax and rules for substitution change depending on the  
shell

used and how your command line tool is launched.  As well, APIs for
launching processes such as NSTask, popen(), system(), and the  
various

fork()/exec*() combinations may or may not behave similarly.

So -- the real questions:

What is launching your command line tool?

Do you really need an argument with a $ character in it?

Most command line tools avoid such characters for the reasons  
stated above.


Have you read this book?  http://tinyurl.com/6kxxgc

b.bum




Thanks for your messages.

Now I see my problem ( Learn Unix! :))

The $ character is part of the user password, that is why I need to  
use it.

Now for the test I am launching my tool in bash.


If you're using bash you can surround the argument in single quotes  
(e.g., 'test$test') and it won't do any expansion.


However, it's a really bad idea to pass a password on the command line  
in Unix in general because any application can read your

process's argument list without any special privileges.

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: failing opening socket

2008-08-22 Thread Jason Coco


On Aug 22, 2008, at 13:12 , Luca Ciciriello wrote:

Hi all.

I'm porting a Linux project (using sockets to implement a ping  
function) on Mac OS X. My problem is that the function:


int sock_icmp = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);

returns always -1.

Where is my mistake? For me is the very first time using socket on  
Mac.


Thanks in advance for any idea.


Hi Luca,

This isn't really a Cocoa question... you would probably get faster/ 
more responses for these kinds of questions on the
Darwin-dev mailing list... but, you should do something like this (at  
least to debug):


int sock_icmp;
if( (sock_icmp = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == -1 ) {
fprintf(stderr, " --> Error opening socket: %s\n", strerror(errno));
return -1;
}

However, your problem most likely is EACCES... in darwin, SOCK_RAW  
requires root privileges to open.


HTH, 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: Preventing windows from being dragged

2008-08-22 Thread Jason Coco


On Aug 22, 2008, at 15:46 , Charles Srstka wrote:


On Aug 21, 2008, at 10:02 PM, Ricky Sharp wrote:


(1) never ever ever capture the display when using AppKit.


This appears to be incorrect, as Apple seems to endorse and even  
provides sample code for capturing the screen while using AppKit:


It also appears that Leopard has added some support for this within  
AppKit itself... three new methods were added to NSView:


-(BOOL)enterFullScreenMode:(NSScreen *)screen withOptions: 
(NSDictionary *)options;

-(void)exitFullScreenModeWithScreen:(NSScreen *)screen;
-(BOOL)isInFullScreenMode;

I just tried them out and they were pretty easy and seemed to work  
well enough. I didn't even bother with the options, just sent:


if( ![myView enterFullScreenMode:[NSScreen mainScreen]  
withOptions:nil] ) { /* error out */ }

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: CFBoolean

2008-08-24 Thread Jason Coco


On Aug 24, 2008, at 21:33 , Chris Idou wrote:


How do I create a property in the user defaults of type boolean?

Internally it seems to use a NSCFBoolean which is an undocumented  
type. If I make the assumption it is the same as a CFBoolean, and  
overlooking the oddness of having to fall back to Carbon for such a  
fundamental thing, the documentation of CFBoolean doesn't seem to  
provide a documented method for creating one.


You don't... there is only kCFBooleanTrue and kCFBooleanFalse. To  
assign a value to a boolean, do:


CFBooleanRef thisOneIsTrue = kCFBooleanTrue;
CFBooleanRef thisOneIsFalse = kCFBooleanFalse;

To test for true or false, you can use:

CFBooleanGetValue(theBooleanValue) which returns a Boolean type...

HTH, 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: NSAppleScript shies away from porcupines

2008-08-26 Thread Jason Coco


On Aug 26, 2008, at 04:19 , Gerriet M. Denkmann wrote:



On 26 Aug 2008, at 15:04, Andrew Farmer wrote:


On 26 Aug 08, at 00:39, Gerriet M. Denkmann wrote:

I want to open some file:

source =
"tell application "SomeApp"...


You're making things harder than they need to be.

[[NSWorkspace sharedWorkspace] openFile:@"/path/to/file"  
withApplication:@"SomeApp"];


As to AppleScript's Unicode support, I wouldn't be surprised if it  
were still unreliable.


Sorry for the badly abridged example. Actually I want to do more  
than just open the file.
Or is it definitely impossible to use un-American pathnames in  
AppleScript?



I did a test with this... it seems that the code to resolve the alias  
in AppleScript doesn't like
non-latin encoded pathnames. If you give it a regular file and don't  
ask it to resolve an
alias, it happily works... even with non-English (I don't know Thai?  
so I used Japanese characters
for the test, but I'm assuming it works pretty much the same--I know,  
dangerous to assume such
things from computers, right? :) )... but if you ask it to resolve an  
alias, it dies with the same
error message that you were getting (String encoded with \u in  
place of actual UTF-16

values).

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: NSAppleScript shies away from porcupines

2008-08-26 Thread Jason Coco


On Aug 26, 2008, at 16:54 , Gerriet M. Denkmann wrote:



On 27 Aug 2008, at 02:09, has wrote:


Gerriet M. Denkmann wrote:


When I try in Script Editor:

set macpath to POSIX file "/Volumes/เม่น/Users" as Unicode  
text


and do "Compile", then this gets transformed into:

set macpath to file " ‘ßÀÏ:Volumes:‡¡Ëπ:Users" as Unicode  
text


Sounds like you're on 10.4 or earlier.

Correct. I should have stated this in my posting.


The test that I did was under 10.5.4, so the "as alias" coercion still  
definitely

fails with Unicode even in Leopard.




AppleScript only supports Unicode source code in 10.5+; previously  
it used the host system's primary encoding, which is why your non- 
MacRoman(?) characters are getting mangled. If you must use  
AppleScript for some reason, either write your unicode string  
literals using raw «data utxt...» format, or pass in unicode  
strings as parameters to an Apple event constructed via  
NSAppleEventDescriptor.


I might try this.
But it is good to know that AppleScript cannot be used on 10.4.


IMO, this is a pretty significant shortcoming for AppleScript.  
Hopefully they fix that soon. Maybe a bug report should be filed?


/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: NSFileManager Help

2008-08-27 Thread Jason Coco


On Aug 27, 2008, at 20:43 , J. Todd Slack wrote:


Hi All,

It simply does not create the directory. This is code that I had in  
another project that worked.


What am I missing?


Does the parent directory exist already (~/Application Support/Ring- 
Maker)? If not, this
call will fail. However, since you're using 10.5 you should use this  
method:


-(BOOL)createDirectoryAtPath:(NSString*)path  
withIntermediateDirectories:(BOOL)createIntermediates attributes: 
(NSDictionary*)attributes error:(NSError**)error;


Here you can specify YES to create the top levels even if it doesn't  
exist and if it does fail, you can interrogate the NSError object to  
see why.


HTH, 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: NSFileManager Help

2008-08-27 Thread Jason Coco


On Aug 27, 2008, at 21:08 , J. Todd Slack wrote:


Hi Jason,

It simply does not create the directory. This is code that I had  
in another project that worked.


What am I missing?


Does the parent directory exist already (~/Application Support/Ring- 
Maker)? If not, this
call will fail. However, since you're using 10.5 you should use  
this method:


-(BOOL)createDirectoryAtPath:(NSString*)path  
withIntermediateDirectories:(BOOL)createIntermediates attributes: 
(NSDictionary*)attributes error:(NSError**)error;


I saw this, but if I have to deploy on 10.4, will this call fail on  
10.4 since it is new in 10.5?


No, it won't. You could check programmatically for 10.5 and call it  
(at least then, if it fails on 10.5 you will know why) and fall back  
to the other call on 10.4.


But you were right, the Ring-Maker Directory did not exist. Not I  
fixed it.


Yeah, that's usually the problem when path creation fails. I never  
understood why the mkdir system call didn't just automatically create  
intermediate directories... I think that would have been a much more  
clever design. Plus ENOENT is a fairly useless error response, but I  
digress :)


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: NSFileManager Help

2008-08-27 Thread Jason Coco


On Aug 27, 2008, at 21:19 , J. Todd Slack wrote:


Hi Jason

-(BOOL)createDirectoryAtPath:(NSString*)path  
withIntermediateDirectories:(BOOL)createIntermediates attributes: 
(NSDictionary*)attributes error:(NSError**)error;


I saw this, but if I have to deploy on 10.4, will this call fail  
on 10.4 since it is new in 10.5?


No, it won't. You could check programmatically for 10.5 and call it  
(at least then, if it fails on 10.5 you will know why) and fall  
back to the other call on 10.4.


I was thinking about this, but I dont quite get what #if I would  
use. I know there is #if (MAC_OS_X_VERSION_10_3) as example, but  
would I have to check like  min MAC_OS_X_VERSION_10_4 max  
MAC_OS_X_VERSION_10_4_11 (Where there .11 releases or .6?) and then  
another conditional of greater MAC_OS_X_VERSION_10_5?


You wouldn't really have to do this. Just compile with the 10.5 SDK on  
Leopard but set your deployment target for 10.4. Then call  
respondsToSelector to see if the NSFileManager that you're using can  
respond to the newer call. If not, use the older call. You don't need  
any #ifdef's or anything like that. Take a look at this document:


http://developer.apple.com/documentation/DeveloperTools/Conceptual/cross_development/Introduction/chapter_1_section_1.html#/ 
/apple_ref/doc/uid/1163-BCICHGIE


/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: Get current amount of available RAM

2008-08-27 Thread Jason Coco


On Aug 28, 2008, at 00:31 , Alex Kac wrote:

I need to check for free RAM before performing a specific operation.  
I've Googled and checked in the docs and I suspect its my  
terminology that's just out of whack.


So what is the best way to find out how much available RAM is  
available in a Cocoa app?


You can also get some information with these calls, although I don't  
know how useful it will be in your situation:


// Amount of physical memory installed -- requires 10.5
unsigned long long memory = [[NSProcessInfo processInfo]  
physicalMemory];


// Amount of memory allocated to user space
unsigned long long memory;
size_t mem_len = sizeof(memory);
int mib[2];

mib[0] = CTL_HW;
mib[1] = HW_USERMEM;
if( sysctl(mib, 2, &memory, &mem_len, NULL, 0) == -1 ) {
 perror("sysctl");
}

It doesn't really tell you about what's actually available to the  
application, though :/


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: understanding conversions between CF and NS datatypes

2008-08-29 Thread Jason Coco


On Aug 29, 2008, at 13:38 , Allen Curtis wrote:
The problem:  I found that if you release the CFMutableArray, you  
also loose

the NSMutableArray

Question:
1. Where can I get a better understanding of the data conversion  
between

these different frameworks?
2. Ultimately the device path names will appear in a ComboBox. Was it
necessary to convert the CFMutableArray to a NSMutableArray for the
datasource function?


It's more convenient to do it this way... however, you were just  
casting the

types, not converting them. You could do something like this:

serialPorts = [(NSArray*)devicePaths copy];
CFRelease(devicePaths);

Or you could just retain your serialPorts object:

serialPorts = (NSArray *)devicePaths;
[serialPorts retain];
CFRelease(devicePaths);

/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: NSString/NSMutable String Concatenation

2008-09-03 Thread Jason Coco


On Sep 3, 2008, at 17:57 , Michael Stearne wrote:


Hi.

I'm new to OS X development and Objective C.  I have a NSString (or
NSMutableString if that is wiser) and I would like to add text on to  
the end

of it.

In PHP it would be something like:
$myString=$myString." more stuff";

I have looked around for docs on this but they are confusing (based  
on my

newbie status and background).

If there a simple equivalent of the code above for Objective C?


You can use the -(NSString *)stringByAppendingString: 
(NSString*)theString method:


NSString myNewString = [myOldString stringByAppendingString:@" more  
stuff"];


Don't forget to retain myNewString if you want it to stick around for  
a while. You could also do:


myString = [myString stringByAppendingString:@" more stuff"];

but if myString wasn't created by a string constant @"..." you will  
obviously be leaking (unless the original myString was

also autoreleased already).

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: Accessing SDL Frameworks Bundled with Leopard...

2008-09-04 Thread Jason Coco


On Sep 5, 2008, at 00:04 , John Joyce wrote:

Does anybody know any official or proper way to link to the SDL  
framework that is bundled in the root library in Leopard?

/Library/Frameworks/SDL.framework
is surprisingly, there!


I don't have any such directory on my installation of Leopard. Another  
application probably installed this there (/Library/Frameworks is for
3rd-party, shared frameworks usually). You should find the source and  
use that because if your application doesn't come with this framework,
chances are it will fail to load on somebody else's computer (like  
mine). But, once you have the framework, you just drag it into shared  
frameworks

in XCode or add it as a -framework flag to gcc.

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: Finding out in code how much memory my application uses

2008-09-08 Thread Jason Coco
I would suggest using the DTrace stuff... either using instruments or  
using DTrace scripts directly... there is tons of good information  
about DTrace at google.


You can also look at /usr/include/mach directory for various mach  
calls regarding process statistics, including memory usage (all the  
stats can be grok'd from there including phyiscal memory used, virtual  
memory used, wired memory used as well as faults and other memory  
info)...


On Sep 8, 2008, at 21:04 , Aaron VonderHaar wrote:


Hi,  I am trying to write some automated scenario tests that verify
that my application meets it's the memory usage constraint
requirements.

What API is available to find out how much memory an
application/process/thread has allocated?

I have looked at the documentation for NSZone, NSProcessInfo,
NSThread, NSAutoreleasePool, NSTask, NSApplication, the "Interacting
with the Operating System" guide and the "Memory Management
Programming Guide for Cocoa" guide but I have not found any
information about how to find out the number of pages, bytes or
objects that are in use.

Has anyone accessed this type of information in their own programs?

Thanks,
--Aaron VonderHaar
___

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


This email sent to [EMAIL PROTECTED]




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: BOOL array

2008-09-09 Thread Jason Coco


On Sep 9, 2008, at 06:24 , Alex Reynolds wrote:

I am currently putting 320 to 480 character long NSString *  
instances into an NSMutableArray. The characters are 0 or 1.


I guess I could use an int array, but I'm looking to speed up my app  
and reduce storage. Is it possible to create a BOOL array that can  
be put into an NSMutableArray?


You can use a BOOL array or an int array... or an array of uint8_t.  
BOOL is just a signed char anyway. Just wrap the array in an NSValue  
object when you put it into the NSMutableArray:


BOOL boolArrayOne[320];

/* ... */

NSValue *boolArrayOneAsValue = [NSValue valueWithPointer:&boolArrayOne];

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: C/Obj-C API Confusion

2008-09-10 Thread Jason Coco


On Sep 10, 2008, at 17:31 , J. Todd Slack wrote:


Hi Sherm,

So if I have an objective C class, how can I call a .c class? and  
pass my arguments from the objective-c class?


What kind of ".c class"? And what kind of arguments? It might help to  
give the prototype of some of the functions
that you want to call in the QTKit, or at least the names of the  
functions :) Then people can help you more easily
understand what would need to be translated from Obj-C objects to  
various other types and how to best do it.


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: GDB Problems

2008-09-11 Thread Jason Coco


On Sep 12, 2008, at 00:10 , Bridger Maxwell wrote:

Woops. I tried to reply to this thread a while ago, but I wasn't  
watching
what I was doing and accidentally replied specifically to Ken. Sorry  
Ken! I

am still having this issue though.


I suspect you've recently installed a haxie, input manager, third- 
party
kernel extension or other piece of software which modifies the  
behavior of
nearly all applications on your system.  It seems to be  
interfering with
gdb.  If you can figure out what it is, disable or uninstall it  
and reboot.



I don't think I have any unusual kernel extensions installed. This  
is a work
computer and my installation is typical of almost everyone else at  
work.


What is the output of "kextstat -k" ?

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: App name from Bundle Identifier?

2008-09-12 Thread Jason Coco


On Sep 12, 2008, at 18:26 , Citizen wrote:


On 12 Sep 2008, at 22:06, Dave DeLong wrote:

I've been looking inside NSWorkspace, NSBundle, NSApplication,  
NSFileWrapper, etc for some way to get the display name of an  
application from it's bundle identifier, but I can't find  
anything.  Is there a way to do this?  For example, if I have  
"com.apple.InterfaceBuilder3", I'd like to get back "Interface  
Builder".


I've just implemented some code to do this:

- (NSString *) name
{
NSBundle * appBundle = [NSBundle bundleWithPath:[self absolutePath]];
	NSString * name = [appBundle  
objectForInfoDictionaryKey:@"CFBundleDisplayName"];
	if (!name) name = [appBundle  
objectForInfoDictionaryKey:@"CFBundleName"]; // this failed for  
"Gimp" so...
	if (!name) name = [appBundle  
objectForInfoDictionaryKey:@"CFBundleExecutable"];
	if (!name) name = [[[self absolutePath]  
stringByDeletingPathExtension] lastPathComponent];

if (!name) name = @"unknown";

return name;
}

- (NSString *) absolutePath
{
	return [[NSWorkspace sharedWorkspace]  
absolutePathForAppBundleWithIdentifier:[self bundleIdentifier]];

}

I don't know if the CFBundleExecutable idea is a good one or not.
You could nest the conditions to make it more efficient (I just went  
for readability).


I think that the file manager way is the better choice because you get  
the localization for free... (assuming the app has a localized name).

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: 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 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: Getting NSTimeZone for a given NSDate

2008-09-15 Thread Jason Coco


On Sep 15, 2008, at 03:49 , Markus Spoettl wrote:


Hi List,

 I just know it must be there but I can't see it. How can I get to  
the NSTimeZone for a given NSDate. When using -description: the date  
got a time zone, so it's stored in there but how on earth can I get  
to it? I only need the GMT offset (numerically, not as string), in  
case there's a simpler way to obtain this.


All NSDate objects are stored as seconds since the reference date (Jan  
1 1970 00:00 GMT) and so are always GMT. The description is using the  
default time zone to adjust the date. You can get the default time  
zone with [NSTimeZone defaultTimeZone] and then you can get the offset  
with -(NSTimeInterval)secondsFromGMT.


HTH, 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: Getting NSTimeZone for a given NSDate

2008-09-15 Thread Jason Coco


On Sep 15, 2008, at 05:35 , Jean-Daniel Dupas wrote:



Le 15 sept. 08 à 09:56, Jason Coco a écrit :



On Sep 15, 2008, at 03:49 , Markus Spoettl wrote:


Hi List,

I just know it must be there but I can't see it. How can I get to  
the NSTimeZone for a given NSDate. When using -description: the  
date got a time zone, so it's stored in there but how on earth can  
I get to it? I only need the GMT offset (numerically, not as  
string), in case there's a simpler way to obtain this.


All NSDate objects are stored as seconds since the reference date  
(Jan 1 1970 00:00 GMT) and so are always GMT. The description is  
using the default time zone to adjust the date. You can get the  
default time zone with [NSTimeZone defaultTimeZone] and then you  
can get the offset with -(NSTimeInterval)secondsFromGMT.


It's conceptualy right, but just for info, NSDate do not store the  
value as a UNIX timestamp, but as a Core Foundation Absolute Time  
which is a double that represents the number of seconds since the  
reference date which is 00:00:00 1 January 2001


Oh yes yes, I actually knew it wasn't since the epoch, just very  
tired :-) but yeah, seconds since 1 Jan 2001 not 1970! That'll teach  
me to expand when I'm missing a lot of sleep... had I just said  
"...since the reference date..." I would have been fine :)


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: 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: 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: async NSOperation and NSOperationQueue

2008-09-15 Thread Jason Coco


On Sep 15, 2008, at 11:02 , John Love wrote:
I must be doing something terribly wrong, because when I start up  
the NSOperationQueue that does some time consuming calculations, I  
do not get back control of my application until after the lengthy  
calculation is complete.  Here are the relevant code snippets:


- (void) calculateWorksheetRow:(id)data {
// takes a long time here
}

- (void) startQueue {
theQueue = [[[NSOperationQueue alloc] init] autorelease];
theOp = [[NSInvocationOperation alloc] initWithTarget:self
	
selector:@selector(calculateWorksheetRow:)

   object:nil];
[theQueue addOperation:theOp];
}


Couple of things... you don't wanna create a queue every time. You  
should

pretty much have just one queue that you add NSOperation objects to. You
probably want to re-write this to be a singleton object that you get  
from your

app controller or some other relevant place.

Also, you most definitely do not want to autorelease your queue. It  
will end
up going away on you when you least want it to or expect it to. Create  
your
queue somewhere (hopefully in your app controller or somewhere like  
that)
and then release it when you're absolutely sure that all your  
operations have

run and you don't want to ever add any more.

You /should/, however, autorelease your NSOperation since your queue
will retain it when you add it and release it when it completes.



- (void) stopQueue {
[theQueue cancelAllOperations];

// [theQueue release];   // [ ... autorelease]
[theOp release];
}


You should probably autorelease your Op (unless you want to query it  
in the
future after it completes, in which case you should release it when  
you're finished
with it). This case will also only release the last operation from  
your loop and

all the others will have been leaked.



- (void) startCalculation { 
int row;

for (row=1; row < 100; row++) {
 // stuff here
[self startQueue];   // start new thread
 // [theQueue waitUntilAllOperationsAreFinished];
}

// more stuff
}




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: async NSOperation and NSOperationQueue

2008-09-15 Thread Jason Coco


On Sep 15, 2008, at 14:04 , Quincey Morris wrote:


On Sep 15, 2008, at 10:31, Jason Coco wrote:


You /should/, however, autorelease your NSOperation since your queue
will retain it when you add it and release it when it completes.


This sounds plausible, but I can't find anything in the  
documentation promising that NSOperationQueue will retain its  
NSOperation objects. (The sample code in the Threading Programming  
Guide does no memory management, so apparently leaks its  
NSInvocationOperation object.)


Good point. It currently retains them and then releases them when  
they're finished, but the documentation doesn't guarantee anything  
about memory
management and the example definitely looks like it leaks. I filed an  
enhancement request for the documentation at rdar://6220597 so  
hopefully someone
will adjust it to let us know what to do. I guess for now it's safer  
to actively manage the NSOperation object and not release it until it  
returns YES (as you indicated

below).

J

It's possible that it's not safe to release a NSOperation until  
after it returns YES to [NSOperation isFinished].




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: MySQL?

2008-09-15 Thread Jason Coco


On Sep 15, 2008, at 18:59 , J. Todd Slack wrote:


Hi All,

Does anyone know what I need to connect from OS X to a MySQL DB and  
run a few queries?


This would be from Objective-C or C++.

Any examples?

What should I be downloading?


The MySQL C API is distributed with MySQL, so if you have downloaded  
the MySQL Community Server, you have
the libraries you need. You can freely call the C API from within  
Objective-C and there is a C++ API as well. All
the documentation for using the MySQL C API is available on MySQL's  
site in a variety for formats:


http://dev.mysql.com/doc/

HTH, 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: NSMutableString question

2008-09-16 Thread Jason Coco


On Sep 16, 2008, at 20:59 , Dave DeLong wrote:

The general rule with convenience class methods like that is that  
they return an autoreleased object.  What that means is that unless  
you retain it, it will disappear at some time in the future  
(whenever the current AutoreleasePool gets drained).


Yes, as Dave says, convenience methods like [NSMutableString string]  
get autoreleased, so you don't have to do anything at all to reclaim  
the memory, but you do have to make sure you retain the string if you  
want it to persist anywhere outside it's current function/method  
scope. (BTW, when I say this, it doesn't mean that the memory /will/  
get freed when the function returns, just that you have no guarantee  
that the object is valid once the function returns--unless you retain  
it)


So if you want to "reclaim" the space, you don't have to do  
anything.  If you want to reclaim it immediately, I think you ought  
to be able to do:


NSString * str = [NSMutableString string];
//do stuff with str
[[str retain] release];

HOWEVER, that might cause funky things to happen with the  
autorelease pool.  So the best idea is to do nothing and let the  
autorelease pool take care of it.


Don't do that... if you're working with a limited-memory environment,  
or you are creating a lot of objects, your best bet is to actively  
manage your memory. Create your mutable string with alloc/init and  
then release it when you're done:


NSMutableString *str = [[NSMutableString alloc]  
initWithCapacity:someAssumedCapacity];

/* do stuff */
[str release];

Or, if you're creating lots of short-lived things in a loop or  
something, create your own autorelease pool:


while (loopConditionIsTrue) {
NSAutoreleasePool *myPool = [[NSAutoReleasePool alloc] init];
NSMutableString *str = [NSMutableString string];
/* do stuff */
	[myPool drain];	// all your autorelease objects created within the  
loop will be freed here

}

/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: NSMutableString question

2008-09-16 Thread Jason Coco


On Sep 16, 2008, at 21:24 , Dave DeLong wrote:



On 16 Sep, 2008, at 7:22 PM, Graham Cox wrote:



On 17 Sep 2008, at 11:11 am, Dave DeLong wrote:

because only a couple days ago I had a crash when I tried  
releasing an already autoreleased object



Yes, because that would be an over-release. release must be  
balanced by a preceding retain. But once an object has been added  
to an autorelease pool it is retained by the pool, so there's  
nothing you can do to deallocate it other than release the pool  
itself.


Is it actually retained by the pool, or does the pool just delay the  
final release?


It doesn't really matter how it's implemented... either way, you  
shouldn't release it unless you own it (i.e., you've retained it  
yourself or gotten it from one of the "ownership" methods such as  
copy, alloc, etc.).


/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: NSMutableString question

2008-09-16 Thread Jason Coco


On Sep 16, 2008, at 21:58 , Bill Bumgarner wrote:

On Sep 16, 2008, at 6:29 PM, Jason Coco wrote:
Is it actually retained by the pool, or does the pool just delay  
the final release?


It doesn't really matter how it's implemented... either way, you  
shouldn't release it unless you own it (i.e., you've retained it  
yourself or gotten it from one of the "ownership" methods such as  
copy, alloc, etc.).


Actually, it does matter.

In particular, -autorelease is just "-release when the containing  
pool is -drain'ed".


Oh, I meant from the perspective of convenience methods, not the case  
where you're actively retaining an object.

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: NSMutableString question

2008-09-16 Thread Jason Coco


On Sep 16, 2008, at 22:41 , Roland King wrote:


Jason Coco wrote:



NSMutableString *str = [[NSMutableString alloc]   
initWithCapacity:someAssumedCapacity];

/* do stuff */
[str release];

Is that actually guaranteed to release the string *right now*? I  
only ask because I seem to recall a message a couple of months ago  
about a more complicated object where it appeared that the  
initializer did a retain/autorelease on the object so it ended up in  
the autorelease pool before you even got hold of it. That was not an  
object obtained from a convenience method either IIRC, it was a  
[ [ SomeClass alloc ] initConstructorOfSomeSort ] call.


Unlikely the case with NSMutableString I'd think, but perhaps for  
other things.


The local autorelease pool version I'd think is guaranteed to work.


It's guaranteed to release the string *right now*, but that doesn't  
mean that the string will be deallocated *right now*. Like the case  
you stated above, other "owners" may also have bumped up the retain  
count. It will be deallocated whenever the retain count reaches 0. For  
instance, if you add the NSMutableString to an NSArray, the NSArray is  
going to retain it, so the memory will not be deallocated until you  
remove it from the array, or the array gets deallocated.


Basically all it guarantees is that *you* don't own this  
NSMutableString (or whatever object) anymore.


/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: NSMutableString question

2008-09-17 Thread Jason Coco


On Sep 17, 2008, at 12:08 , Roland King wrote:
You'd think perhaps that alloc/init would give you an object which  
really has never been retained by anyone else, but as I said I  
remembered a post from a while ago about a complex object which was  
alloc/init'ed but ended up still having a retain/autorelease on it,  
so it hung around after the author of that post thought it would be  
gone.


That must be a really rare case. Do you remember if this was from one  
of the Cocoa framework objects or rather from something that somebody  
else created? I can't think of any reason why you would want to [[self  
retain] autorelease] from within init unless you didn't really know  
how the whole Cocoa memory management/ownership/reference counting  
system worked when you wrote your initializer. (BTW, when I say you  
here, I don't mean you, Roland :-) I mean the generic you).


I've had cases where I've released the allocated object self within my  
init and created a new object, but that object leaves init with only  
one reference to it... I think that's kinda the implied contract,  
although if it was autoreleased, it still will be freed at some future  
point and won't be leaked.


You can never actually totally manage when an object is really,  
actually deallocated. Implementation details mean that objects could  
have retains on them (either real or from some outer autorelease  
pool you have no control over) but if you want to be aggressive  
about it and do all you can to maximize the chance objects are  
actually deallocated when you personally are done with them it seems  
to me that the worst of all worlds is the convenience constructor,  
in the middle is alloc/init, and the best shot you can give yourself  
is to make your own autorelease pool and retain/release all the  
objects you want inside it.


I think it depends on your situation. Like I said, I think that the  
second may be better if you have a tight loop that creates lots of  
little helper objects that you don't care anymore once the scope of  
the loop ends. However, in most cases if your alloc/init an object and  
own that object, when you release it, it is probably going to get  
deallocated. If you're really paranoid about memory, you can ask the  
object if anyone else has a reference to it (for debugging purposes)  
and try to track down who's holding it and re-thing your design so  
that you conserve more memory... but if somebody else /did/ take  
ownership of an object that you created, it's probably a bad idea to  
deallocate it out from under them anyway. It's not being leaked, in  
that case.


/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: How to get AirPort Connection Status

2008-09-18 Thread Jason Coco


On Sep 18, 2008, at 00:50 , Rashmi Vyshnavi wrote:


I want to know when my computer connects/disconnects to WiFi/AirPort
network.
Is there a way to get the status of connection to a WiFi network. I  
tried
using System Configuration API,but I could not get the status. Here  
is the

snippet
--


[...]


--
Am able to get connection status if I connect to a modem, but it  
fails when

connected
to a WiFi/AirPort network.


According to the documentation, the SCNetworkConnection API currently  
only works with PPP.

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: NSTimer does NOT repeat, why ?

2008-09-18 Thread Jason Coco


On Sep 18, 2008, at 05:18 , Florian Soenens wrote:


Hi list,

anyone knows why in this simple piece of code, the method testTimer  
is only called once and not every 2 seconds?


Yes, it is because you created a timer and then fired it manually. You  
need to schedule the timer with the run loop
in order to get it to fire repeatedly... the run loop is what is  
responsible for firing your timer every x seconds. You can
also adjust this if you don't actually need a reference to the timer  
(I assume you're keeping one because you may
have to fire it manually from time to time, or you may want to  
invalidate it outside of its normal cycle and call-back).


The example below schedules the timer automatically during  
awakeFromNib (I'm assuming that this is the functionality
that you want based on your example). You could also create the timer  
and schedule it manually with the run loop (e.g.,
in response to a button press). For further reference, you should see  
the documentation for NSTimer and NSRunLoop... links provided
at the bottom of this message for reference. It's important to note  
that a timer will never fire automatically unless it's scheduled

with a run loop and that run loop is running in the correct mode.

HTH, Jason

Replace your implementation with this:

#import "Controller.h"

@implementation Controller

-(void)awakeFromNib
{
NSLog(@"Creating NSTimer");
	timer = [[NSTimer scheduledTimerWithTimeInterval:2.0 target:self  
selector:@selector(testTimer:) userInfo:nil repeats:YES] retain];
	// do you really want to fire it manually right away? if so, leave  
this line here - this will not interrupt the regular schedule

[timer fire];
}

-(void)testTimer:(NSTimer*)aTimer
{
NSLog(@"Fired: %@", aTimer);
}
@end


NSTimer: 
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html
NSRunLoop: 
http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSRunLoop_Class/Reference/Reference.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: File I/O

2008-09-19 Thread Jason Coco


On Sep 19, 2008, at 17:20 , Nick Zitzmann wrote:



On Sep 19, 2008, at 3:15 PM, Jordon Hirshon wrote:

How can I read a file a line at a time (i.e. getline)?  I'm trying  
to do this in  a Cocoa Framework.



Try using NSFileHandle to read a file until a line feed is  
encountered. There's no built-in method of stopping at a character,  
but you could always read it in byte by byte.


Or you could read the file into a string and split it with \n,  
although Nick's method is probably more efficient:


NSError *error;
// use the proper encoding if it's not UTF-8
NSString *string = [[NSString alloc] initWithContentsOfFile:path  
encoding:NSUTF8StringEncoding error:&error];

if( !string ) { /* do something with the error */ }

NSArray *lines = [[string componentsSeparatedByString:@"\n"]  
retain];	// assuming line terminator is \n for this file

[string release];

for( NSString *line in lines ) {
// process each line
}
[lines release];



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: async NSOperation and NSOperationQueue

2008-09-19 Thread Jason Coco


On Sep 19, 2008, at 18:27 , Michael Ash wrote:

On Fri, Sep 19, 2008 at 2:41 PM, John Love <[EMAIL PROTECTED]>  
wrote:

Michael Ash wrote:




Has it occurred to you that waiting for the operation to finish is
rather at odds with the idea of trying to run it asynchronously to
keep your program responsive?




Absolutely, but if the Thread is running in the background, it really
shouldn't matter to the main Thread of the app.  While calculations  
of a
document are buzzing away in the background, I could be doing other  
things,
e.g., opening other docs to get their calculations going.  But, I  
cannot get

back control until after the first document's calculations are done.


I'm confused. I thought that the call to [theQueue
waitUntilAllOperationsAreFinished] was being made on the main thread.
If you're already spawning a second thread for those calls, why bother
with the NSOperationQueue at all?


That's how I read it too...

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: Constant NSArray Count

2008-09-20 Thread Jason Coco


On Sep 20, 2008, at 05:05 , Alex Mills wrote:


Hey,

I have started looking at Key Value Observing but I'm having trouble  
working out how to observe the changes within an Array.


Is there some place I can find example code on this to help wrap my  
head around it?


I'm pretty sure that you can't do KVO directly on arrays, just on the  
relationships that the array holds, but to get started, here is

a link to the Key-Value Observing guide from Apple:

http://developer.apple.com/documentation/Cocoa/Conceptual/KeyValueObserving/KeyValueObserving.html#/ 
/apple_ref/doc/uid/1177


You might also want to do a full-text search for KVO and Key-Value  
Observing in the search window in Xcode.


HTH, 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: Programmatically inserting text into NSTextView and scrolling

2008-09-21 Thread Jason Coco


On Sep 21, 2008, at 21:05 , Rick Mann wrote:

I want to implement a simple console for my app. As it generates  
data, it outputs a string representation of it to an NSTextView in a  
window. Already this was fairly cumbersome to do, but I got it  
working. The part that doesn't work is that it doesn't automatically  
scroll the text up after new text starts getting appended beyond the  
bottom of the window.


How can I get it to do this?


You can do something like this:

// assume textView is a pointer to the actual text view
NSRange endRange = NSMakeRange([[textView string] length], 0);

// assume string already contains the data to add to this text view
[textView replaceCharactersInRange:endRange withString:string];
[textView scrollRangeToVisible:endRange];
[textView setNeedsDisplay:YES];

To complicate matters, how can I get it to do this only when the  
window was already scrolled to the bottom, and not when scrolled  
elsewhere (in the same fashion as Terminal.app)?


You would have to track whether or not the text view is at the end. I  
suggest looking at the documentation for NSTextView as well as the  
Scroll View Programming Guide:


http://developer.apple.com/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/Introduction.html

HTH, 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: Programmatically inserting text into NSTextView and scrolling

2008-09-21 Thread Jason Coco


On Sep 21, 2008, at 22:03 , Rick Mann wrote:


Thanks!


You're welcome :)


On Sep 21, 2008, at 18:32:58, Jason Coco wrote:

You would have to track whether or not the text view is at the end.  
I suggest looking at the documentation for NSTextView as well as  
the Scroll View Programming Guide:


Well, I was looking all through the NSTextView docs, and couldn't  
find anything on scrolling. I always forget to look at the inherited  
docs.


Javadocs manage to at least list all the methods that are inherited,  
so you know there's something to go look for.


If you look at the top of the reference document, you will see a small  
table. The first row is the list of object references that the object  
inherits from. Clicking on
any of these will take you to the reference for that superclass.  The  
second row lists all the protocols that the object conforms to so you  
can see which methods
are implemented due to those protocols. The rest of the table shows  
you which framework the object is defined in, which header file  
defines it and lists other

guides of interest related to the object.

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: Programmatically inserting text into NSTextView and scrolling

2008-09-21 Thread Jason Coco


On Sep 21, 2008, at 23:02 , Rick Mann wrote:



On Sep 21, 2008, at 19:38:16, Jason Coco wrote:

If you look at the top of the reference document, you will see a  
small table. The first row is the list of object references that  
the object inherits from. Clicking on
any of these will take you to the reference for that superclass.   
The second row lists all the protocols that the object conforms to  
so you can see which methods
are implemented due to those protocols. The rest of the table shows  
you which framework the object is defined in, which header file  
defines it and lists other

guides of interest related to the object.



Yes, I know, but that's of limited use. For example, when I'm  
scanning the document (or using Find) to learn about scrolling a  
text view, I look for something under the Tasks section on  
scrolling. Oh, I spotted "display", but that didn't have anything  
for scrolling. Let's try searching for "scroll". Nope, the word is  
used in the rulers section, but nothing about scrolling the text.


If at least the inherited action names were reproduced in that file,  
I would've come across several scroll-related actions. A click  
could've taken me to the other doc.


Instead, I have to do multiple searches, potentially in more than  
one additional doc to get somewhere. And for some reason, I always  
forget to do that, so I go to the list.


Ah, I see what you mean... whereas the Java docs show the actual  
inherited methods and such on the subclass's doc page. I usually  
search in the Xcode window and do it that way, so I guess I didn't  
really think about it.


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: Properties and bindings

2008-09-22 Thread Jason Coco


On Sep 22, 2008, at 21:35 , D.K. Johnston wrote:

I'm trying to learn how to use bindings. MyObject has an NSInteger  
myInt. I used @property and @synthesize to make myInt into a  
property. In IB I bound an NSTextField to the myInt property. Now  
when I do this:


self.myInt = 123;

when initialising MyObject, the value shows up in the text field.  
But if I do this instead:


myInt = 123;

the textfield just shows '0'. What's happening here?


Others already answered this, but if (for some reason) you want to do  
this manually, you can enable the KVO as so:


[self willChangeValueForKey:@"myInt"];
myInt = 123;
[self didChangeValueForKey:@"myInt"];

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: Properties and bindings

2008-09-23 Thread Jason Coco


On Sep 22, 2008, at 23:44 , D.K. Johnston wrote:


Thanks for the explanations: it does make some kind of sense now.

The reason I was looking at both forms is that I want the myInt  
property to be read-only, but I want the MyObject instance to be  
able to set it. If I do this:


@property(readonly) NSInteger myInt;

I can't do this in MyObject:

self.myInt = 123;

without generating a compiler error. And as you've all explained, I  
can't do this either:


myInt = 123;

because the textfield value won't be changed. Is Jason's suggestion  
the best way to get around this problem?


Yes, in this case you would want to do the manual KVO as I  
demonstrated earlier. If you just surround your
ivar update with those messages, your bindings and such will behave as  
expected.


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: Unable to launch about panel for the 2nd time

2008-09-23 Thread Jason Coco


On Sep 23, 2008, at 02:58 , Arun wrote:


Hi All,

I am a newbie to cocoa programming.
I have written a small program in which i will be loading a Custom  
About

panel from another nib.
This launching of the panel works well only for the first time.
If i close the panel and try to launch for the 2nd time, it is  
unable to

show the panel.
Can anyone let me know what is wrong in the code?

Attaching the code along with this mail.

Thanks in advance..!!!


Hi Arun,

The problem is that you're AboutPanel nib is wired-up a bit wrong.  
Since you're loading the instance yourself, you don't want to create
the AboutPanelController object *inside* the nib. This is what the  
File's Owner object is for. To correct your issue keeping (mostly) the

same code as in your small example project, make these changes:

In AbouPanel.nib:

1) Delete the instance of AboutPanelController
2) Select File's Owner and open the inspector; under the Identity  
panel, change the Class to AboutPanelController

3) Wire your File's Owner mPanelToDisplay outlet to the panel in the nib
4) (optional since you don't do any delegate methods at the moment)  
wire your panel's delegate outlet to File's Owner

5) Save (and optionally quit IB)

In AboutPanelController.mm:

1) In the method implementation for sharedInstance, change line 20 to  
the following line (change marked in bold):


if (YES == [NSBundle loadNibNamed:@"AbouPanel.nib"  
owner:sharedInstance];


2) save and rebuild -- this should now work as expected

In this case, you want your sharedInstance variable to actually be the  
file's owner so that it can receive messages meant for the panel in  
the nib. You don't want
the class itself to be the file's owner since you're actually creating  
an instance of the class here.


HTH, 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: Converting from Carbon Event Manager to NSTimer

2008-09-23 Thread Jason Coco


On Sep 23, 2008, at 19:20 , Dan Birns wrote:

I'm trying to convert from Carbon to Cocoa for a number of reasons  
which I won't go into here.


My application needs to set a timer that causes a function to be  
called at a time in the future.  This is non-repeating, and  
sometimes has be immediate.  I need it to be as efficient as  
possible, because it's called frequently.


In Carbon I'm using:

EventLoopTimerUPP upp;
upp = NewEventLoopTimerUPP(macTimerCallback);

InstallEventLoopTimer(GetMainEventLoop(),0, kEventDurationForever,
upp,0,&macTimer);


Then, when I need to set the timer:
nextTimerTime = CFAbsoluteTimeGetCurrent() + nextTimer; 
SetEventLoopTimerNextFireTime(macTimer, nextTimer);

In Cocoa, the system I'm using requires me to allocate a new NSTimer  
every time I need to set a timer:


self.timer = [NSTimer scheduledTimerWithTimeInterval:   t   
// seconds
  target:   self
selector:   @selector 
(mainLoopTimer:)
userInfo:   nil 
 repeats:   NO];


In your example, what is the value of t? There is some time required  
to set up the timer and get it scheduled, so you should take that into  
account. Did you want
it to fire again at some point or did you want to schedule a new timer  
in mainLoopTimer: ?


This is working fine, but our performance is poor.  It's not so poor  
that it's obviously broken, but I'm looking for ways to improve it.   
I've been try to alloc one NSTimer that I reuse, and I've had no  
success doing so.


I've tried

timer = [NSTimer alloc];
   [timer initWithFireDate:[NSDate date] interval:t target:self  
selector:@selector(mainLoopTimer:) userInfo:halTimer repeats:NO];
   [[NSRunLoop currentRunLoop] addTimer:timer  
forMode:NSDefaultRunLoopMode];


This has failed.  Investigating, I called [timer isValid] and it  
returns false.  I've tried altering the args in various ways without  
success.  I've also had various problems retain'ing this timer.   
When I add [timer retain];, it crashes having exhausted the stack,  
where it's calling retain over and over.


That's because the timer fires NOW when done this way and interval is  
ignored since repeats is NO. Once the timer fires it is invalidated  
(again, since repeats is NO). To create a non-repeating timer that  
fires in t seconds using the init method, try this:


timer = [[NSTimer alloc] initWithFireDate:[NSDate  
dateWithTimeIntervalSinceNow:t] interval:0 target:self  
selector:@selector(mainLoopTimer:) userInfo:halTimer repeats:NO];
[[NSRunLoop currentRunLoop] addTimer:timer  
forMode:NSDefaultRunLoopMode];


What you might want to do is create a repeating timer which fires  
every so often (whatever granularity you need). Then in the timer  
function, if nextTimer's time hasn't yet been reached, return  
immediately. If it has, do whatever you need to do and reset nextTimer  
to some time in the future. That should be more efficient (or at least  
get you better granularity after the initial firing of the timer). You  
can also manually fire a repeating timer (without worrying about it  
getting invalidated) if you want it to start AS SOON AS POSSIBLE  
without waiting for it to get scheduled and fired from the run loop  
(the initial firing can be a bit delayed in that case...)


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: Unable to launch about panel for the 2nd time

2008-09-23 Thread Jason Coco


On Sep 23, 2008, at 02:58 , Arun wrote:


Hi All,

I am a newbie to cocoa programming.
I have written a small program in which i will be loading a Custom  
About

panel from another nib.
This launching of the panel works well only for the first time.
If i close the panel and try to launch for the 2nd time, it is  
unable to

show the panel.
Can anyone let me know what is wrong in the code?

Attaching the code along with this mail.


Another thing that you may want to look into is NSWindowController...  
especially in this simple case, I think it's a better choice than
your own subclass of NSObject. For just this simple about panel, you  
probably wouldn't even need to subclass it. To use it, just
create it with your window nib and in your window nib make file's  
owner an instance of NSWindowController or (if you decide to

subclass it) an instance of your subclass.

You can read more about NSWindowController at: 
http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindowController_Class/Reference/Reference.html

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: Very basic Bindings question

2008-09-24 Thread Jason Coco


On Sep 24, 2008, at 04:21 , Adil Saleem wrote:


Hi,

I am trying to use bindings for the first time. So this is a pretty  
basic question.


As an example what i am trying to do is that i have a NSTextField in  
which user enters some numeric value. I have a int type variable in  
my class that is binded to the value field of this text field. I get  
the value in the variable correctly. But the problem is that the  
accessor method that i have written are not called. If i print  
something in the accessor methods, it is not printed on the console.


Here is the code.


I have declared in myClass.h

@interface myClass: NSObject {

 int Var;
}

-(void)setVar:(int)aNumber;
-(int)getVar;


Don't use getVar (also, don't start a variable with a capital  
letter)... the correct naming convention is this:


@interface MyClass : NSObject {	// the convention is to start class  
names with a capital letter

int var;
}

-(void)setVar:(int)aNumber;		// the setter message should be the word  
set + [capital first letter] + rest of variable name
-(int)var;			// the getter message should have the same name as  
the variable


HTH, 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: Unable to launch about panel for the 2nd time

2008-09-24 Thread Jason Coco


On Sep 24, 2008, at 15:16 , I. Savant wrote:


On Wed, Sep 24, 2008 at 6:17 AM, Arun <[EMAIL PROTECTED]> wrote:

First time i am to see the panel being launched and if i close the  
panel and

try yo launch it one more time, the panel is not vsible.


 Your question was answered yesterday ... check the archives or your
spam filter.


Yeah, how rude :)

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: unable to break out of runloop because timers are fired and then the loop waits

2008-09-24 Thread Jason Coco


On Sep 24, 2008, at 15:15 , Jason Bobier wrote:


Hey folks, I have a runloop on a thread that looks like this:

while (! _cancelled) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

	[runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate  
distantFuture]];

[pool release];
}

And I put a timer in the loop that sets _cancelled to true, the  
runloop never stops. What's the proper way to do this?


The run loop only returns from this call when one of the following  
happens: 1) it has no input sources or timers left; 2) the
beforeDate: date expires; or 3) an input source has been triggered and  
processed.


Timers don't count as input sources, they are handled at a different  
part of the event loop. Also, even if you haven't added
any timers or input sources to the run loop, many of the high-level  
frameworks (like AppKit) do, so you can't be sure that

the call will return just because you haven't put anything.

Your options, then, are to use a shorter date, as was suggested, or to  
have an actual input source that gets triggered (the Mach Port Poke),  
also

suggested already. I just wanted to let you know why this happens :)

HTH, 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: unable to break out of runloop because timers are fired andthen the loop waits

2008-09-24 Thread jason . coco
He said in another message that he didn't want to poll... In that case the only 
option is to ensure an input source fires or to use a CFRunLoop instead.

Sent via BlackBerry from T-Mobile

-Original Message-
From: Muraviev Dmitry <[EMAIL PROTECTED]>

Date: Wed, 24 Sep 2008 23:30:45 
To: Jason Bobier<[EMAIL PROTECTED]>
Cc: Cocoa Developers
Subject: Re: unable to break out of runloop because timers are fired and
then the loop waits


This works fine:


NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
mTimer = [[NSTimer alloc] initWithFireDate: ... interval: ...  
target:self selector:@selector(...:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:mAudioIdleTimer  
forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:mAudioIdleTimer  
forMode:NSModalPanelRunLoopMode];
[[NSRunLoop currentRunLoop] addTimer:mAudioIdleTimer  
forMode:NSEventTrackingRunLoopMode];
while (...) [[NSRunLoop currentRunLoop] runUntilDate:[NSDate  
dateWithTimeIntervalSinceNow:1.]];
[pool release];




On 24.09.2008, at 23:15, Jason Bobier wrote:

> Hey folks, I have a runloop on a thread that looks like this:
>
> while (! _cancelled) {
>   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>   
>   [runloop runMode:NSDefaultRunLoopMode beforeDate:[NSDate  
> distantFuture]];
>   [pool release];
> }
>
> And I put a timer in the loop that sets _cancelled to true, the  
> runloop never stops. What's the proper way to do this?
>
> Thanks,
>
> Jason
> ___
>
> 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/muravievd%40gmail.com
>
> This email sent to [EMAIL PROTECTED]

___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/jason.coco%40gmail.com

This email sent to [EMAIL PROTECTED]
___

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

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

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

This email sent to [EMAIL PROTECTED]

  1   2   >