Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"

2009-04-04 Thread Dave Keck
(Sorry for the thread-hijack, but I suppose I should finish what I've
started. Last message I promise :))

> Assuming I've got my const's straight, "NSString *const" makes the pointer
> const, but not the thing pointed to -- "const NSString *const" would make
> the pointer *and* the value const, but I doubt the compiler actually has the
> concept of const-ness of objects. (And NSString's immutability is a run-time
> thing.)

Hah, of course. This wouldn't be the first time I've confused myself
over 'const'.

At any rate, I've done a little more research, and it seems I was
wrong - constant NSStrings are not formed at runtime. A constant
NSString is completely contained in the binary (in the __DATA,
__cfstring segment) and has four fields - one that specifies the Obj-C
isa, a field for flags, a field that's a pointer to the actual
C-string (the C-string is contained in the __TEXT, __cstring segment),
and finally, a field containing the length of the C-string.

In the example I linked to in the last email, I was modifying the
bytes at the address of the NSString, but since it's contained in the
read/write __DATA segment, it's no surprise that the app didn't crash.
(And to prove my sanity, I tried writing to the NSString's referenced
C-string - which crashed. Phew.)

So, here's an example illustrating how to form an NSString at runtime
in the same fashion that the compiler forms constant NSStrings at
compile-time (which it then sticks in the binary):

http://www.docdave.com/halla2.zip

(If this isn't the epitome of 'defeating the purpose', I don't know what is...)

Also, this link has some great info on the subject:
http://jens.ayton.se/blag/objc-constant-objects/

Perhaps someone will find this information useful.

David
___

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

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

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

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


Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"

2009-04-04 Thread Uli Kusterer

Nate Weaver wrote:
IIRC they're optimized to point to the same memory location (I  
wasn't sure, so I tested and confirmed).


 Well, within a particular Mach-O Container, yes. But if you have a  
framework and an application, they could presumably get two different  
strings (It's an implementation detail I wouldn't rely on if constants  
are merged across containers). So if you're intending to compare them  
using == and not using -isEqualToString:, a #define will not do.


On 04.04.2009, at 00:44, Quincey Morris wrote:
Except that the reason for *that* is to have the names of the  
strings in the public API but to keep the content of the strings out  
of it, which is presumably not a consideration for the OP.


 Exactly. It's not just so Apple are able to hide the string from you  
(you could use NSLog to easily print the contents, after all), but  
also to be able to change the actual value at any time, e.g. if they  
notice a common namespace collision etc.


I'd choose the #define version, and give the compiler elbow room to  
do its job of optimizing away duplicate literals -- and whatever  
else it can do, such as possibly putting string literals in read- 
only address space.


 It will do all of this for the string literal being assigned to your  
global kMyKey variable as well. It's just that the actual kMyKey is  
still there, pointing at the string.


But the difference (if any) between the two approaches is so minimal  
that personal preference is a fine criterion for deciding. :)



 If you're inside a single, monolithic application, yes. However,  
#define is eliminated by the preprocessor, whereas kMyKey would still  
be exported to the linker, e.g. in the case of a framework. Which  
means you can make 100% sure that this one key string is shared by  
anyone in the current address space ("linked into the application")  
who is using your framework. That in turn means you can compare the  
actual address of the string, without having to look at its contents.


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





___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread Ricky Sharp


On Apr 3, 2009, at 7:39 PM, jmun...@his.com wrote:

I have one more question:  How does one replace the blue cube object  
icon that tags on the text field with my formatter's graphic?



That, I do not know how to do.   I'll definitely update the my example  
though if I or someone else figures it out.


___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.com



___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread Ricky Sharp


On Apr 3, 2009, at 8:28 PM, jmun...@his.com wrote:


OK, now I have one more question.

I'd like to "install" and use my plug-in.  However, when accessing  
IB's preferences->Plug-ins and attempting to add the plug-in I get:   
1) when simply adding the ibplugin an error that states the file is  
missing necessary resources and to reinstall the bundle, or 2) when  
"opening" the framework folder no error but also nothing else either.


What else did I miss



This actually depends on what you'd like to do.  For my own apps, I do  
what is documented in the "ReadMe" file from my sample plugin (see the  
'Installation' section).


In my case, I put the IBPlugin into the framework's resources folder:

+ MyIBPluginFramework.framework
  + Versions
+ A
  + Resources
+ MyIBPlugin.ibplugin

NOTE: There are other files/folders too; above just shows specifically  
where the plugin resides.


___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.com



___

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

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

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

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


Re: Very interesting ordering caveat with NSArray arrayWithObjects:

2009-04-04 Thread Gregory Weston

Eric Hermanson wrote:


Some (or most) people might be aware of this caveat, but I was not, so
I'll share it.

Consider this code:

NSArray *array = [NSArray arrayWithObjects:[MyCounterClass
newObject], [MyCounterClass newObject], nil];

where [MyCounterClass newObject] is a static method that returns a new
autoreleased instance that simply stores an incrementing int32 counter
in its instance variable, e.g.

self.oid = SomeStaticCounter++;   // (or ideally,
OSAtomicIncrement32Barrier(&SomeStaticCounter);

Now, one would expect that the array would contain:

element 1: MyCounterInstance.oid=1
element 2: MyCounterInstance.oid=2

However, this is NOT the case.  Either the compiler or the runtime
executes the SECOND call to [MyCounterClass newObject] FIRST, 

NSArray arrayWithObjects: is of course correctly putting the objects
into the array in the correct natural ordering, but the objects are
CREATED on the stack in the oppose order.  Maybe most people knew
that, I did not.  So the (or a) workaround is:

MyCounterClass *object1 = [MyCounterClass newObject];
MyCounterClass *object2 = [MyCounterClass newObject];
NSArray *array = [NSArray arrayWithObjects: object1, object2,  
nil];


You've discovered the joy of implementation-defined behavior. The  
problem is not anything inherent in arrayWithObjects:; it's in the  
fact that you're modifying a variable (SomeStaticCounter) twice  
between a single pair of sequence points. The elements of an argument  
list are not guaranteed to be evaluated in any order. It could go  
front to back, or back to front, or alternate left and right from the  
outside in.


Note, by the way, that the order in which the arguments are evaluated  
has nothing whatsoever to do with the order in which they're put on  
the stack. They are not *created* on the stack. They're all evaluated  
and then they're pushed in the proper sequence.

___

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

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

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

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


RE: Best Practice for reading a string with NSScanner

2009-04-04 Thread Kirk Kerekes
It looks like you have tabular data to deal with, like punch cards.  
That means that you can assume a fixed character position for the  
beginning of each column in the table. And your code can infer those  
positions the same way you would -- by looking at the source file. Or  
you can just manually determine the offsets. Note that the end of  
column[1] is the beginning of column[2]-1, and so on.


First, steal  to break your big  
NSString into an array of lines.


Then take each line and use substringWithRange to extract the field  
text for each column, then use [NSString  
stringByTrimmingCharactersInSet:] to trim the field to just the text  
contents.



___

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

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

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

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


Need localization-proof method of transporting dates.

2009-04-04 Thread Graham Cox

My app encodes expiry dates for demo versions, etc.

One problem I've had occasional reports of is that the expiry is  
prematurely detected, and it seems to be on systems with system  
language set other than English. I need to store and check the dates  
in a way that is not sensitive to this. I thought I was, yet the  
reports persist.


Here's what I'm doing:

The stored date originally comes from a NSDatePicker control, textual  
with stepper. I retrieve the date using its -dateValue method.


The date, along with other data, is digitally signed with a SHA-1  
hash, which in turn is based on the object's -hash method. As far as I  
could tell, the -hash method returns a value that is sensitive to the  
actual stored date, but not to the date localization on the system.


At runtime, the date is recovered and verified by rehashing and  
comparing the hash, then the date value is simply compared to see if  
the current date is before or after it using [[NSDate date]  
timeIntervalSinceDate:expiryDate] (if negative, hasn't expired).


Can anyone spot any problem with this approach? Note that the SHA-1  
check appears to pass OK - it's the date comparison that seems to be  
wrong. Unfortunately I can't reproduce the bug locally so I'm relying  
on reports from relatively non-technical testers who aren't able to  
give me much to go on.


--Graham


___

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

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

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

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


Re: Best Practice for reading a string with NSScanner

2009-04-04 Thread Gustavo Pizano
Hello, Im gonna check what Quencey Morris, suggested, Im gonna see how  
to stop just before the line break,  and analyze the data I gather, I  
think NSScanner provides me a quick way to scan the file lines, its  
huge, so checking  line by line  it will take longer.


When reading the documentation I read that by default NSScanner sips  
blanks and line breaks, so I will see how to change that behavior,.


If I have no success in doing so I will be posting again.

Thanks a lot for the help

Gustavo



On 4.4.2009, at 13:32, Kirk Kerekes wrote:

It looks like you have tabular data to deal with, like punch cards.  
That means that you can assume a fixed character position for the  
beginning of each column in the table. And your code can infer those  
positions the same way you would -- by looking at the source file.  
Or you can just manually determine the offsets. Note that the end of  
column[1] is the beginning of column[2]-1, and so on.


First, steal  to break your big  
NSString into an array of lines.


Then take each line and use substringWithRange to extract the field  
text for each column, then use [NSString  
stringByTrimmingCharactersInSet:] to trim the field to just the text  
contents.





___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Ken Thomases

On Apr 4, 2009, at 7:01 AM, Graham Cox wrote:

One problem I've had occasional reports of is that the expiry is  
prematurely detected, and it seems to be on systems with system  
language set other than English. I need to store and check the dates  
in a way that is not sensitive to this. I thought I was, yet the  
reports persist.


Here's what I'm doing:

The stored date originally comes from a NSDatePicker control,  
textual with stepper. I retrieve the date using its -dateValue method.


The date, along with other data, is digitally signed with a SHA-1  
hash, which in turn is based on the object's -hash method. As far as  
I could tell, the -hash method returns a value that is sensitive to  
the actual stored date, but not to the date localization on the  
system.


At runtime, the date is recovered and verified by rehashing and  
comparing the hash, then the date value is simply compared to see if  
the current date is before or after it using [[NSDate date]  
timeIntervalSinceDate:expiryDate] (if negative, hasn't expired).


Can anyone spot any problem with this approach? Note that the SHA-1  
check appears to pass OK - it's the date comparison that seems to be  
wrong. Unfortunately I can't reproduce the bug locally so I'm  
relying on reports from relatively non-technical testers who aren't  
able to give me much to go on.


Unless I've missed something, you left out an important part.  How are  
you storing/serializing the date information and later "recovering" it?


Regards,
Ken

___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Graham Cox


On 04/04/2009, at 11:17 PM, Ken Thomases wrote:

Unless I've missed something, you left out an important part.  How  
are you storing/serializing the date information and later  
"recovering" it?



Ah, good point ;-)

The date is added to a dictionary. The dictionary is then archived.  
Decoding is simply dearchiving. The SHA-1 hash is stored in the same  
dictionary as NSData. On decoding I can recover all the objects OK as  
far as my own testing can establish - unfortunately getting a debug  
trace on the tester's machine is not really possible, so exactly where  
it's failing I can't be sure.


The reason I suspect the localisation is that an earlier version  
definitely broke with system locale because I was using the - 
description method of the date to compute the hash, not the -hash  
method, and -description was being formatted according to the system  
locale.


--Graham


___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Andy Lee

On Apr 4, 2009, at 8:29 AM, Graham Cox wrote:
The date is added to a dictionary. The dictionary is then archived.  
Decoding is simply dearchiving.


As long as you're archiving the actual NSDate object, it seems to me  
this should be fine.  Even if Apple had a bug in the archiving/ 
unarchiving of NSDate that was sensitive to locale, I would expect  
this to affect all your users in a given locale.  Is there any way of  
telling whether it's correlated with OS version or processor  
architecture?


If I wanted to be super-confident/super-paranoid about archiving a  
date in a localization-proof way, I'd store the timeIntervalSince1970  
rather than the date object itself.


 The SHA-1 hash is stored in the same dictionary as NSData. On  
decoding I can recover all the objects OK as far as my own testing  
can establish - unfortunately getting a debug trace on the tester's  
machine is not really possible, so exactly where it's failing I  
can't be sure.


The reason I suspect the localisation is that an earlier version  
definitely broke with system locale because I was using the - 
description method of the date to compute the hash, not the -hash  
method, and -description was being formatted according to the system  
locale.


Is it possible some of your users are using an archive that uses the  
older, buggy storage method?  Can they send you the archive file for  
dissection?


--Andy

___

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

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

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

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


Re: Very interesting ordering caveat with NSArray arrayWithObjects:

2009-04-04 Thread Sherm Pendley
On Fri, Apr 3, 2009 at 8:30 PM, Eric Hermanson  wrote:

[MyCounterClass newObject] is a static method that returns a new
> autoreleased instance


A method that begins with the word "new" is supposed to return an object
that you own. See:

<
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/2043-SW1
>

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread jmunson

Namaste!



Still getting "no action" after attempting to add my plug-in to IB.   
No error either.


I compared my target property settings with yours and BGHUD to be sure  
I hadn't goofed on something - everything seems well there (I reverted  
my settings which were retrieved from someone else's post to what I  
think are the default settings and that cleared up any previous errata).


I cleaned my targets and recompiled.  No errors of course.

I moved the ibplugin file to the location you shared below.

I copied the release framework folder to the ~/library/frameworks  
section of my disk.


Attempting to add that to IB results in no-action (through  
Preferences->Plug-ins).  No message, no action, nothing.


Double-clicking the ibplugin results in the same thing.

ARRRGGGHHH :/  

What am I missing?

I'd be happy to zip up and send the project to someone (nothing  
spectacular in it after all) who would like to take a look at it.


Thanks for any further help!!!

Peace, Love, and Light,

/s/ Jon C. Munson II

Quoting Ricky Sharp :



On Apr 3, 2009, at 8:28 PM, jmun...@his.com wrote:


OK, now I have one more question.

I'd like to "install" and use my plug-in.  However, when accessing   
IB's preferences->Plug-ins and attempting to add the plug-in I get:  
  1) when simply adding the ibplugin an error that states the file   
is missing necessary resources and to reinstall the bundle, or 2)   
when "opening" the framework folder no error but also nothing else   
either.


What else did I miss



This actually depends on what you'd like to do.  For my own apps, I do
what is documented in the "ReadMe" file from my sample plugin (see the
'Installation' section).

In my case, I put the IBPlugin into the framework's resources folder:

+ MyIBPluginFramework.framework
  + Versions
+ A
  + Resources
+ MyIBPlugin.ibplugin

NOTE: There are other files/folders too; above just shows specifically
where the plugin resides.

___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.com




___

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

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

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

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


Re: Very interesting ordering caveat with NSArray arrayWithObjects:

2009-04-04 Thread Michael Ash
On Sat, Apr 4, 2009 at 2:14 AM, Eric Hermanson  wrote:
> A comma is a sequence yet the order in arrayWithObjects is indeterminate.
>  It must be the var arg causing the ordering mix.

No, the comma *operator* is a sequence point. In other words, if you
just write "foo(), bar();", then the order is defined. But when you
call a function you are not using the comma operator. Yes, it is the
same character, but it's in a different context. And there, the comma
is not a sequence point, so the order of evaluation of the different
function argument expressions is completely undefined. Nothing to do
with varargs, you'll find the same thing happening with any function
or method.

The comp.lang.c FAQ has a question addressing exactly this:

http://c-faq.com/expr/comma.html

It says, "The comma operator does guarantee left-to-right evaluation,
but the commas separating the arguments in a function call are not
comma operators."

I highly encourage everybody reading this mailing list to read through
that entire FAQ. C has a lot of behaviors that are not exactly
obvious, and forewarned is forearmed.

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

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


Re: NSString* kMyKey = @"aKey" vs #define MYKEY @"aKey"

2009-04-04 Thread Michael Ash
On Sat, Apr 4, 2009 at 6:15 AM, Uli Kusterer
 wrote:
>  If you're inside a single, monolithic application, yes. However, #define is
> eliminated by the preprocessor, whereas kMyKey would still be exported to
> the linker, e.g. in the case of a framework. Which means you can make 100%
> sure that this one key string is shared by anyone in the current address
> space ("linked into the application") who is using your framework. That in
> turn means you can compare the actual address of the string, without having
> to look at its contents.

Danger Will Robinson! Given the semantics of an NSString, you should
never rely on external code giving you the same pointer that you gave
it. In other words, never rely on comparing NSStrings by pointer
equality (at least never do it if the pointer ever passed through code
that isn't yours). It would be perfectly legitimate to copy the string
and then still use it as though it were the original.

It's perfectly reasonable to use pointer equality *first* before you
perform content equality, as an optimization, and no doubt
-isEqualToString: does this. And it would be perfectly reasonable to
use the global variable to ensure that this optimization can be
performed under as many circumstances as possible. But you shouldn't
rely only on pointer equality even if you're using the global
variable.

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

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


Re: Screen recorder

2009-04-04 Thread Uli Kusterer

On 04.04.2009, at 07:44, Conrad Taylor wrote:
Hi, I would recommend Screen Flow to capture what you're doing on  
the computer and Mouse Posé to display your keyboard commands.



 Does "I need" mean you want to write one? Because that's what this  
mailing list would really be about. There are no Cocoa APIs for doing  
that, but there is very useful stuff in the CoreGraphics APIs (The  
Quartz mailing lists can probably help). There are callbacks for  
changes in the screen backbuffer, and the CGWindow code can take  
screen shots, and there are other ways (and even some sample code on  
Apple's web site) on how to take screen shots or record.


 If you're looking for a good app that already does this, nobody's  
mentioned ScreenFlick yet:


http://araelium.com/screenflick/

 It's a simple app, but visually indicates mouse-clicks and has the  
best performance if you need to capture complex animations or even  
movie playback in a way that doesn't look like a slide show.


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





___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Greg Guerin

Graham Cox wrote:

One problem I've had occasional reports of is that the expiry is  
prematurely detected, and it seems to be on systems with system  
language set other than English. I need to store and check the  
dates in a way that is not sensitive to this. I thought I was, yet  
the reports persist.


When a premature expiry occurs, how premature is it?  A day?  A few  
days?  An hour?  A few hours?


If it's up to a few hours, it might be the time-zone difference.  If  
it's at most one day, at about the same local time of day, then that  
might also be the time-zone difference.  If it's a few days, then  
time-zone is unlikely.  Otherwise I concur with Andy Lee: try storing  
the timeIntervalSince1970.


You might also try correlating it to the specific language, locale,  
and/or calendar type.  It could be a bug in a particular calendrical  
case, such as the Buddhist calendar.


  -- GG

___

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

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

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

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


Re: Toll-free bridge type at runtime

2009-04-04 Thread Michael Ash
On Sat, Apr 4, 2009 at 2:21 PM, Marcel Weiher  wrote:
>> But clearly that is not correct, since you keep saying that it is
>> trivial to distinguish them. So, please fill out the following
>> function:
>>
>> NSString *IsNSOrCFArray(id foo) // returns @"NSArray" or @"CFArray"
>> {
>>   
>> }
>>
>> And also please indicate what this function should return for
>> IsNSOrCFArray([NSArray array]).
>
> As I've repeated multiple times now:   it is impossible to distinguish a
> CFArray from an NSCFArray because they are the same thing.  It is trivial to
> distinguish other NSArrays.

So fill in the code.

This isn't some abstract arena of ideas. It's programming. We build
real things here. Since you claim to be able to differentiate between
them, show us the code. You say it's possible, prove it. Fill out the
function template I provided above and demonstrate what you're talking
about.

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

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


RE: Error: mutating method sent to immutable object

2009-04-04 Thread Priscila J . V .


Change:
[arregloNumeros release];
}
to:
[arregloNumeros removeAllObjects];
}
[arregloNumeros release];

regards
Simon

Hello Simon, 
thanks for your advice but now the message in the log window is:
*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)

Can you please suggest me something to fix it?
Cheers
Priscila
_
Téléphonez gratuitement à tous vos proches avec Windows Live Messenger  !  
Téléchargez-le maintenant !
http://www.windowslive.fr/messenger/1.asp___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Greg Guerin

Graham Cox wrote:

The date, along with other data, is digitally signed with a SHA-1  
hash, which in turn is based on the object's -hash method. As far  
as I could tell, the -hash method returns a value that is sensitive  
to the actual stored date, but not to the date localization on the  
system.



An object's -hash method is not guaranteed to return a unique value.   
Different objects can have the same hash as other objects of the same  
type, or of different types.  Therefore, if you are calculating a  
SHA-1 hash of the -hash value returned from the NSDate, your  
authentication can be spoofed by an unknown number of other NSDate  
objects that return the same value from -hash.


In this situation, where it only affects the expiry of a demo  
version, this probably isn't a big problem.  It's also possible I've  
misinterpreted how the NSDate's -hash method is being used.



By the way, if the list archives are correct, you are in a time-zone  
at GMT+1100.  Evidence is the "Date:" line here:


http://lists.apple.com/archives/cocoa-dev/2009/Apr/msg00292.html

Second, I opened a plist in Property List Editor and added a key of  
type Date, with the value set to 1/1/70.  When written out and opened  
in a text editor, it showed this:


  1970-01-01T07:00:00Z

 From this, one might infer I'm in a time-zone at GMT-0700, which  
would be correct.


I suspect that when you write an expiry NSDate to a plist file, it  
represents your local date and time.  This expiry is then expiring at  
your local time, not the recipient's local time.  However, since it's  
later in your location than almost anywhere else in the world, the  
recipient perceives the expiration as premature.


The problem is not in the localization of NSDate.  The problem is in  
not accounting for time-zone differences between your location and  
the user's location.


  -- GG

___

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

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

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

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


Re: UITableView "port" to Mac?

2009-04-04 Thread Seth Pellegrino
Excellent, this will be very helpful. Thanks!
Seth

On Thu, Apr 2, 2009 at 7:06 AM, Andreas Mayer  wrote:

>
> Am 02.04.2009 um 08:46 Uhr schrieb Seth Pellegrino:
>
>  NSCollectionView seems a little like what I'd want, but the API on
>> UITableView is much cleaner and easier to use (and I'm only really
>> interested in a single column rather than a grid). I've also looked at
>> stepwise's method for using views as rows in a NSTableView, but it seems
>> like it would be much cleaner to start from scratch.
>>
>> Toward this end, I was wondering if anyone had seen/built such a class,
>>
>
>
> http://www.harmless.de/cocoa-code.php#collectionview
>
>
> Andreas
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post 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/sethp88%40gmail.com
>
> This email sent to seth...@gmail.com
>
___

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

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

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

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


Re: Error: mutating method sent to immutable object

2009-04-04 Thread Greg Guerin

Priscila J.V wrote:


thanks for your advice but now the message in the log window is:
*** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)

Can you please suggest me something to fix it?


Bug-fixing tip number 1: Don't do that.

In particular: Stop trying to index past the end of the array.

Take a close look at your 'for' loop, and consider what happens if  
the array contains fewer than 7 items.


Then look at the basic documentation for NSArray and read about the - 
count method.


  -- GG

___

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

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

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

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


Re: Toll-free bridge type at runtime

2009-04-04 Thread Michael Ash
On Sat, Apr 4, 2009 at 3:10 PM, Marcel Weiher  wrote:
>
> On Apr 3, 2009, at 13:24 , Michael Ash wrote:
>>
>> As far as I can tell, what you're saying is that NSCFArray == CFArray.
>> In which case it is *still* impossible to distinguish an NSArray from
>> a CFArray, and still nonsensical to want to.
>>
>> But clearly that is not correct, since you keep saying that it is
>> trivial to distinguish them. So, please fill out the following
>> function:
>>
>> NSString *IsNSOrCFArray(id foo) // returns @"NSArray" or @"CFArray"
>> {
>>   
>> }
>>
>> And also please indicate what this function should return for
>> IsNSOrCFArray([NSArray array]).
>
> That function template has nothing to do with what I was saying, so I don't
> see why I should fill it in.  I have been saying that it is trivial to
> distinguish non-NSCFArray NSArrays from CFArray, and have given code that
> does so.  I have not said that it is possible to distinguish *all* NSArrays
> from CFArray, because that is clearly non-sensical as *some* NSArrays are
> CFArrays (just not all of them as would be necessary for your claim to be
> true that NSArray and CFArray are in fact indistinguishable).
>
> That you are so vehement made me wonder wether I wrote sloppily, but
> reviewing my very first post on this topic, the distinction seems very clear
> and explicitly stated just as above  (corrected "as" to "ask"):
>
> On Apr 2, 2009, at 12:20 , Marcel Weiher wrote:
>
>> An NSCFArray and a CFArray are indistinguishable as described, and if you
>> ask for an NSArray, you will typically get an NSCFArray.
>>
>> However, an actual NSArray that is not an NSCFArray will be different and
>> distinguishable.  This distinction is also not just academic, but quite
>> important because it is used by CoreFoundation to know wether to call its
>> own functions or send a message to the object in question, allowing custom
>> NSArray subclasses to be used in CFArray calls.
>
> So once again:
>
> 1.      An NSCFArray and a CFArray indistinguishable as you claim (and
> no-one ever claimed different)
> 2.      A non-NSCFArray NSArray and a CFArray are trivially distinguishable,
> as I've demonstrated
>
> Your responses seem to indicate that I am saying "NSAray != CFArray" for all
> NSArray, or that there is a test that can ALWAYS distinguish an NSArray from
> a CFArray, but that is clearly not what I am saying.  I am and have been
> saying that "NSArray = CFArray is false" and that there exists a test that
> can distinguish non-NSCFArray NSArrays from CFArrays.  If you recall your
> basic logic, you will remember that the two are not the same thing.

Well, here's what you said in one of your messages:

>>> So the compiler also disagrees with you that these are the same type.  You
>>> can *cast* them to be compatible, but they are not the same type.
>>
>> Right, but the original question was about figuring out what they are
>> at runtime which I don't believe is possible and it's not clear to me
>> whether you think it is possible.
>
> As I explained, it is trivially possible, because the only Objective-C class 
> that
> is the same as its underlying CFType is NSCFArray.

That last sentence is you. The previous context is "distinguishing
between NSArray and CFArray". The "because" doesn't make any sense,
because you are actually addressing a different point: differentiating
between NSCFArray (which you see as being the same as CFArray) and
*other* NSArray subclasses.

So, yes, you were pretty sloppy here. You took the question at hand,
formed a completely different question, answered *that* one, and were
not very clear about the change of course you made. Given that you
were talking about question A and everybody else was talking about
question B, a gross misunderstanding is inevitable.

Your claim that NSCFArray can be distinguished from other NSArray
subclasses is obvious. This still has no bearing on "distinguishing
between NSArray and CFArray". It's a substantially different, if
related, idea.

It is clear that you agree that "distinguishing between NSArray and
CFArray" is nonsensical. You say as much in your message here. It is
also clear that I agree that "distinguishing between NSCFArray and
other NSArray subclasses" is trivial, I admit it right here. What I
don't understand is why you've kept up arguing with people over the
second one when we've only been talking about the first, but there it
is.

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

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


RE: Error: mutating method sent to immutable object

2009-04-04 Thread Priscila J . V .


> 
>> thanks for your advice but now the message in the log window is:
>> *** -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)
>>
>> Can you please suggest me something to fix it?
> 
> Bug-fixing tip number 1: Don't do that.
> 
> In particular: Stop trying to index past the end of the array.
> 
> Take a close look at your 'for' loop, and consider what happens if  
> the array contains fewer than 7 items.
> 
> Then look at the basic documentation for NSArray and read about the - 
> count method.
> 
>-- GG

Hello Greg, 
thanks a lot for your suggestions :-)
cheers
Priscila 
_
Vous voulez savoir ce que vous pouvez faire avec le nouveau Windows Live ? 
Lancez-vous !
http://www.microsoft.com/windows/windowslive/default.aspx___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Tommy Nordgren


On Apr 4, 2009, at 2:01 PM, Graham Cox wrote:


My app encodes expiry dates for demo versions, etc.

One problem I've had occasional reports of is that the expiry is  
prematurely detected, and it seems to be on systems with system  
language set other than English. I need to store and check the dates  
in a way that is not sensitive to this. I thought I was, yet the  
reports persist.


Here's what I'm doing:

The stored date originally comes from a NSDatePicker control,  
textual with stepper. I retrieve the date using its -dateValue method.


The date, along with other data, is digitally signed with a SHA-1  
hash, which in turn is based on the object's -hash method. As far as  
I could tell, the -hash method returns a value that is sensitive to  
the actual stored date, but not to the date localization on the  
system.


At runtime, the date is recovered and verified by rehashing and  
comparing the hash, then the date value is simply compared to see if  
the current date is before or after it using [[NSDate date]  
timeIntervalSinceDate:expiryDate] (if negative, hasn't expired).


Can anyone spot any problem with this approach? Note that the SHA-1  
check appears to pass OK - it's the date comparison that seems to be  
wrong. Unfortunately I can't reproduce the bug locally so I'm  
relying on reports from relatively non-technical testers who aren't  
able to give me much to go on.


--Graham



	I suggest encoding your dates as strings, in standard Iso Text Format  
(-mm-ss)

---
See the amazing new SF reel: Invasion of the man eating cucumbers from  
outer space.
On congratulations for a fantastic parody, the producer replies :  
"What parody?"


Tommy Nordgren
tommy.nordg...@comhem.se



___

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

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

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

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


Re: Non-pageable app

2009-04-04 Thread Sean McBride
Clark Cox (clarkc...@gmail.com) on 2009-04-03 7:27 PM said:

>> My primary interest is to ensure that the content of an NSSecureTextField
>> and any times I extract the string from it, the memory is not paged out, or
>> cached.
>
>Then turn on "Use Secure Virtual Memory" in the Security Pane in
>System Preferences.

Note that that option is not available on Mac OS X Server, so you might
want not to rely on it as your only solution.

Sean


___

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

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

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

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


Cursor Invisible when NSTextView is not editable

2009-04-04 Thread Тимофей Даньшин

Hello.

In my application, i need some parts of the text in my NSTextView to  
be editable and some not. However, the user should be able to navigate  
through those non-editable parts, but the cursor (the flickering thing  
showing the insertion point) gets invisible as soon as it gets into a  
non-editable part.
The best I've come up with so far is to replace it by the "find  
indicator", but it flickers as the user moves it along the line and it  
disappears after a short while when the user stops moving the cursor,  
which, i believe, would be annoying to the user. And the second thing  
is that the insertion point doesn't move downwards or upwards when the  
corresponding arrow keys are pressed. It is only possible to move it  
left or right.
Is there a way either to make the insertion point remain visible or a  
better thing to replace it with than the find indicator?

Is there a way to make it move up and down as well as left and right?

Thank you for your replies in advance.
Timofey.
___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread jmunson

Namaste!

Well, I don't know that I did anything different as I haven't changed  
anything since the last email...


But now the plugin is showing up in IB...

???

Oh well, hopefully that will be the end of the drama...

Thanks everyone!!!

Peace, Love, and Light,

/s/ Jon C. Munson II

Quoting josh hughes :


Hi Jon,

This might be a bit random as I've only just started reading this thread.

I was wondering if you have a copy files build phase setup for your   
framework.


When I'm building an IBPlugin I usually create a new copy files build
phase for the framework target with /Library/Frameworks as the
destination and drag in the framework from the Products group. This way
the framework is automatically copies the framework to the right
location at build time.

b.t.w you said that:
I copied the release framework folder to the ~/library/frameworks   
section of my disk.


maybe try /Library/Frameworks rather than ~/Library/Frameworks.

Also, make sure to add the framework to any project you wish to use it in!

Sorry if this is irrelevant or you have already done so!

Hope this helps,

Josh

p.s send a zip to my address if you like, no guaranties!




On 4 Apr 2009, at 15:47, jmun...@his.com wrote:


Namaste!



Still getting "no action" after attempting to add my plug-in to IB.  
  No error either.


I compared my target property settings with yours and BGHUD to be   
sure I hadn't goofed on something - everything seems well there (I   
reverted my settings which were retrieved from someone else's post   
to what I think are the default settings and that cleared up any   
previous errata).


I cleaned my targets and recompiled.  No errors of course.

I moved the ibplugin file to the location you shared below.

I copied the release framework folder to the ~/library/frameworks   
section of my disk.


Attempting to add that to IB results in no-action (through   
Preferences->Plug-ins).  No message, no action, nothing.


Double-clicking the ibplugin results in the same thing.

ARRRGGGHHH :/  

What am I missing?

I'd be happy to zip up and send the project to someone (nothing   
spectacular in it after all) who would like to take a look at it.


Thanks for any further help!!!

Peace, Love, and Light,

/s/ Jon C. Munson II

Quoting Ricky Sharp :



On Apr 3, 2009, at 8:28 PM, jmun...@his.com wrote:


OK, now I have one more question.

I'd like to "install" and use my plug-in.  However, when   
accessing  IB's preferences->Plug-ins and attempting to add the   
plug-in I get:  1) when simply adding the ibplugin an error that   
states the file  is missing necessary resources and to reinstall   
the bundle, or 2)  when "opening" the framework folder no error   
but also nothing else  either.


What else did I miss



This actually depends on what you'd like to do.  For my own apps, I do
what is documented in the "ReadMe" file from my sample plugin (see the
'Installation' section).

In my case, I put the IBPlugin into the framework's resources folder:

+ MyIBPluginFramework.framework
+ Versions
  + A
+ Resources
  + MyIBPlugin.ibplugin

NOTE: There are other files/folders too; above just shows specifically
where the plugin resides.

___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.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/cocoa%40brikbatrecords.net

This email sent to co...@brikbatrecords.net




___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread jmunson

Namaste!

So, not the end of the drama.

The plugin shows in the list and is available in IB.

However, when I use it, my xib gets toasted - on next open IB asks  
what file I'd like to create.  I had to restore a prior backup to  
rescue my xib.


Any thoughts anyone?

Thanks!

Peace, Love, and Light,

/s/ Jon C. Munson II

Quoting jmun...@his.com:


Namaste!

Well, I don't know that I did anything different as I haven't changed
anything since the last email...

But now the plugin is showing up in IB...

???

Oh well, hopefully that will be the end of the drama...

Thanks everyone!!!

Peace, Love, and Light,

/s/ Jon C. Munson II

Quoting josh hughes :


Hi Jon,

This might be a bit random as I've only just started reading this thread.

I was wondering if you have a copy files build phase setup for your  
  framework.


When I'm building an IBPlugin I usually create a new copy files build
phase for the framework target with /Library/Frameworks as the
destination and drag in the framework from the Products group. This way
the framework is automatically copies the framework to the right
location at build time.

b.t.w you said that:
I copied the release framework folder to the ~/library/frameworks   
 section of my disk.


maybe try /Library/Frameworks rather than ~/Library/Frameworks.

Also, make sure to add the framework to any project you wish to use it in!

Sorry if this is irrelevant or you have already done so!

Hope this helps,

Josh

p.s send a zip to my address if you like, no guaranties!




On 4 Apr 2009, at 15:47, jmun...@his.com wrote:


Namaste!



Still getting "no action" after attempting to add my plug-in to   
IB.   No error either.


I compared my target property settings with yours and BGHUD to be   
 sure I hadn't goofed on something - everything seems well there  
(I   reverted my settings which were retrieved from someone else's  
 post  to what I think are the default settings and that cleared  
up  any  previous errata).


I cleaned my targets and recompiled.  No errors of course.

I moved the ibplugin file to the location you shared below.

I copied the release framework folder to the ~/library/frameworks   
 section of my disk.


Attempting to add that to IB results in no-action (through
Preferences->Plug-ins).  No message, no action, nothing.


Double-clicking the ibplugin results in the same thing.

ARRRGGGHHH :/  

What am I missing?

I'd be happy to zip up and send the project to someone (nothing
spectacular in it after all) who would like to take a look at it.


Thanks for any further help!!!

Peace, Love, and Light,

/s/ Jon C. Munson II

Quoting Ricky Sharp :



On Apr 3, 2009, at 8:28 PM, jmun...@his.com wrote:


OK, now I have one more question.

I'd like to "install" and use my plug-in.  However, when
accessing IB's preferences->Plug-ins and attempting to add the
plug-in I get:  1) when simply adding the ibplugin an error that  
  states the file  is missing necessary resources and to   
reinstall  the bundle, or 2)  when "opening" the framework   
folder no error  but also nothing else  either.


What else did I miss



This actually depends on what you'd like to do.  For my own apps, I do
what is documented in the "ReadMe" file from my sample plugin (see the
'Installation' section).

In my case, I put the IBPlugin into the framework's resources folder:

+ MyIBPluginFramework.framework
+ Versions
 + A
   + Resources
 + MyIBPlugin.ibplugin

NOTE: There are other files/folders too; above just shows specifically
where the plugin resides.

___
Ricky A. Sharp mailto:rsh...@instantinteractive.com
Instant Interactive(tm)   http://www.instantinteractive.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/cocoa%40brikbatrecords.net

This email sent to co...@brikbatrecords.net




___

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

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

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

This email sent to jmun...@his.com




___

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

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

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

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


memory deallocation

2009-04-04 Thread Daniel Luis dos Santos

Hello,

From what I know so far, memory allocated using the malloc() family  
of functions is freed using the free() function. Literal values such  
as :


char *aString = "some text";

are automatic values and are deallocated by the compiler automatically.

When I free some pointer that was allocated as in the example  
declaration above I get a warning that a non page-aligned, non  
allocated pointer is being freed. Then in practical terms, what does a  
literal value such as a #define that is used to initialize pointers  
such as the one above serves for ?


If for example I have a group of string #defines that are used in log  
messages, that means that I will have to malloc space for them the  
sprintf them to it, so I can be sure that I don't get that warning  
when deallocating the log messages.


when you pass as pointer to bytes (like a void*) to cocoa (for example  
NSData), what does it do ? It copies the bytes or just copies the  
pointer ? If I pass &aString to it that means that at the end of the  
scope it will be deallocated, and NSData will have a dangling pointer ?

___

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

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

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

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


Re: memory deallocation

2009-04-04 Thread Andrew Farmer

On 04 Apr 09, at 14:35, Daniel Luis dos Santos wrote:

Hello,

From what I know so far, memory allocated using the malloc() family  
of functions is freed using the free() function. Literal values such  
as :


char *aString = "some text";

are automatic values and are deallocated by the compiler  
automatically.


This is incorrect. String constants are stored as constant data in  
your program and cannot be deallocated (because they were never  
allocated in the first place). Passing them to free() will cause an  
error like the one you observed.


when you pass as pointer to bytes (like a void*) to cocoa (for  
example NSData), what does it do ? It copies the bytes or just  
copies the pointer ? If I pass &aString to it that means that at the  
end of the scope it will be deallocated, and NSData will have a  
dangling pointer ?


Depends on whether you use a NoCopy/freeWhenDone: initializer for  
NSData or not. As described in the documentation, NSData will by  
default make a copy of the data (the bytes, not the pointer).


In your case, if you're trying to create a NSData object with the  
contents of a string, the correct usage is:


  char *cstring = "some text";
  return [NSData dataWithBytesNoCopy:cstring length:strlen(cstring)];

We use dataWithBytesNoCopy here because the contents of the string are  
in constant data, and can be guaranteed to not change or go away.

___

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

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

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

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


Re: memory deallocation

2009-04-04 Thread Dave Carrigan


On Apr 4, 2009, at 2:35 PM, Daniel Luis dos Santos wrote:


Hello,

From what I know so far, memory allocated using the malloc() family  
of functions is freed using the free() function. Literal values such  
as :


char *aString = "some text";

are automatic values and are deallocated by the compiler  
automatically.


In actual fact, they are neither allocated nor deallocated. String  
literals are stored in a section executable itself, and the compiler  
just initializes the aString pointer have the address of that literal.


When I free some pointer that was allocated as in the example  
declaration above I get a warning that a non page-aligned, non  
allocated pointer is being freed.


Yup, don't do that. You're attempting to free something that was never  
malloc'ed.


Then in practical terms, what does a literal value such as a #define  
that is used to initialize pointers such as the one above serves for ?


#define is a different thing altogether. The C compiler never sees  
#defines; by the time the C compiler is processing that code, all  
macros have been evaluated and that is what the C compiler sees.


Thus, the following two things are identical as far as the C compiler  
is concerned.


#define STR "string"
char* str = STR;
---
char* str = "string";

If for example I have a group of string #defines that are used in  
log messages, that means that I will have to malloc space for them  
the sprintf them to it, so I can be sure that I don't get that  
warning when deallocating the log messages.


You don't have to dealloc them, ever.

when you pass as pointer to bytes (like a void*) to cocoa (for  
example NSData), what does it do ? It copies the bytes or just  
copies the pointer ?


It just copies the pointer.

This is basic C (no cocoa or anything involved). I strongly recommend  
that you find a good C book that talks about pointers and how they  
work. You will save yourself years of grief and unexplained bugs if  
you understand pointers now; they are the most critical concept in C  
and if you don't understand them, you will never be a good C (C+ 
+,Objective-C) programmer.


--
Dave Carrigan
d...@rudedog.org
Seattle, WA, USA



PGP.sig
Description: This is a digitally signed message part
___

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

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

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

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

Re: memory deallocation

2009-04-04 Thread Scott Ribe
> If for example I have a group of string #defines that are used in log
> messages, that means that I will have to malloc space for them the
> sprintf them to it, so I can be sure that I don't get that warning
> when deallocating the log messages.

That's a symptom of a bad design. You shouldn't be trying to deallocate
strings in code that has no idea how the strings were allocated in the first
place. You need to have a clear idea about "ownership" of all data.

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


___

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

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

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

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


Re: Need localization-proof method of transporting dates

2009-04-04 Thread Peter Hudson
When you collect your date from the date picker, are you setting the  
time in the date picker as well as the date ?


I used a date picker - setting dd/mm/yy only - and found it producing  
date objects bearing unexpeced times of the given day.
Naturally, these produced interesting results as they travelled around  
the world...


To fix this aspect of my problem, I collected the date from the picker  
and created a new date object using a specific time ( in this case  
12:00 )


The other part of the fix was to set the application to run in a given  
time zone ( in my case GMT was convenient )


[NSTimeZone  setDefaultTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

All you then need to do is to tell your users that expiry will occur  
at a given time in the time zone you set - leaving them to determine  
the local time at which it will occur.


PGJH
___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread Jonathan Hess


On Apr 4, 2009, at 1:48 PM, jmun...@his.com wrote:

However, when I use it, my xib gets toasted - on next open IB asks  
what file I'd like to create.  I had to restore a prior backup to  
rescue my xib.


Hey Jon -

Could you describe the failure in a little more detail? Are you  
running your plug-in and IB in the debugger? If so, is there an  
exception being raise?


Jon Hess

___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread jmunson

Namaste!

Thank you for your reply.

If I run the plug-in in debug mode, I DO get an assertion failure:

Assertion Message: Two plug-ins  
(com.JTAENTERPRISESLLC.JTAENTLLCTextLengthLimiter and  
com.JTAENTERPRISESLLC.JTAENTLLCTextLengthLimiter) both integrate a  
class description for the class JTAENTLLCTextLengthLimiterFormatter.  
The primary definition for the class should only come from one  
plug-in; the other plug-in should be declaring a category. Declaring a  
category is accomplished by omitting the super class from  
classdescription file.


Backtrace:
  0. Interface Builder0x4d29 [IBApplication  
handleAssertion:inFile:onLine:]
  1. InterfaceBuilderKit  0x0038d242 [IBClassDescriber  
refactorWithActionChangeTypeRefactoringOperation:inDocument:error:]

  2. InterfaceBuilderKit  0x002c4033 [IBPlugin didLoad]
  3. InterfaceBuilderKit  0x002c389f [IBPluginController  
loadPluginAtPath:error:]
  4. InterfaceBuilderKit  0x002ca5e3 [IBPluginController  
loadPluginWithIdentifier:error:]
  5. InterfaceBuilderKit  0x002ca519 [IBPluginController  
restorePreviouslyLoadedPluginsFromIdentifiers:]

  6. Interface Builder0x23db [IBApplication finishLaunching]
  7. AppKit   0x950c73a3 [NSApplication run]
  8. AppKit   0x950948a4 NSApplicationMain
  9. Interface Builder0x4eca [IBApplication changeInspectorMode:]
 10. ???  0x3

I don't know how to fix that.  I don't know why it thinks I have two plug-ins.

If I run in release mode, it appears to load up and function EXCEPT  
upon re-loading a nib.  I hadn't been running in debug mode once I got  
the plug-in actually working correctly, so there's got to be a change  
I made that caused this (that would be a Homer "doh" moment).


What I mean is, if I put it in a live project by putting the framework  
in a more public place (like Library/Frameworks), then add it to a  
project, start IB, go into prefs->plugins and add it there, create a  
window nib, add a textfield to the window, then add the formatter,  
fill in the limit value, and save it, then close the nib, re-opening  
the nib results in IB asking what type of resource I'd like to create.


I also noticed that under required frameworks the ibplugin file is  
displayed instead of the .framework file.  I don't know how to fix  
that either.


I'll be happy to forward the project to you if you'd like a gander,  
the file is 2.7mb in size.


Thanks!

Peace, Love, and Light,

/s/ Jon C. Munson II


Quoting Jonathan Hess :



On Apr 4, 2009, at 1:48 PM, jmun...@his.com wrote:

However, when I use it, my xib gets toasted - on next open IB asks   
what file I'd like to create.  I had to restore a prior backup to   
rescue my xib.


Hey Jon -

Could you describe the failure in a little more detail? Are you running
your plug-in and IB in the debugger? If so, is there an exception being
raise?

Jon Hess




___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread jmunson

Namaste!

Just want to pass on some further information.

After that last post, the assertion error really bothered me.  So,  
after a while of careful inspection (to the limits of what I know), I  
decided to and "clean[ed] all targets" of both the debug and release  
builds and re-compiled.  In the plug-in project, runs of both debug  
and release went smoothly - IB loaded the plug-in, I was able to use  
it, close and re-open nibs successfully.  No errors.


"Deploying" the plug-in is proving difficult.

I copied the release framework to Library/Frameworks.  I also copied  
the framework into the frameworks section of a live project.  I then  
created a test.xib in my live project, which I subsequently opened.   
In the Preferences->Plug-ins pane for IB, I attempted to add the  
plug-in.  I got nothing - no error, nor plug-in.


I then added the ibplugin file to the Resources folder of the version  
A of the framework.


I then repeated the process of copying.  This time, the plug-in  
appeared in IB.  I added a textfield to test.xib, and applied the  
plug-in to it.  I saved and closed the file.  Upon re-open, IB didn't  
open the xib, but popped up the standard "create a resource" dialog -  
test had gotten kaboshed.


I do notice that the Required Frameworks is displaying the .ibplugin  
file instead of the expected .framework file.  I don't know if that is  
related or not.


Again, I'll be happy to send up the project should you want to see it.

Thanks!

Peace, Love, and Light,

/s/ Jon C. Munson II


Quoting Jonathan Hess :



On Apr 4, 2009, at 1:48 PM, jmun...@his.com wrote:

However, when I use it, my xib gets toasted - on next open IB asks   
what file I'd like to create.  I had to restore a prior backup to   
rescue my xib.


Hey Jon -

Could you describe the failure in a little more detail? Are you running
your plug-in and IB in the debugger? If so, is there an exception being
raise?

Jon Hess




___

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

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

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

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


Automating reading classes with InterfaceBuilder

2009-04-04 Thread Ryan Joseph
I'm working on a Pascal bridge to Cocoa and as part of the system I  
have a PHP script which converts files to Objective-C headers, which  
InterfaceBuilder can use. However first I must manually "Read class  
files" and Reload in InterfaceBuilder. Xcode does this so there must  
be a way, but can I use AppleEvents to tell InterfaceBuilder to do  
this automatically? A UNIX solution that I could call from PHP or a  
shell script would be even better. Thank you.


Regards,
Josef

___

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

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

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

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


Beachball on Lengthy Task

2009-04-04 Thread Pierce Freeman
Hi everyone:

I am getting the beachball of death when I try to run an action that takes
over a few seconds to complete.  Given, the beachball goes away after the
task is completed - But for lengthy tasks, why can't I just allow the user
to go along with their work instead of having them wait with the beachball?
Would this be a problem with memory management, or something else entirely?


Sincerely,

Pierce Freeman


___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread john chen
You can try to do that task in another thread.
John

On Sat, Apr 4, 2009 at 8:08 PM, Pierce Freeman
wrote:

> Hi everyone:
>
> I am getting the beachball of death when I try to run an action that takes
> over a few seconds to complete.  Given, the beachball goes away after the
> task is completed - But for lengthy tasks, why can't I just allow the user
> to go along with their work instead of having them wait with the beachball?
> Would this be a problem with memory management, or something else entirely?
>
>
> Sincerely,
>
> Pierce Freeman
>
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post 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/johnchen202%40gmail.com
>
> This email sent to johnchen...@gmail.com
>
___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Ryan Joseph
Are you aware of threading or run loops? There is no problem here, you  
must share the processor with OS X. Read about those concepts and come  
back later with questions. ;)


On Apr 5, 2009, at 8:08 AM, Pierce Freeman wrote:


Hi everyone:

I am getting the beachball of death when I try to run an action that  
takes
over a few seconds to complete.  Given, the beachball goes away  
after the
task is completed - But for lengthy tasks, why can't I just allow  
the user
to go along with their work instead of having them wait with the  
beachball?
Would this be a problem with memory management, or something else  
entirely?



Sincerely,

Pierce Freeman


___

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

Please do not post 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/thealchemistguild%40gmail.com

This email sent to thealchemistgu...@gmail.com


Regards,
Josef

___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Pierce Freeman
John:

Good idea, I¹ll look into threads and hopefully it will work.


On 4/4/09 6:37 PM, "john chen"  wrote:

> You can try to do that task in another thread.
> 
> John
> 
> On Sat, Apr 4, 2009 at 8:08 PM, Pierce Freeman 
> wrote:
>> Hi everyone:
>> 
>> I am getting the beachball of death when I try to run an action that takes
>> over a few seconds to complete.  Given, the beachball goes away after the
>> task is completed - But for lengthy tasks, why can't I just allow the user
>> to go along with their work instead of having them wait with the beachball?
>> Would this be a problem with memory management, or something else entirely?
>> 
>> 
>> Sincerely,
>> 
>> Pierce Freeman
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post 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/johnchen202%40gmail.com
>> 
>> This email sent to johnchen...@gmail.com
> 
> 

___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Pierce Freeman
Hey Ryan:

I have heard of threads before, but am just looking into them now to see if
they will work.


On 4/4/09 6:40 PM, "Ryan Joseph"  wrote:

> Are you aware of threading or run loops? There is no problem here, you must
> share the processor with OS X. Read about those concepts and come back later
> with questions. ;)
> 
> On Apr 5, 2009, at 8:08 AM, Pierce Freeman wrote:
> 
>> Hi everyone:
>> 
>> I am getting the beachball of death when I try to run an action that takes
>> over a few seconds to complete.  Given, the beachball goes away after the
>> task is completed - But for lengthy tasks, why can't I just allow the user
>> to go along with their work instead of having them wait with the beachball?
>> Would this be a problem with memory management, or something else entirely?
>> 
>> 
>> Sincerely,
>> 
>> Pierce Freeman
>> 
>> 
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> Please do not post 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/thealchemistguild%40gmail.co>>
m
>> 
>> This email sent to thealchemistgu...@gmail.com
> 
>  
> Regards,
> Josef
>  
> 
> 

___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Dave Keck
> I am getting the beachball of death when I try to run an action that takes
> over a few seconds to complete.  Given, the beachball goes away after the
> task is completed - But for lengthy tasks, why can't I just allow the user
> to go along with their work instead of having them wait with the beachball?
> Would this be a problem with memory management, or something else entirely?

Something else entirely.

User interface events (mouse clicks, typing, etc) are handled on the
main thread. If you start performing a long task on the main thread,
the main thread is blocked from reacting to any user events until this
lengthy-task is complete. In more technical terms, while this long
task is running, the main thread's run loop (the mechanism that helps
handle UI events) cannot perform another iteration until your
lengthy-function returns. (Note that the beachball appears when an
app's main thread is blocked, as you've seen.)

There are two ways I solve this problem: either create a separate
thread, or use a timer.

Creating a separate thread could be opening a can of worms, depending
on how complex your app is. When using threads in your app, you must
make sure that your threads communicate safely. If you choose to go
the thread route, research "thread safety". There's around a
bajillion+1 articles on the subject; of course, you should look for
thread-safety articles written for the context of OS X/Cocoa. Also
note that much of Cocoa is _not_ thread-safe, so the burden will often
be on you to ensure that you're not using certain Cocoa classes
incorrectly in regard to thread safety. (That is, using locks where
appropriate, and not using certain classes or methods if they don't
support multiple threads.) An excellent article on thread-safety and
Cocoa can be found here:
http://mikeash.com/?page=pyblog/friday-qa-2009-01-09.html

On the other hand, you could use a timer. The idea behind a timer is
you complete a small part of the task every time the timer fires,
until the task is complete. In some respects, using a timer can be
'cleaner' than creating a separate thread: since a timer runs in the
main thread, you don't have to worry about using locks everywhere. In
other respects, using a timer can be much less elegant: you'll have to
store the lenghty-task's state somewhere, so every time the timer
fires, it knows where it left off. This can lead to some confusing and
overall inelegant code, but sometimes can still be easier than
creating a separate thread and dealing with the caveats of
thread-safety. (And sometimes you simply can't use a separate thread,
if something you rely on doesn't play nice with threads.)

The route you choose really depends on how well your task can be
self-contained. For example, if I'm calculating pi to ten billion
digits, but want the UI to remain responsive, this is a perfect time
to use a separate thread. On the other hand, if a lengthy task
requires access to Cocoa classes that don't like threads (and the
lenghty-task can be broken up into smaller chunks) then a timer may be
a better choice.

Hope this helps,

David
___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Pierce Freeman
Hey Dave:

Yeah, it really helped!  I am trying to get the contents of the files in a
certain directory, so I think that I could probably get away with using a
timer.  I assume you mean NSTimer for the timer, though there could be
another class that I am totally missing. ;)  In addition, if you are to use
NSTimer, how would you suggest setting the timer to call another function
that requires a passed variable?


Thanks again.


On 4/4/09 7:27 PM, "Dave Keck"  wrote:

>> I am getting the beachball of death when I try to run an action that takes
>> over a few seconds to complete.  Given, the beachball goes away after the
>> task is completed - But for lengthy tasks, why can't I just allow the user
>> to go along with their work instead of having them wait with the beachball?
>> Would this be a problem with memory management, or something else entirely?
> 
> Something else entirely.
> 
> User interface events (mouse clicks, typing, etc) are handled on the
> main thread. If you start performing a long task on the main thread,
> the main thread is blocked from reacting to any user events until this
> lengthy-task is complete. In more technical terms, while this long
> task is running, the main thread's run loop (the mechanism that helps
> handle UI events) cannot perform another iteration until your
> lengthy-function returns. (Note that the beachball appears when an
> app's main thread is blocked, as you've seen.)
> 
> There are two ways I solve this problem: either create a separate
> thread, or use a timer.
> 
> Creating a separate thread could be opening a can of worms, depending
> on how complex your app is. When using threads in your app, you must
> make sure that your threads communicate safely. If you choose to go
> the thread route, research "thread safety". There's around a
> bajillion+1 articles on the subject; of course, you should look for
> thread-safety articles written for the context of OS X/Cocoa. Also
> note that much of Cocoa is _not_ thread-safe, so the burden will often
> be on you to ensure that you're not using certain Cocoa classes
> incorrectly in regard to thread safety. (That is, using locks where
> appropriate, and not using certain classes or methods if they don't
> support multiple threads.) An excellent article on thread-safety and
> Cocoa can be found here:
> http://mikeash.com/?page=pyblog/friday-qa-2009-01-09.html
> 
> On the other hand, you could use a timer. The idea behind a timer is
> you complete a small part of the task every time the timer fires,
> until the task is complete. In some respects, using a timer can be
> 'cleaner' than creating a separate thread: since a timer runs in the
> main thread, you don't have to worry about using locks everywhere. In
> other respects, using a timer can be much less elegant: you'll have to
> store the lenghty-task's state somewhere, so every time the timer
> fires, it knows where it left off. This can lead to some confusing and
> overall inelegant code, but sometimes can still be easier than
> creating a separate thread and dealing with the caveats of
> thread-safety. (And sometimes you simply can't use a separate thread,
> if something you rely on doesn't play nice with threads.)
> 
> The route you choose really depends on how well your task can be
> self-contained. For example, if I'm calculating pi to ten billion
> digits, but want the UI to remain responsive, this is a perfect time
> to use a separate thread. On the other hand, if a lengthy task
> requires access to Cocoa classes that don't like threads (and the
> lenghty-task can be broken up into smaller chunks) then a timer may be
> a better choice.
> 
> Hope this helps,
> 
> David


___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Andrew Farmer

On 04 Apr 09, at 19:35, Pierce Freeman wrote:
Yeah, it really helped!  I am trying to get the contents of the  
files in a
certain directory, so I think that I could probably get away with  
using a

timer.  I assume you mean NSTimer for the timer, though there could be
another class that I am totally missing. ;)


There's also NSObject's performSelector:withObject:afterDelay: method.


In addition, if you are to use
NSTimer, how would you suggest setting the timer to call another  
function

that requires a passed variable?


Read up on CPS[1], but be prepared to have your head explode a bit.

[1]: http://en.wikipedia.org/wiki/Continuation-passing_style
___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Stuart Malin


On Apr 4, 2009, at 5:07 PM, Andrew Farmer wrote:


On 04 Apr 09, at 19:35, Pierce Freeman wrote:

Yeah, it really helped!  I am trying to get the contents of the
files in a
certain directory, so I think that I could probably get away with
using a
timer.  I assume you mean NSTimer for the timer, though there could  
be

another class that I am totally missing. ;)


There's also NSObject's performSelector:withObject:afterDelay: method.



And, if you are 10.5 only, there's also NSObject's  
performSelectorInBackground:withObject:


http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#/ 
/apple_ref/doc/uid/2050-SW4


and make callbacks using - 
performSelectorOnMainThread:withObject:waitUntilDone:


http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html#/ 
/apple_ref/doc/uid/2050-CJBEHAEF



Regarding threads, see Threading Programming Guide:
http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/

___

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

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

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

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


How can I get data from a javascript function in a WebView into the enclosing Cocoa App?

2009-04-04 Thread Darren Wheatley

Hi,

I'm writing an application that renders a web page in a web view.

The web page contains an image that the user can click on. There are 
Javascript events that get called when the user clicks on the image. 
These events contain the coordinates of the point the user clicked on.


I need to be able to get the coordinates out of the web view and back 
into the enclosing Cocoa application.


Is this possible, and if so, could anyone suggest how this could be done?

Thanks

Darren.


___

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

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

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

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


Re: Very interesting ordering caveat with NSArray arrayWithObjects:

2009-04-04 Thread Eric Hermanson
A comma is a sequence yet the order in arrayWithObjects is  
indeterminate.  It must be the var arg causing the ordering mix.


Sent from my iPhone

On Apr 4, 2009, at 12:29 AM, Michael Ash  wrote:

On Fri, Apr 3, 2009 at 8:30 PM, Eric Hermanson   
wrote:
Some (or most) people might be aware of this caveat, but I was not,  
so I'll

share it.

Consider this code:

   NSArray *array = [NSArray arrayWithObjects:[MyCounterClass  
newObject],

[MyCounterClass newObject], nil];

where [MyCounterClass newObject] is a static method that returns a  
new
autoreleased instance that simply stores an incrementing int32  
counter in

its instance variable, e.g.

   self.oid = SomeStaticCounter++;   // (or ideally,
OSAtomicIncrement32Barrier(&SomeStaticCounter);

Now, one would expect that the array would contain:

   element 1: MyCounterInstance.oid=1
   element 2: MyCounterInstance.oid=2

However, this is NOT the case.  Either the compiler or the runtime  
executes
the SECOND call to [MyCounterClass newObject] FIRST, so the array  
actually

contains:

   element 1: MyCounterInstance.oid=2
   element 2: MyCounterInstance.oid=1

NSArray arrayWithObjects: is of course correctly putting the  
objects into
the array in the correct natural ordering, but the objects are  
CREATED on
the stack in the oppose order.  Maybe most people knew that, I did  
not.  So

the (or a) workaround is:

   MyCounterClass *object1 = [MyCounterClass newObject];
   MyCounterClass *object2 = [MyCounterClass newObject];
   NSArray *array = [NSArray arrayWithObjects: object1, object2,  
nil];


This is actually a "feature" of C, which ObjC inherits. C does not
define an order of operations except across "sequence points", which
are basically semicolons, although C defines some others too.
Different parts of a statement are executed in an arbitrary order.
Basically, the compiler can decide which order suits it best. As such,
conforming C (and thus ObjC) code must never rely on the order of
execution of function arguments, arithmetic subexpressions, or
anything else of that nature. In any given statement, there should
never be two parts of the statement that have interdependent side
effects.

Wikipedia has a decent discussion of this concept along with some
illuminating examples:

http://en.wikipedia.org/wiki/Sequence_point

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/zmonster%40mac.com

This email sent to zmons...@mac.com

___

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

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

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

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


Re: Error: mutating method sent to immutable object

2009-04-04 Thread Simon Robbie

Change:

[arregloNumeros release];
}

to:

[arregloNumeros removeAllObjects];
}

[arregloNumeros release];

regards

Simon
___

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

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

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

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


NSXMLParser memory consumption

2009-04-04 Thread George King

Hi List,

I hit a stumbling block when passing large files (multi-GB) to  
NSXMLParser. It appears that NSXMLParser's initWithContentsOfURL:  
method loads the contents of the entire file into memory, which is  
causing virtual memory thrashing for at file sizes approaching my  
physical RAM (2 GB in this case, so I start seeing performance issues  
at around 1.3 GB). After reading the CFXMLParser documentation, I  
suspect that core foundation does the same thing.


Can somebody suggest an alternative API for parsing xml that does not  
have memory requirements linear with file size for the initialization?  
Given the event-driven design I originally imagined that the parser  
would read through a file incrementally, without loading it all into  
memory.


Also, would it be appropriate to file a bug / enhancement request for  
this issue?


Note that once the NSXMLParser delegate starts receiving messages, I  
am able to keep memory usage under control by giving the delegate its  
own autorelease pool and draining/replacing it once every x calls to  
parser:didStartElement


I started looking into libxml2 but then thought I'd ask here first.  
Any suggestions would be much appreciated. Thanks!


George
___

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

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

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

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


Re: Non-pageable app

2009-04-04 Thread Finlay Dobbie
On Fri, Apr 3, 2009 at 11:57 PM, Rich Collyer  wrote:
> My primary interest is to ensure that the content of an NSSecureTextField
> and any times I extract the string from it, the memory is not paged out, or
> cached.

http://developer.apple.com/documentation/Darwin/Conceptual/KernelProgramming/security/security.html
says:

--
Indeed, many types of data, such as hashes, unencrypted versions of
sensitive data, and authentication tokens, should generally not be
written to disk due to the potential for abuse. This raises an
interesting problem. There is no good way to deal with this in user
space (unless a program is running as root).
--

 -- Finlay
___

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

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

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

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


Using bindings to set NSImageView from filename

2009-04-04 Thread Martin Cote
Hi,
I would like to know if there's a way to use bindings to set the image of an
NSImageView from a filename in Interface Builder.  As far as I can see, you
can only set the image from an NSImage instance.

I'm feeling that I'll have to write some code to do it, but if there's a way
to do it in IB, I would like to know how.

Many thanks,
Martin Cote
___

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

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

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

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


Re: Need localization-proof method of transporting dates.

2009-04-04 Thread Marcel Weiher


On Apr 4, 2009, at 5:01 , Graham Cox wrote:

One problem I've had occasional reports of is that the expiry is  
prematurely detected, and it seems to be on systems with system  
language set other than English. I need to store and check the dates  
in a way that is not sensitive to this. I thought I was, yet the  
reports persist.


Dates are tricky.  One issue is that what's consistent in a machine  
sense is often at odds with consistent from the user's point of view,  
and that various layers of interpretation get you a bit of a muddle  
(classic case is calendar programs treating dates as absolute times,  
so when you schedule appointments in a different time-zone for a trip  
and then switch to that time-zone during the trip, all your  
appointments shift).


The muddle problem can be largely eliminated by storing a fairly  
unambiguous value, such as seconds since 1970 (or 2000 see  
NSTimeInterval), preferably as a 64 bit value (NSTimeInterval's double  
should also work for most applications..).


Once you've left the muddle behind, you are left with  
interpretations.  What time-zone is the value interpreted in?  GMT?   
The user's time-zone?  When are offsets applied?


If you are archiving the date, my guess is that it is being archived  
with your local time-zone, and then compared to a date that is in your  
client's time-zone.


The solution I have is to store the date  year/month/day, completely  
independent of NSDate.  I then construct the expiry NSDate locally, so  
it will be interpreted in the same context as the current date that  
"[NSDate date]" delivers.


I also tend to not say when exactly the software expires... :-)

Hope that helps,

Marcel

___

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

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

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

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


Re: Reading cab into object

2009-04-04 Thread Marcel Weiher


On Apr 3, 2009, at 14:18 , Mark Bateman wrote:


Hi
I have a csv file I want to use as a source for a searchable list

The csv has 16 fields. I have managed to read the csv line by line  
into an array


You don't necessarily need to read the lines into an array, you can  
just process them one-by-one.


I'm having difficulty figuring out how to load an instance of an  
object with the single line of the array and initialising each of  
the objects properties with the fields seperated by commas
What am I missing.  Should I load an intermediate array using  
ComponentsSeparatedByString method. Even so how do I then initialize  
the custom object fields


-componentsSeparatedByString:  is a reasonable way of getting the  
components.  You will then have 16 individual strings.


The rest depends very much on your actual class and on the values,  
here is an example with 4 fields


#import 

@interface MyObject : NSObject
{
id a,b;
int c,d;
}
@end

@implementation MyObject

-initWithCSV:(NSString*)csvString
{
self=[super init];
if (self) {
id fields=[csvString  componentsSeparatedByString:@","];
a=[[fields objectAtIndex:0] retain];
b=[[fields objectAtIndex:1] retain];
c=[[fields objectAtIndex:2] intValue];
d=[[fields objectAtIndex:3] intValue];
}
return self;
}

-description { return [NSString stringWithFormat:@"<%@:%p a=%@ b=%@ c= 
%d d=%d",[self class],self,a,b,c,d]; }


@end

int main( int argc, char *argv[] )
{
id pool=[NSAutoreleasePool new];
char buffer[1024];
NSMutableArray *arrayOfObjects=[NSMutableArray array];

while ( fgets(buffer,1000, stdin) ) {
if ( strlen(buffer) > 1 ) {
buffer[strlen(buffer)-1]=0;
}
		[arrayOfObjects addObject:[[[MyObject alloc] initWithCSV:[NSString  
stringWithCString:buffer]] autorelease]];

}
NSLog(@"array: %@",arrayOfObjects);   
exit(0);
[pool release];
return 0;
}




mar...@spock[tmp]./a.out
hello world, cocoa rocks, 1 ,2
according to douglas adams, the answer is, 42, 0
^D
2009-04-04 14:00:49.229 a.out[69819:10b] array: (
c=42 d=0

)
mar...@spock[tmp]



___

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

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

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

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


Cocoa user pane equivalent?

2009-04-04 Thread Jo Meder

Hi,

I'm in the planning stages of porting the Mac back end of my cross  
platform UI framework from Carbon to Cocoa, because I need 64 bit GUI  
support. It looks like it should be relatively straightforward. I'm  
already using some Obj-C++ and Cocoa APIs for stuff like cursor  
management and drawing text into graphics canvases.


The one thing I'm not really clear on is what the Cocoa equivalent of  
a Carbon user pane control would be. It seems that there isn't really  
a direct equivalent in Cocoa and that the best way to do things would  
be to have a custom view inheriting from NSControl. Would that be right?


Regards,

Jo Meder
___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Pierce Freeman
> And, if you are 10.5 only, there's also NSObject's
> performSelectorInBackground:withObject:

Is this a timer or a thread creator?  I don't believe it has inputs for the
time, or could it just do it automatically?  Also, is there some way I can
make this work with a function already created?


___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Stuart Malin


On Apr 4, 2009, at 5:36 PM, Pierce Freeman wrote:


And, if you are 10.5 only, there's also NSObject's
performSelectorInBackground:withObject:


Is this a timer or a thread creator?  I don't believe it has inputs  
for the
time, or could it just do it automatically?  Also, is there some way  
I can

make this work with a function already created?


That is a thread creator. It will initiate the specified selector of  
the receiver (the invoked object). You can pass a single object to it;  
that object can, of course, contain references to other objects.


Please be careful to distinguish "method" from "function."  If you  
meant an Objective-C method, yes, it will work with that. If you meant  
a C function, then no, it will not work, at least not directly, but in  
such case it would be easy to create a method that called the function.


Note: as has already been pointed out, you must be very careful  
regarding thread safety. A background thread task must carefully  
constrain which objects it instantiates and methods used to those that  
are thread safe. Certainly no U/I.


Read the cited references, and additional material germane to these.

btw: by any stretch of the imagination, I'm not an expert with threads.

___

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

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

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

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


Re: Beachball on Lengthy Task

2009-04-04 Thread Dave Keck
> Yeah, it really helped!  I am trying to get the contents of the files in a
> certain directory, so I think that I could probably get away with using a
> timer.

In this case, the reason your task is taking several seconds to
complete is most likely attributed to the sheer time it takes the read
the contents of the files; that is, most of the time that it takes for
the lengthy-task to complete isn't due to lots of
computation-intensive stuff going on, but rather the age-old slow disk
read. On the list of the 3 best times to use threads, reading large
files from disk would perhaps be one of them...

I probably should have asked for more information before forming my
last post - for this case in particular, I would use NSFileHandle's
asynchronous file reading mechanisms (which create separate threads
for you, so you don't have to worry about it). Read about NSFileHandle
in the docs, specifically, check out
-readToEndOfFileInBackgroundAndNotify.

At any rate, to get the contents of every file in a directory, I would
iterate over the files in the directory, creating an NSFileHandle for
each one, and call -readToEndOfFileInBackgroundAndNotify for each.
Depending on how many files you're expecting, you may need to call
-readToEndOfFileInBackgroundAndNotify on a small number of
NSFileHandles, wait until those have finished reading, call it on the
next group of NSFileHandles, etc.

Note that while you may have escaped from using threads this time
(directly, at least) that's not always going to be the case :).
Threads are indispensable and with the number of cores chips are
sporting these days, will only become more so...

Good luck!

David
___

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

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

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

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


Re: memory deallocation

2009-04-04 Thread Michael Ash
On Sat, Apr 4, 2009 at 6:02 PM, Andrew Farmer  wrote:
> In your case, if you're trying to create a NSData object with the contents
> of a string, the correct usage is:
>
>  char *cstring = "some text";
>  return [NSData dataWithBytesNoCopy:cstring length:strlen(cstring)];
>
> We use dataWithBytesNoCopy here because the contents of the string are in
> constant data, and can be guaranteed to not change or go away.

This is no good. NSData will attempt to free your constant string when
it's destroyed. You need to explicitly say freeWhenDone:NO here,
because not specifying it is equivalent to YES.

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

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


Re: Cocoa user pane equivalent?

2009-04-04 Thread Michael Ash
On Sat, Apr 4, 2009 at 10:20 PM, Jo Meder  wrote:
> Hi,
>
> I'm in the planning stages of porting the Mac back end of my cross platform
> UI framework from Carbon to Cocoa, because I need 64 bit GUI support. It
> looks like it should be relatively straightforward. I'm already using some
> Obj-C++ and Cocoa APIs for stuff like cursor management and drawing text
> into graphics canvases.
>
> The one thing I'm not really clear on is what the Cocoa equivalent of a
> Carbon user pane control would be. It seems that there isn't really a direct
> equivalent in Cocoa and that the best way to do things would be to have a
> custom view inheriting from NSControl. Would that be right?

Can you explain what a user pane is (not all of us are that familiar
with Carbon) and what exactly you're trying to do?

>From a cursory search on the term, it seems that a custom NSView
subclass is what you want. Whether you'd want to inherit from
NSControl or not depends on whether NSControl provides any
functionality you desire.

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

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


Re: Cocoa user pane equivalent?

2009-04-04 Thread Ryan Joseph


On Apr 5, 2009, at 11:30 AM, Michael Ash wrote:


On Sat, Apr 4, 2009 at 10:20 PM, Jo Meder  wrote:

Hi,

I'm in the planning stages of porting the Mac back end of my cross  
platform
UI framework from Carbon to Cocoa, because I need 64 bit GUI  
support. It
looks like it should be relatively straightforward. I'm already  
using some
Obj-C++ and Cocoa APIs for stuff like cursor management and drawing  
text

into graphics canvases.

The one thing I'm not really clear on is what the Cocoa equivalent  
of a
Carbon user pane control would be. It seems that there isn't really  
a direct
equivalent in Cocoa and that the best way to do things would be to  
have a

custom view inheriting from NSControl. Would that be right?


Can you explain what a user pane is (not all of us are that familiar
with Carbon) and what exactly you're trying to do?


A user pane was a precursor to HIView, that is a view (control is the  
proper term for the user pane) that could handle user input events,  
drawing and adding sub-views for grouping purposes. NSView is the  
equivalent of HIView so NSView is what you want I think.






From a cursory search on the term, it seems that a custom NSView

subclass is what you want. Whether you'd want to inherit from
NSControl or not depends on whether NSControl provides any
functionality you desire.

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

This email sent to thealchemistgu...@gmail.com


Regards,
Josef

___

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

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

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

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


Re: Where is "Accessibility Reference for Assistive Applications"?

2009-04-04 Thread Scott Anguish
If it isn't linked, that's a bug worth hitting the feedback button on.  
A missing link like that usually means the doc has been retired, just  
renaming the book won't cause a broken link.


I looked for a broken link in see-alsos on the current release in  
accessibility docs, but didn't see anything.


It may have been replaced by

ADC Home > Core Reference Library > User Experience > Accessibility

or by the docs


Getting Started with Accessibility.
Accessibility Programming Guidelines for Cocoa
and
Accessiblity Overview.

Looks like some of those first came out in the 10.4 timeframe.


On 4-Apr-09, at 2:14 AM, m wrote:

In the "See Also" section of an old Accessibility doc is listed one  
named "Accessibility Reference for Assistive Applications", which  
uniquely (and frustratingly) is not linked to the actual document.


Neither a Spotlight search of my machine, an Xcode Help search, or  
Google search seem to be able to locate this perhaps mythical scroll.


Where is this doc? Does it really exist? If it has been superseded,  
what (and where) is its successor?


___

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

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

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

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


[Moderator] Re: Toll-free bridge type at runtime

2009-04-04 Thread Scott Anguish
this thread has passed it's usefulness. It certainly isn't appropriate  
for cocoa-dev anyways.



___

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

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

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

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


Re: memory deallocation

2009-04-04 Thread Andrew Farmer

On 04 Apr 09, at 21:28, Michael Ash wrote:
On Sat, Apr 4, 2009 at 6:02 PM, Andrew Farmer   
wrote:
In your case, if you're trying to create a NSData object with the  
contents

of a string, the correct usage is:

 char *cstring = "some text";
 return [NSData dataWithBytesNoCopy:cstring length:strlen(cstring)];

We use dataWithBytesNoCopy here because the contents of the string  
are in

constant data, and can be guaranteed to not change or go away.


This is no good. NSData will attempt to free your constant string when
it's destroyed. You need to explicitly say freeWhenDone:NO here,
because not specifying it is equivalent to YES.


Erp... right you are. That last line should indeed be

  return [NSData dataWithBytesNoCopy:cstring length:strlen(cstring)  
freeWhenDone:NO];

___

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

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

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

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


Re: Obj-C equivalent to Python generator functions

2009-04-04 Thread Marcel Weiher


On Apr 1, 2009, at 19:04 , Sam Krishna wrote:

Does anyone here know of any Obj-C functional equivalent to Python  
generator functions? These are *categorically* different that the  
Spotlight API generator functions.

http://is.gd/qcYt


There is no direct equivalent at the language level, because Objective- 
C does not support coroutines (and even light-weight coroutines such  
as generators).  However, generators can usually (always?) be  
transformed into methods of objects by storing the temporary variables  
in instance variables and thus saving temporary state across  
invocations.


If you want to get fancier, you could use one of the coroutine  
packages for C and apply it to Objective-C (google  "coroutines in c" ).



Here's the code for a fibonacci generator created using the generator - 
> object covnersion technique described above:



#import 

@interface FibGen : NSEnumerator
{
int current,previous;
}

@end

@implementation FibGen : NSEnumerator
-init
{
if ( self=[super init]) {
previous=0;
current=1;
}
return self;
}

-nextObject
{
id retval=[NSNumber numberWithInt:current];
int next=previous+current;
previous=current;
current=next;
return retval;  
}

@end

int main( int argc, char *argv[] )
{
id pool=[NSAutoreleasePool new];
id fib=[FibGen new];
for ( id  no in fib ) {
NSLog(@"next: %@",no);
}   
return 0;
}

mar...@spock[tmp]./generator
2009-04-04 14:49:30.118 generator[69984:10b] next: 1
2009-04-04 14:49:30.120 generator[69984:10b] next: 1
2009-04-04 14:49:30.120 generator[69984:10b] next: 2
2009-04-04 14:49:30.120 generator[69984:10b] next: 3
2009-04-04 14:49:30.121 generator[69984:10b] next: 5
2009-04-04 14:49:30.121 generator[69984:10b] next: 8
2009-04-04 14:49:30.121 generator[69984:10b] next: 13
2009-04-04 14:49:30.122 generator[69984:10b] next: 21
2009-04-04 14:49:30.122 generator[69984:10b] next: 34
2009-04-04 14:49:30.123 generator[69984:10b] next: 55
2009-04-04 14:49:30.123 generator[69984:10b] next: 89
2009-04-04 14:49:30.123 generator[69984:10b] next: 144
2009-04-04 14:49:30.123 generator[69984:10b] next: 233
2009-04-04 14:49:30.124 generator[69984:10b] next: 377
2009-04-04 14:49:30.124 generator[69984:10b] next: 610
2009-04-04 14:49:30.124 generator[69984:10b] next: 987
2009-04-04 14:49:30.125 generator[69984:10b] next: 1597
2009-04-04 14:49:30.125 generator[69984:10b] next: 2584
2009-04-04 14:49:30.125 generator[69984:10b] next: 4181
2009-04-04 14:49:30.125 generator[69984:10b] next: 6765
2009-04-04 14:49:30.126 generator[69984:10b] next: 10946
2009-04-04 14:49:30.126 generator[69984:10b] next: 17711
2009-04-04 14:49:30.126 generator[69984:10b] next: 28657
2009-04-04 14:49:30.127 generator[69984:10b] next: 46368
2009-04-04 14:49:30.127 generator[69984:10b] next: 75025
^C

___

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

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

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

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


Re: Using bindings to set NSImageView from filename

2009-04-04 Thread Scott Anguish


On 4-Apr-09, at 5:36 PM, Martin Cote wrote:


Hi,
I would like to know if there's a way to use bindings to set the  
image of an
NSImageView from a filename in Interface Builder.  As far as I can  
see, you

can only set the image from an NSImage instance.

I'm feeling that I'll have to write some code to do it, but if  
there's a way

to do it in IB, I would like to know how.


NSImageView has a valuePath binding. That's for just that purpose.

file:///Developer/Documentation/DocSets/com.apple.ADC_Reference_Library.CoreReference.docset/Contents/Resources/Documents/documentation/Cocoa/Reference/CocoaBindingsRef/BindingsText/NSImageView.html


___

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

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

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

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


Re: IB Plugin help

2009-04-04 Thread Kevin Cathey

Hi Jon,

Let's see if we can't get this figured out.

So the current problem you are having is that you cannot deploy an  
IBPlugin for use on your system, correct? If so, I have a few questions.


(1) How are you installing the plugin and framework? Are you placing  
both them in /Library/Frameworks, with the plugin inside the  
framework's resources folder?
(2) What is the bundle identifier for your framework (from the  
Properties tab in the target for your framework)? And what is the  
identifier for your plugin?
(3) Do you mind sending the output of running the following commands  
in Terminal (assuming you are running IB 3.1.2; if you are running  
3.1.1, then replace 3.1.2 with 3.1.1, and so forth):


defaults read com.apple.InterfaceBuilder3 IBKnownPluginPaths.3.1.2
defaults read com.apple.InterfaceBuilder3 IBLoadedPluginIdentifiers. 
3.1.2


Kevin

--
Kevin Cathey



Namaste!

Just want to pass on some further information.

After that last post, the assertion error really bothered me.  So,  
after a while of careful inspection (to the limits of what I know),  
I decided to and "clean[ed] all targets" of both the debug and  
release builds and re-compiled.  In the plug-in project, runs of  
both debug and release went smoothly - IB loaded the plug-in, I was  
able to use it, close and re-open nibs successfully.  No errors.


"Deploying" the plug-in is proving difficult.

I copied the release framework to Library/Frameworks.  I also copied  
the framework into the frameworks section of a live project.  I then  
created a test.xib in my live project, which I subsequently opened.   
In the Preferences->Plug-ins pane for IB, I attempted to add the  
plug-in.  I got nothing - no error, nor plug-in.


I then added the ibplugin file to the Resources folder of the  
version A of the framework.


I then repeated the process of copying.  This time, the plug-in  
appeared in IB.  I added a textfield to test.xib, and applied the  
plug-in to it.  I saved and closed the file.  Upon re-open, IB  
didn't open the xib, but popped up the standard "create a resource"  
dialog - test had gotten kaboshed.


I do notice that the Required Frameworks is displaying the .ibplugin  
file instead of the expected .framework file.  I don't know if that  
is related or not.


Again, I'll be happy to send up the project should you want to see it.

Thanks!

Peace, Love, and Light,

/s/ Jon C. Munson II


___

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

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

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

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