Re: NSManagedObject validateForDelete problem

2009-03-14 Thread Ward Ruth
Thanks for the feedbacks -- makes total sense to me now. Yeah, I was  
under the mistaken impression NSManagedObject's -validateForDelete was  
something that would work for me to call before actually attempting  
the delete. After actually performing a delete and save (based on my  
toy example) I see things behave and get deleted without errors as  
expected.


I'll implement my own -isDeletable type methods on my managed objects  
in order to check them before potentially erroneously deleting them  
and having to present the user with a confusing message when they  
attempt to save.


Thanks again,

Ward
___

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

Please do not post admin requests or moderator comments to the list.
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: Performance problem with GC enabled

2009-03-14 Thread Paul Sanders
> If Apple later on wants to change how it works
> internally so that the function returns a temporary object instead,
> well, too bad, can't!

Well, that's patently untrue.  It can just return a temporary object with a 
retain count of 1.

It comes down to a simple question of whether or not you are happy to entask 
programmers to release objects - any object - when they are done with them. 
I personally feel a lot happier doing things that way as (a) I can get rid 
of things I don't want in timely fashion, and (b) I can test my program for 
memory leaks.  Autorelease pools make the latter effectively impossible. 
It's no coincidence that a lot of programmers new (and perhaps not-so-new) 
to the Mac have object lifetime issues.

I think it is a practical impossibility to prove your app is leak-free under 
Cocoa whereas on a certain other platform I can and do check if there is any 
memory left allocated at the end of the app (assuming everything is 
correctly released on shutdown).  I really miss the ability to do that and I 
know for a fact that what I will end up shipping will have memory leaks, 
somewhere.

___

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

Please do not post admin requests or moderator comments to the list.
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: Performance problem with GC enabled

2009-03-14 Thread Paul Sanders
> How about perl instead? (I don't think egrep is a fair test, it
> doesn't have to 'do anything' with the results, like create a new
> string from them). This is a rough perl equivalent of my original
> problem:

I guess that's the point I was trying to get across - the overhead of 
creating all those strings (and whatever other temporary objects have to be 
created behind the scenes) might be significant.  Ditto in perl, perhaps, I 
really wouldn't know.  There's of no reason why the underlying RegEx 
implementation needs to be inefficient if it's well written.

As Michael Ash has been kind enough to document, object instantiation is 
quite expensive :

http://www.mikeash.com/?page=pyblog/performance-comparisons-of-common-operations.html

But of course, if you need to break your original text up into NSString's, 
there's not much you can do about it.

I'm sorry Bill, but the more I hear about GC and in particular the 
difficulties of using it with malloc'd memory the gladder I am not to be 
using it.  I guess that one should not be surprised that it is difficult to 
retro-fit it in the way that you are forced to.  Caveat emptor!

Rgds - Paul Sanders

___

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

Please do not post admin requests or moderator comments to the list.
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: Calling Script Objects in Applescript

2009-03-14 Thread has

Karen van Eck wrote:


We have a lot of code in libraries in Applescript. Now starting to
look at using Cocoa to move forward, as we are really using
Applescript to pretty much its limit.

But it is not a short term solution to rewrite all our Applescript
libraries in Objective-C. We need to be able to use Objective-C
programs to load and execute our Applescripts.

I've managed to get a program to execute an Applescript and to execute
a handler in an Applescript.

But most of our libraries are saved as Script Objects. Please could
someone point me in the right direction for executing a subroutine
inside a script object in an Applescript.



Neither NSAppleScript nor OSAKit wrappers expose the APIs you need for  
this, therefore, you will need to use the Carbon OSA APIs directly.  
Use OSALoadFile to load the script, OSAGetProperty to copy the script  
object into a new slot, and OSAExecuteEvent to invoke its handlers.


You can save yourself a bunch of work if you use objc-appscript's  
AEMCodecs class to convert your Cocoa objects (NSStrings, NSArrays,  
etc.) to/from NSAppleEventDescriptors, which in turn are easily  
converted to Carbon AEDescs. There's an example project,  
CallAppleScriptHandler, in the objc-appscript repository that shows  
how to do most of this.


BTW, best place for these sorts of questions is applescript- 
implementors:


http://lists.apple.com/mailman/listinfo/applescript-implementors

More focused, less crowded.

HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.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: Performance problem with GC enabled

2009-03-14 Thread Michael Ash
On Sat, Mar 14, 2009 at 6:11 AM, Paul Sanders  wrote:
>> If Apple later on wants to change how it works
>> internally so that the function returns a temporary object instead,
>> well, too bad, can't!
>
> Well, that's patently untrue.  It can just return a temporary object with a
> retain count of 1.

No, it can't. I specified a Get function, where convention specifies
that the caller does not own it. Even if Apple were willing to break
with convention, such a change would cause every existing client of
the API to start leaking.

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: Calling Script Objects in Applescript

2009-03-14 Thread Ken Tozier
Have you looked at OSAKit? It has methods for executing subroutines of  
scripts without having to do that "initWithSource" hack.


You can find the header files here: "/System/Library/Frameworks/ 
OSAKit.framework/Versions/A/Headers/"


A couple of caveats about using it though. Subroutine names have to be  
all lowercase when you call them and parameters you feed to the script  
MUST be enclosed in an NSArray, even if your script only takes one  
parameter. So, for example if the subroutine name in the script is  
"DoSomethineNifty" you have to call it as "dosomethingnifty"


Here's a sampling of what you'll find in the OSAKit->script header  
file (Note the "executeHandlerWithName" method)


// Construction
- (id)initWithSource:(NSString *)source;
- (id)initWithSource:(NSString *)source language:(OSALanguage  
*)language;
- (id)initWithContentsOfURL:(NSURL *)url error:(NSDictionary  
**)errorInfo;
- (id)initWithContentsOfURL:(NSURL *)url language:(OSALanguage  
*)language error:(NSDictionary **)errorInfo;
- (id)initWithCompiledData:(NSData *)data error:(NSDictionary  
**)errorInfo;


// Accessors
- (NSString *)source;
- (NSURL *)url;
- (OSALanguage *)language;
- (void)setLanguage:(OSALanguage *)language;
- (BOOL)isCompiled;

// Operations
- (BOOL)compileAndReturnError:(NSDictionary **)errorInfo;
- (NSAppleEventDescriptor *)executeAndReturnError:(NSDictionary  
**)errorInfo;
- (NSAppleEventDescriptor *)executeAppleEvent:(NSAppleEventDescriptor  
*)event error:(NSDictionary **)errorInfo;
- (NSAppleEventDescriptor *)executeAndReturnDisplayValue: 
(NSAttributedString **)displayValue error:(NSDictionary **)errorInfo;
- (NSAppleEventDescriptor *)executeHandlerWithName:(NSString *)name  
arguments:(NSArray *)arguments error:(NSDictionary **)errorInfo;

- (NSAttributedString *)richTextSource;
- (NSAttributedString *)richTextFromDescriptor:(NSAppleEventDescriptor  
*)descriptor;
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)type error: 
(NSDictionary **)errorInfo;
- (BOOL)writeToURL:(NSURL *)url ofType:(NSString *)type  
usingStorageOptions:(OSAStorageOptions)storageOptions error: 
(NSDictionary **)errorInfo;
- (NSData *)compiledDataForType:(NSString *)type usingStorageOptions: 
(OSAStorageOptions)storageOptions error:(NSDictionary **)errorInfo;


Also, Have you looked into AppleScript Studio? You can call built-in  
and custom Cocoa classes directly from your scripts which might be  
useful if you just need to use Cocoa classes in certain spots to speed  
things up.


For example:
To load an NSDictionary:
set dict to call method "dictionaryWithContentsOfFile:" of class  
"NSDictionary" with parameter "/path/to/a/plist/file"

set x to (|some key| of dict) as string -- as list -- as record
log x
log dict

To split a string at a delimiter
set testString to "Homer says Doh!"
set parts to call method "componentsSeparatedByString:" of testString  
with parameter " "

log parts


On Mar 13, 2009, at 10:23 AM, Karen van Eck wrote:

We have a lot of code in libraries in Applescript. Now starting to  
look at using Cocoa to move forward, as we are really using  
Applescript to pretty much its limit.


But it is not a short term solution to rewrite all our Applescript  
libraries in Objective-C. We need to be able to use Objective-C  
programs to load and execute our Applescripts.


I've managed to get a program to execute an Applescript and to  
execute a handler in an Applescript.


But most of our libraries are saved as Script Objects. Please could  
someone point me in the right direction for executing a subroutine  
inside a script object in an Applescript.


I'm guessing I could do something like:

	NSApplescript *scriptObject = [[NSAppleScript alloc]  
initWithSource: @"set scriptObject to (scriptObjectName of (load  
script file scriptPath))

 
  tell scriptObject to doHandler()"];

and execute it, but that seems to be quite klunky. There must be a  
neater way to do it.


Any advice, hints and links will be gratefully received.

Thank you

Karen






___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/kentozier%40comcast.net

This email sent to kentoz...@comcast.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: How to use MySql, which api is for that

2009-03-14 Thread Karolis Ramanauskas
I happily used ActiveRecord
http://github.com/aptiva/activerecord/tree/master
Look how nice it is to connect:

NSDictionary * databaseConnectionInfo = [NSDictionary
dictionaryWithObjectsAndKeys:

@"127.0.0.1", @"host",

@"obama", @"user",

@"supersecretpassword", @"password",

@"databasename", @"database",

[NSNumber numberWithInt:3306], @"port", nil];

mySQLConnection = [[ARMySQLConnection alloc] init];

NSError * databaseError = nil;

[mySQLConnection initWithConnectionInfo:databaseConnectionInfo error
:&databaseError];

[mySQLConnection executeSQL:@"TRUNCATE TABLE trial" substitutions:nil];
___

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

Please do not post admin requests or moderator comments to the list.
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


Any interest in an article comparing and contrasting Cocoa with MS Managed C++ with CLI

2009-03-14 Thread Erik Buck
I am a Cocoa expert, and I have been teaching myself Microsoft Managed  
C++ (a language very different from ANSI/ISO standard C++) along with  
Microsoft's CLR/CLI (.Net) frameworks.


I am still a novice with Managed C++ and .Net, but I have already  
drawn some conclusions that were surprising to me.  Is anyone  
interested in an article or series of articles comparing and  
contrasting Managed C++ with Objective-C and CLI (.Net) with Cocoa ?


I started with the ubiquitous "Currency Converter" example, and so far  
I have worked up to a flexible interactive engineering units  
conversion calculator.  I have examined interface building tools,  
model development support tools, binding and data source techniques,  
etc.


Assuming there is interest, is there a preferred venue ?  Scott, are  
you interested in articles for Stepwise ?

___

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

Please do not post admin requests or moderator comments to the list.
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: Performance problem with GC enabled

2009-03-14 Thread Bill Bumgarner

On Mar 14, 2009, at 3:29 AM, Paul Sanders wrote:

I'm sorry Bill, but the more I hear about GC and in particular the
difficulties of using it with malloc'd memory the gladder I am not  
to be
using it.  I guess that one should not be surprised that it is  
difficult to

retro-fit it in the way that you are forced to.  Caveat emptor!


Heh.  No need to apologize.  Seriously -- no need --  do whatever you  
need to do to serve your customer's needs as efficiently as you can!


I simply fail to understand the difficulty of using GC. with malloc'd  
memory.   Malloc'd memory works *exactly* as it always has.


Instead of calling free() in -dealloc, you call it in -finalize.

As for storing object references into malloc()'d memory, you need to  
CFRetain()/CFRelease() on the way in/out.  Same as always, but a  
function call -- that will work in non-GC -- vs. a method call.


As for interior pointers;   interior pointers are equally as  
problematic under GC vs. non-GC.   Under GC, they tend to blow up a  
little bit sooner, but only in situations where the non-GC pattern was  
-- at the very least -- fragile to start with.


Given all of that combined with the overall boost in programmer  
productivity at the higher level and the decreased number of crashes  
in the application, especially plug-in driven applications, I --  
personally -- will never waste my customer's time writing non-GC'd  
Cocoa code again, given the choice (and, to be utterly clear, there  
are a number of non-technical reasons to stick with non-GC -- iPhone,  
being the 800 lbs gorilla in the room).


Furthermore, by embracing GC, my applications will be faster and even  
easier to debug as the underlying collector is improved.  For those of  
you who paid attention to the speed of GC under Leopard, there was a  
many times performance improvement between it being first turned on  
and what was finally released.


Obviously, I can't speak to Snow Leopard performance beyond saying  
that there has been significant effort on this front.


GC is similar to Core Data.   If you had a Core Data app on Tiger,  
there were numerous operations on Leopard that were significantly  
faster -- many, many times faster -- that you got for free.


But, heck, if you think it will serve your product's time to market  
better by focusing on the innards than the directly customer facing  
bits and then playing catch-up when Apple significantly advances the  
state of the art of similar technologies, well... bully for you!


(Yah -- snarky -- I know -- but, seriously, if every engineering  
decision is not made in the "how does this best serve my target  
users?", then you are likely asking and answering the wrong question...)


b.bum
___

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

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

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

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


Re: Performance problem with GC enabled

2009-03-14 Thread Kyle Sluder
On Sat, Mar 14, 2009 at 12:22 PM, Bill Bumgarner  wrote:
> On Mar 14, 2009, at 3:29 AM, Paul Sanders wrote:
> GC is similar to Core Data.   If you had a Core Data app on Tiger, there
> were numerous operations on Leopard that were significantly faster -- many,
> many times faster -- that you got for free.

Interesting you bring up Core Data given the show-stopping bugs we've
seen with it when combined with GC.

--Kyle Sluder
___

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

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

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

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


How to create an NSDecimal?

2009-03-14 Thread WT

Hello all,

I was reading the "Number and Value Programming Topics for Cocoa"  
section about decimal numbers and  now I'm confused. If I want to use  
the C interface rather than the NSDecimalNumber class, how do I  
"instantiate" an NSDecimal struct? According to the "Foundation Data  
Types Reference", the fields of NSDecimal are private. I couldn't find  
any function that takes the necessary data and returns an NSDecimal,  
so how do I create an NSDecimal?


By the way, I searched the archives and found out that someone else  
asked the same question back in 2001 (http://lists.apple.com/archives/cocoa-dev/2001/Sep/msg00041.html 
) but the ensuing discussion went somewhere else and the original  
question never got answered.


Thanks in advance.
Wagner
___

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

Please do not post admin requests or moderator comments to the list.
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: Performance problem with GC enabled

2009-03-14 Thread Bill Bumgarner

On Mar 14, 2009, at 9:27 AM, Kyle Sluder wrote:

On Sat, Mar 14, 2009 at 12:22 PM, Bill Bumgarner  wrote:

On Mar 14, 2009, at 3:29 AM, Paul Sanders wrote:
GC is similar to Core Data.   If you had a Core Data app on Tiger,  
there
were numerous operations on Leopard that were significantly faster  
-- many,

many times faster -- that you got for free.

Interesting you bring up Core Data given the show-stopping bugs we've
seen with it when combined with GC.


Filed, right?   And fixed, I'd hope?

b.bum

___

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

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

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

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


Re: Performance problem with GC enabled

2009-03-14 Thread Paul Sanders
>> Well, that's patently untrue. It can just return a temporary object with 
>> a
>> retain count of 1.

> No, it can't. I specified a Get function, where convention specifies
> that the caller does not own it. Even if Apple were willing to break
> with convention, such a change would cause every existing client of
> the API to start leaking.

Ah, right, sorry.  I'm not saying the existing API would permit such a 
change, more's the pity.  All I'm saying (and I doubt that saying this has 
any value) is that it could, and in my opinion should, have been done that 
way in the first place.

Forgive me for cluttering up the mailing list with what is basically just a 
bit of a rant.  Subject closed as far as I am concerned.  Your page of 
objective C benchmarks is very handy by the way.

___

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

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

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

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


Re: Customizing an NSToolbar to wrap it's tools.

2009-03-14 Thread Joar Wingfors


On 13 mar 2009, at 23.55, Ken Tozier wrote:

I would like to customize an NSToolbar to make it's tools wrap  
rather than overflow, but I can't see any way to control the toolbar  
height. Is there some way to do this? I've had a lot of practice  
writing wrapping views but NSToolbar seems to be locked up pretty  
tight as far as how it lays out items so I don't know where to look.  
It's not even a subclass of NSView so there doesn't seem to be any  
way to set the size.


Specifically, I want to keep the unified titlebar/toolbar look but  
have complete control of the layout inside the toolbar. Anyone know  
if this can be done?



It can't be done. If you need this behavior / appearance, you'd have  
to implement your own toolbar.


j o a r


___

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

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

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

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


Messages between Threads

2009-03-14 Thread Gerriet M. Denkmann

I have a Main object  which has:

- (void)add2Number: (NSNumber *)n;
{
self.sum += [ n intValue ];;//  bound to TextField
self.count++;   //  bound to TextField and 
ProgressIndicator
}

The UserInterface has a Start/Stop button which does (on Start):
for (int i = 0; i < 10; i++ ) [ self add2Number: [ NSNumber  
numberWithInt: i ]];


Is fast - about 7400 aps (actions or additons per second), but of  
course cannot be stopped.


So I created an NSThread which does:
for( int i = 0; i < 10; i++ )
{
if ( [ [ NSThread currentThread ] isCancelled ] ) break;
NSNumber *n = [NSNumber numberWithInt: i];
	[  main performSelectorOnMainThread: @selector(add2Number:)  
withObject: n waitUntilDone: NO];

};

Is even faster (8000 aps) but the Stop-button is unusable. Seems like  
the performSelector message has a higher priority than the action  
method of the button.


So I changed to: ... waitUntilDone: YES.
Now the Stop button can be used to cancel the thread, but it is really  
slow: about 58 aps.

Obviously the switching between worker and main thread is rather costly.

So: what should be done?

What about:
for( int i = 0; i < 10; i++ )
{
if ( [ [ NSThread currentThread ] isCancelled ] ) break;
NSNumber *n = [NSNumber numberWithInt: i];
[ lockForSumAndCount lock];
[  main add2Number:n];
[ lockForSumAndCount unlock];
};

Fast it is, and stoppable too, but would it be save, given the fact  
that sum and count are bound to some textFields/progressIndicator?



Kind regards,

Gerriet.

___

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

Please do not post admin requests or moderator comments to the list.
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: Performance problem with GC enabled

2009-03-14 Thread Paul Sanders
> But, heck, if you think it will serve your product's time to market
> better by focusing on the innards than the directly customer facing
> bits and then playing catch-up when Apple significantly advances the
> state of the art of similar technologies, well... bully for you!

I believe I mentioned that I need to support Tiger, and I do feel competent 
to make such decisions, thanks all the same.

But it's good to know that GC will not 'reap' my malloc'd memory unless I 
ask it to.  If I get serious about using it (which I am not, currently) I 
will look into things in more detail.  As I said, I can see that for many 
developers GC is a big plus, but for me it is something I can easily do 
without.

___

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

Please do not post admin requests or moderator comments to the list.
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: Any interest in an article comparing and contrasting Cocoa with MSManaged C++ with CLI

2009-03-14 Thread Paul Sanders
> Is anyone interested in an article or series of articles comparing and
> contrasting Managed C++ with Objective-C and CLI (.Net) with Cocoa ?

Yes, very much so.  It would be good if you could post a notification to 
this list when you have decided where to publish this.  The Code Project 
might be a possible candidate (although it ihas a heavy Microsoft bias).

Rgds - Paul Sanders. 

___

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

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

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

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


Re: How to create an NSDecimal?

2009-03-14 Thread Ashley Clark

On Mar 14, 2009, at 11:28 AM, WT wrote:

I was reading the "Number and Value Programming Topics for Cocoa"  
section about decimal numbers and  now I'm confused. If I want to  
use the C interface rather than the NSDecimalNumber class, how do I  
"instantiate" an NSDecimal struct? According to the "Foundation Data  
Types Reference", the fields of NSDecimal are private. I couldn't  
find any function that takes the necessary data and returns an  
NSDecimal, so how do I create an NSDecimal?


You can get an NSDecimal structure from any NSNumber or  
NSDecimalNumber object by sending it the -decimalValue message. As far  
as I know that's the only way to create one.



Ashley
___

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

Please do not post admin requests or moderator comments to the list.
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: NSProgressIndicator's setUsesThreadedAnimation only works sometimes?

2009-03-14 Thread Keary Suska


On Mar 13, 2009, at 4:20 PM, Sean McBride wrote:


Hi all,

I'm trying to make a cheap, modal, indeterminate progress dialog, but
I'm having trouble animating the progress bar.

(Yes, I know this is only slightly better than the spinning wheel of
death.  Yes, I know I should thread my long running code.  Yes, I  
know I

should not block the main thread.  One day...)

The docs for NSProgressIndicator's setUsesThreadedAnimation say "This
value is only a hint and may be ignored".  Indeed, sometimes it  
animates

and sometimes it does not.  I can't find any pattern.

Is there a way to reliably make an NSProgressIndicator animate while  
the

main thread is blocked?



I have had success using -beginModalSessionForWindow: and an NSTimer  
that calls a method that checks for an end condition and calls - 
runModalSession:.


I have mostly used this in cases where I needed asynchronous behavior  
but I need to block the UI.


HTH,

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

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

Please do not post admin requests or moderator comments to the list.
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: Messages between Threads

2009-03-14 Thread Paul Sanders
> So: what should be done?

1.  Do the calculations in a sub-thread.

2.  Test a 'please stop' variable each time round the loop in that thread.

3.  Set this variable in the main thread when the user clicks the Stop 
button.

4.  To show progress, call performSelectorOnMainThread from the sub-thread. 
Do this every, say, 1000 loop iterations for efficiency.  That method (so to 
speak) is safe.  I'm not sure if other techniques are safe or not, but my 
guess is that they aren't.

The 'please stop' variable can be in a class object accessible to both 
threads, and can be accessed via getter and setter methods (which of course 
are each being called by a different thread) if you so choose.  Just be sure 
you have a reasonable grasp of the sort of issues doing this can involve 
before you write your code.  It is important, for example, that any objects 
the sub-thread might access do not go away until the thread has terminated.

http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.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: Calling Script Objects in Applescript

2009-03-14 Thread Matt Neuburg
On Fri, 13 Mar 2009 14:23:37 +, Karen van Eck
 said:
>We have a lot of code in libraries in Applescript. Now starting to
>look at using Cocoa to move forward, as we are really using
>Applescript to pretty much its limit.
>
>But it is not a short term solution to rewrite all our Applescript
>libraries in Objective-C. We need to be able to use Objective-C
>programs to load and execute our Applescripts.
>
>I've managed to get a program to execute an Applescript and to execute
>a handler in an Applescript.
>
>But most of our libraries are saved as Script Objects. Please could
>someone point me in the right direction for executing a subroutine
>inside a script object in an Applescript.

Useful code here:

http://lists.apple.com/archives/applescript-implementors/2001/Apr/msg1.h
tml

There's an Objective-C version of calling the 'ascr/psbr' Apple event on p.
479 of my book, and Ken Ferry has a wonderful set of convenience methods
(http://homepage.mac.com/kenferry/software.html). m.

-- 
matt neuburg, phd = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings



___

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

Please do not post admin requests or moderator comments to the list.
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: Performance problem with GC enabled

2009-03-14 Thread Sean McBride
Bill Bumgarner (b...@mac.com) on 2009-03-14 12:40 PM said:

>On Mar 14, 2009, at 9:27 AM, Kyle Sluder wrote:
>> On Sat, Mar 14, 2009 at 12:22 PM, Bill Bumgarner  wrote:
>>> On Mar 14, 2009, at 3:29 AM, Paul Sanders wrote:
>>> GC is similar to Core Data.   If you had a Core Data app on Tiger,
>>> there
>>> were numerous operations on Leopard that were significantly faster
>>> -- many,
>>> many times faster -- that you got for free.
>> Interesting you bring up Core Data given the show-stopping bugs we've
>> seen with it when combined with GC.
>
>Filed, right?   And fixed, I'd hope?

I suspect Kyle is referring to the hangs when combining
NSPersistentDocument + GC + SQL stores.  

100% repro, causes data loss, not fixed. :(

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


Re: Performance problem with GC enabled

2009-03-14 Thread Sean McBride
Paul Sanders (p.sand...@dsl.pipex.com) on 2009-03-14 6:29 AM said:

>I'm sorry Bill, but the more I hear about GC and in particular the
>difficulties of using it with malloc'd memory the gladder I am not to be
>using it.

My unsolicited 2¢: :)

I am happy that the GC implementation keeps GC memory and malloc memory
separate.  It makes using C/C++ libraries in your GC Cocoa app much
easier.  Such libraries expect malloc to work the usual way, and would
likely need all kinds of changes were malloc's behaviour changed.  I
work on a GC Cocoa app that uses several C and C++ libraries.  It has
not been difficult to integrate them.  In fact, I spent more time
retrofitting Obj-C libraries that were written to support retain-release only.

I have found it much more pleasurable to work in GC, and would not go back!

The biggest problems I have encountered are:

1) tools support.  Finding classic leaks is basically impossible. :
(  Recall that I use C and C++ libraries, and so have a need to do
classic leak checking.  MallocDebug.app crashes with GC apps, and
'leaks' and Instruments find nothing but false positives.

2) premature collection wrt inner pointers.  Easily fixed by grepping
for bytes|mutableBytes|fileSystemRepresentation|bitmapData and
defensively sprinkling some [obj self] messages around.

3) NSPersistentDocument + GC + Core Data's SQL store don't work
together.  So I'm stuck with the XML store. :(

4) Universal Binary testing.  Rosetta does not support GC.  This means
that your unit tests can't run in Rosetta, like they can and do with
retain-release.  Easily fixed by scrounging up a real PPC from somewhere.

As for performance, I have encountered several instances where Shark
reports various libauto calls in the top 5, but I have not investigated
due to other priorities.

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


Re: How to create an NSDecimal?

2009-03-14 Thread Luca Pazzerello
You can also create NSDecimals using NSDecimalFromString().
--Luca C.

2009/3/14 Ashley Clark 
>
> You can get an NSDecimal structure from any NSNumber or NSDecimalNumber
> object by sending it the -decimalValue message. As far as I know that's the
> only way to create one.
>
>
> Ashley
>
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> http://lists.apple.com/mailman/options/cocoa-dev/luca.pazzerello%40gmail.com
>
> This email sent to luca.pazzere...@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: Performance problem with GC enabled

2009-03-14 Thread Bill Bumgarner

To bring this back around to the concrete...

First -- a very hearty and public THANK YOU to Sean for filing quality  
bug reports that often include minimal examples.  The community has  
definitely benefited from your contributions to the bug database!


On Mar 14, 2009, at 11:17 AM, Sean McBride wrote:

1) tools support.  Finding classic leaks is basically impossible. :
(  Recall that I use C and C++ libraries, and so have a need to do
classic leak checking.  MallocDebug.app crashes with GC apps, and
'leaks' and Instruments find nothing but false positives.


The Object Graph instrument in Instruments does a pretty good job in  
Leopard, though it has bugs, too.   Turn off automatic sampling.


Most of what you are looking for in GC'd apps -- and, frankly, not  
enough people look for in non-GC'd apps -- is unexpected growth of the  
object graph or unexpected lack of shrinkage.   The easiest way to  
test for this is to repeat a task a couple of times.   The object  
graph *should* reach a stable state with the only growth being in  
caches (though, hopefully not for repeated actions), logs, and any  
other new data the app may have pulled in.


The 'heap' command can also give you an inventory of objects that  
remain in existence within your app.   Comparing the output of  
repeated heap scans can do wonders for figuring out why an app is  
growing.   The object inventory section -- the part that lists the #  
of any given type of object -- can generally be diff'd or opened in  
FileMerge.


Frankly, though, the tools are a bit primitive in Leopard   If  
there are workflows that are broken for you, please file bugs.
However, if you have access to the Snow Leopard seeds, try and give a  
test in SL before filing the bugs, if possible.



2) premature collection wrt inner pointers.  Easily fixed by grepping
for bytes|mutableBytes|fileSystemRepresentation|bitmapData and
defensively sprinkling some [obj self] messages around.


That works.   Patrick Beard took the suggestion of using the cleanup()  
attribute and refactored it for use with GC.  This works on Leopard.


This could be refactored for both GC and Non-GC by using [*object  
release] and just dropping the objc_collect() -- it is only a hint  
anyway.The -release will be ignored in GC, but the collector  
doesn't know that. :)


#import 

#define GCKEEPALIVE __attribute__((cleanup(touchObject)))
static inline void touchObject(id *object) {
[*object self];
objc_collect(OBJC_COLLECT_IF_NEEDED);
}

int main (int argc, const char * argv[]) {
while (--argc) {
const char *arg = *++argv;
GCKEEPALIVE NSData *page = [NSData dataWithContentsOfURL: 
[NSURL URLWithString:[NSString stringWithUTF8String:arg]]];

const char *bytes = [page bytes];
printf("page = %s\n", bytes);
}
return 0;
}


As for performance, I have encountered several instances where Shark
reports various libauto calls in the top 5, but I have not  
investigated

due to other priorities.


Bug reports that contain performance issues are taken extremely  
seriously.   Bugs filed with -- even binary only -- relatively minimal  
demonstrations of issues are captured and retested often to ensure  
that we are, at the very least, not making the issue worse and, of  
course, the goal is to make things go faster.


b.bum


___

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

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

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

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


Re: EXC_BAD_ACCESS on NSImageView::setImage

2009-03-14 Thread Volker in Lists

Hi,

retainCount is not in anyway useful when debugging - I had many cases  
of rc > 5 with the object being gone the next instance. your error  
sounds like you loose the image at some point in time. retain it and  
use Instruments to see if you leak or over alloc.


Volker

Am 14.03.2009 um 01:23 schrieb Dev:

On Wed, Mar 11, 2009 at 9:33 AM, Scott Ribe > wrote:

Does your setImage method retain the image?


The object ExternalView is a NSImageView so the setImage is the one of
NSImageView.
The doc says nothing about it, but i added some debug log like this :

  NSLog(@"BEFORE : %d", [NewDisplayImage  
retainCount]);

  [CameraView setImage:NewDisplayImage];
  NSLog(@"AFTER : %d", [NewDisplayImage  
retainCount]);


2009-03-13 17:17:35.105 xxx[2281:e503] BEFORE : 1
2009-03-13 17:17:35.106 xxx[2281:e503] AFTER : 3

So i guess the image have been retained 2 times 
--
I.
___

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

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

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/volker_lists%40ecoobs.de

This email sent to volker_li...@ecoobs.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: Performance problem with GC enabled

2009-03-14 Thread Wade Tregaskis

Ah, right, sorry.  I'm not saying the existing API would permit such a
change, more's the pity.  All I'm saying (and I doubt that saying  
this has
any value) is that it could, and in my opinion should, have been  
done that

way in the first place.


It's very tempting to try to enforce this in a CF-based API.  It also  
turns out to be really annoying to use the subsequent API.  If you  
look at CoreFoundation itself, you'll find a lot of void returns  
(what, errors?  impossible!) and non-retaining getters... these make  
it really simple to use and impossible to use safely, and impossible  
to improve the implementation there-of.  You really appreciate this  
the first time you re-implement a function conscious of the fact that  
it now deliberately leaks every time it's called (don't ask, the  
memory still makes me cry).


Having written libraries/frameworks at both the C, CF and Cocoa  
levels, if you told me you were writing one in anything less than  
Objective-C, I would slap you in the face, shake you by the shoulders  
and scream "Why?  Oh god why?".  And you'd better have a damn good  
reason (there are some, but they're thankfully rarely applied), else  
I'll revoke your programming privileges for eighteen months. :P


And though personally I dislike GC, if you said you weren't supporting  
it, I'd be upset much the same.  It should be pretty obvious to  
everyone that GC is ultimately the way forward, and that it's only  
going to get better as time goes on. Reference-counting is virtually  
static.  It will not magically improve in any significant way.  If you  
think GC can never outperform it, even in theory, I'd politely suggest  
you haven't considered the matter very well.


So while it's not a panacea today, complaining about it on lists is  
not productive (as opposed to seeking workarounds in a constructive  
manner, which is entirely appropriate).  Please file bugs, as Bill has  
reiterated over and over.  How many software companies do you  
personally get begged by to optimise your specific use?


Wade
___

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

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

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

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


Re: How to create an NSDecimal?

2009-03-14 Thread Ashley Clark
I don't see NSDecimalFromString() in any of the docs or header files,  
only NSDecimalString() to create strings. Where is that defined?



Ashley


On Mar 14, 2009, at 2:08 PM, Luca Pazzerello wrote:


You can also create NSDecimals using NSDecimalFromString().
--Luca C.

2009/3/14 Ashley Clark 


You can get an NSDecimal structure from any NSNumber or  
NSDecimalNumber
object by sending it the -decimalValue message. As far as I know  
that's the

only way to create one.


___

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

Please do not post admin requests or moderator comments to the list.
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


HTTP response using CFHTTPMessageCreateEmpty/CFHTTPMessageAppendBytes

2009-03-14 Thread Greg Hoover
I'm trying to parse an HTTP Post response using the following code.   
The problem is that CFHTTPMessageAppendBytes always returns false.   
I've tested by stripping down the response to just "HTTP/1.0 200 OK\r\n 
\r\n" and still no go.  Does anyone know what the appropriate response  
format is?


CFHTTPMessageRef response =  
CFHTTPMessageCreateEmpty(kCFAllocatorDefault, TRUE);

if (CFHTTPMessageAppendBytes(response, [data bytes], [data length])) {
if (CFHTTPMessageIsHeaderComplete(response)) {
...
}}

Thanks in advance.
___

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

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

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

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


How to flash two rectangles in a frame?

2009-03-14 Thread Philip Kime

I am trying to work out how to flash two rects in a frame. I have it
working with one rect using the view cacheImageInRect method but this
only works on one rect. I tried putting two such calls in serial but
the second one doesn't work for some (optimisation?) reason. Then I
tried copying and modifying the code from the GNUstep implementation
of the method but this is too hard for me since I'm not a serious ObjC
or Cocoa programmer - the method is designed to be run as an instance
method and the code wasn't suitable for just calling directly in a
routine. I never got it to work. So, I subclassed  NSWindow and tried
adding a "cacheImagesInRects" method but again, I couldn't get this to
work - the "restoreImagesInRects" never seemed to restore anything.

I also tried just colouring the rects with
NSRectFillListWithColorsUsingOperation, hoping to be able to use
NSCompositeLighter and then NSCompositeDarker to reverse the change.
Again, no luck - it almost looked right with a simple DeviceWhite 50%
alpha fill and then Lighter/Darker change but not quite. Any other
colour (which I needed) just failed to reverse and the rects stayed in
the "on" flash state.

I've spent far, far too much time on this now and I realise I'm just
not knowledgeable enough in ObjC or Cocoa. So, any hints on how to
approach flashing two rectangles at the same time? This was so easy in
Carbon - InvRect().

PK


___

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

Please do not post admin requests or moderator comments to the list.
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


PDFView drag and drop

2009-03-14 Thread Uribe Emiro
Hello my name is Emiro Uribe and I am new to Cocoa. My system is OS X  
10.4 and Xcode 2.5.

I am trying to make PDFView a source for drag and drop.
I would like to be able to drag the inner view into other applications.
I see that I can set it to be destination by setting  
setAllowsDragging:YES, but

can you point me in the right direction for making it a source?
Thank you for consideration.



___

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

Please do not post admin requests or moderator comments to the list.
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: GC Thread - Please, do _not_ crosspost

2009-03-14 Thread Scott Anguish
The GC thread that is ongoing has been crossposted between cocoa-dev  
and obj-c. Please do not do this.


Crossposting between cocoa-dev and other groups is not allowed.  
Starting threads that are crossposted will cause your messages to be  
moderated, and that will slow down posting.


Also, please remember that if you're going to speak to an issue,  
please try and be authoritative. There has been some information,  
particularly in this thread, that has been argued very articulately,  
but been 100% wrong nonetheless. Engineers that work on these areas  
have been concerned as a result.


Thanks

scott


___

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

Please do not post admin requests or moderator comments to the list.
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: PDFView drag and drop

2009-03-14 Thread Jean-Daniel Dupas


Le 14 mars 09 à 21:24, Uribe Emiro a écrit :

Hello my name is Emiro Uribe and I am new to Cocoa. My system is OS  
X 10.4 and Xcode 2.5.

I am trying to make PDFView a source for drag and drop.
I would like to be able to drag the inner view into other  
applications.
I see that I can set it to be destination by setting  
setAllowsDragging:YES, but

can you point me in the right direction for making it a source?
Thank you for consideration.


What about the "Dragging Sources" section of the "Drag and Drop  
Programming Topics for Cocoa" ?



http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/DragandDrop/Concepts/dragsource.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: How to create an NSDecimal?

2009-03-14 Thread Keary Suska

On Mar 14, 2009, at 2:35 PM, Ashley Clark wrote:

I don't see NSDecimalFromString() in any of the docs or header  
files, only NSDecimalString() to create strings. Where is that  
defined?


It's part of Foundation, defined in NSDecimal.h.


On Mar 14, 2009, at 2:08 PM, Luca Pazzerello wrote:


You can also create NSDecimals using NSDecimalFromString().
--Luca C.

2009/3/14 Ashley Clark 


You can get an NSDecimal structure from any NSNumber or  
NSDecimalNumber
object by sending it the -decimalValue message. As far as I know  
that's the

only way to create one.



Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

___

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

Please do not post admin requests or moderator comments to the list.
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: [MODERATOR] Re: GC Thread - Please, do _not_ crosspost

2009-03-14 Thread Paul Sanders
I think a lot of that was aimed at me, although I didn't start the 
cross-post.

Once again I'd like to apologise for cluttering up the list with irrelevant 
chit-chat.  That was not the intention and it's not as if it's going to 
change anything, however valid or otherwise my opinion might be.  I will try 
to stick to the point in future.

Please convey my best wishes to the engineers.  Cocoa, and the Mac in 
general, is a fine achievement and looking forward to the day when my 
[Windows] app is up and running there gets me up in the morning.

Rgds - Paul Sanders.

- Original Message - 
From: "Scott Anguish"
To: 
Sent: Saturday, March 14, 2009 9:42 PM
Subject: [MODERATOR] Re: GC Thread - Please, do _not_ crosspost


The GC thread that is ongoing has been crossposted between cocoa-dev
and obj-c. Please do not do this.

Crossposting between cocoa-dev and other groups is not allowed.
Starting threads that are crossposted will cause your messages to be
moderated, and that will slow down posting.

Also, please remember that if you're going to speak to an issue,
please try and be authoritative. There has been some information,
particularly in this thread, that has been argued very articulately,
but been 100% wrong nonetheless. Engineers that work on these areas
have been concerned as a result.

Thanks

scott

___

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

Please do not post admin requests or moderator comments to the list.
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


iPhone UIWebView height?

2009-03-14 Thread William Jon Shipley
Is it possible to set an HTML string on a UIWebView and have it resize  
automatically to the right height, but NOT take up the entire screen?


I sure can't figure it out. I feel like the iPhone really HATES rich  
text.


Here's what I've tried so far. Most of these are "Hail Mary" attempts,  
which I didn't expect to work:


UIWebView *synopsisWebView = [[UIWebView alloc] initWithFrame: 
(CGRect){CGPointZero, {CGRectGetWidth(self.scrollView.frame), 30.0}}];
synopsisWebView.autoresizingMask =  
UIViewAutoresizingFlexibleHeight; // unrelated?

synopsisWebView.scalesPageToFit = YES; // just shrinks text
[synopsisWebView loadHTMLString:synopsisHTMLString  
baseURL:nil];

[self.scrollView addSubview:synopsisWebView];
[synopsisWebView layoutIfNeeded]; // no visible effect
[synopsisWebView release];
NSLog(@"synopsisWebView frame %@",  
NSStringFromCGRect(synopsisWebView.frame)); // still 30 high!



-W
___

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

Please do not post admin requests or moderator comments to the list.
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: Messages between Threads

2009-03-14 Thread Michael Ash
On Sat, Mar 14, 2009 at 1:29 PM, Paul Sanders  wrote:
>> So: what should be done?
>
> 1.  Do the calculations in a sub-thread.
>
> 2.  Test a 'please stop' variable each time round the loop in that thread.
>
> 3.  Set this variable in the main thread when the user clicks the Stop
> button.

Better yet, test NSThread's isCanceled in your loop, and use the
cancel method. Obviously, only works if you don't support Tiger.

> 4.  To show progress, call performSelectorOnMainThread from the sub-thread.
> Do this every, say, 1000 loop iterations for efficiency.  That method (so to
> speak) is safe.  I'm not sure if other techniques are safe or not, but my
> guess is that they aren't.

Rather than doing it every 1000 iterations, make it be time-based.
Check the time since the last notification, and only message the main
thread if the current time is more than, say, 1/30th of a second
later. There's no point in updating the GUI more than 30Hz or so, and
this makes it so that it doesn't matter how long each individual
iteration takes to run. Depending on how long you expect the full
operation to take, you might update substantially less often than
this.

I'm not sure what you're referring to when you talk about "other
techniques", but in general it is forbidden to access the GUI of a
Cocoa app from secondary threads, so you pretty much have to use
performSelectorOnMainThread: or some equivalent to update your GUI.

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: How to create an NSDecimal?

2009-03-14 Thread Michael Ash
On Sat, Mar 14, 2009 at 6:55 PM, Keary Suska  wrote:
> On Mar 14, 2009, at 2:35 PM, Ashley Clark wrote:
>
>> I don't see NSDecimalFromString() in any of the docs or header files, only
>> NSDecimalString() to create strings. Where is that defined?
>
> It's part of Foundation, defined in NSDecimal.h.

It's not in any of the copies of NSDecimal.h on *my* system (10.5.6)

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: HTTP response using CFHTTPMessageCreateEmpty/CFHTTPMessageAppendBytes

2009-03-14 Thread Greg Hoover
Wow.  Don't you hate it when its staring you in the face and you still  
can't see it.


Thanks.

On Mar 14, 2009, at 5:31 PM, Michael Ash wrote:

On Sat, Mar 14, 2009 at 5:17 PM, Greg Hoover   
wrote:
I'm trying to parse an HTTP Post response using the following  
code.  The
problem is that CFHTTPMessageAppendBytes always returns false.   
I've tested
by stripping down the response to just "HTTP/1.0 200 OK\r\n\r\n"  
and still

no go.  Does anyone know what the appropriate response format is?

CFHTTPMessageRef response =  
CFHTTPMessageCreateEmpty(kCFAllocatorDefault,

TRUE);


From the documentation for CFHTTPMessageCreateEmpty:

Pass TRUE to create an empty request message; pass FALSE to create an
empty response message.

You're passing TRUE, indicating a request, but then you're feeding it
a response. What happens if you pass FALSE?

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: How to create an NSDecimal?

2009-03-14 Thread Michael Vannorsdel
Use the NSDecimalNumber class (subclass of NSNumber) and create it  
like you would any other NSNumber.  Then use decimalValue to get the  
NSDecimal struct from it.  There is no NSDecimalFromString, only the  
other way NSDecimalString.  The only other way is to do it is manually  
by setting the struct members.


typedef struct {
signed int _exponent:8;
unsigned int _length:4;
unsigned int _isNegative:1;
unsigned int _isCompact:1;
unsigned int _reserved:18;
unsigned short _mantissa[NSDecimalMaxSize];
 } NSDecimal;


On Mar 14, 2009, at 6:32 PM, Michael Ash wrote:

It's not in any of the copies of NSDecimal.h on *my* system  
(10.5.6)


___

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

Please do not post admin requests or moderator comments to the list.
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


Custom NSManagedObject Class Initializer

2009-03-14 Thread Richard Somers
I have a custom NSManagedObject class MyEntity. It works just fine.  
However when I add an initializer and override the superclass's  
designated initializer an error occurs.


[< MyEntity 0x1f3f70> valueForUndefinedKey:]: the entity (null) is not  
key value coding-compliant for the key myAttribute.


The initializer in MyEntity looks like this.

- (id)initWithEntity:(NSEntityDescription *)entity
insertIntoManagedObjectContext:(NSManagedObjectContext *)context
{
[super initWithEntity:entity
insertIntoManagedObjectContext:context];
return self;
}

Why does the superclass initializer work but my override does not?

Richard

___

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

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

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

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


Re: Custom NSManagedObject Class Initializer

2009-03-14 Thread mmalc Crawford


On Mar 14, 2009, at 8:02 PM, Richard Somers wrote:
I have a custom NSManagedObject class MyEntity. It works just fine.  
However when I add an initializer and override the superclass's  
designated initializer an error occurs.

[...]
{
   [super initWithEntity:entity
   insertIntoManagedObjectContext:context];
   return self;
}
Why does the superclass initializer work but my override does not?




mmalc

___

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

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

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

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


Re: Custom NSManagedObject Class Initializer

2009-03-14 Thread Kyle Sluder
On Sat, Mar 14, 2009 at 11:02 PM, Richard Somers
 wrote:
> I have a custom NSManagedObject class MyEntity. It works just fine. However
> when I add an initializer and override the superclass's designated
> initializer an error occurs.

Not only should you not do this, if you do you really need to return
the result of super's implementation.

- (id)initWithEntity:(NSEntityDescription *)desc
insertIntoManagedObjectContext:(NSManagedObjectContext *)ctx
{
  if(self = [super initWithEntity:desc insertIntoManagedObjectContext:ctx])
  {
 // do things here
  }

  return self;
}

--Kyle Sluder
___

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

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

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

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


Re: Performance problem with GC enabled

2009-03-14 Thread John Engelhart
On Fri, Mar 13, 2009 at 11:21 PM, Peter Ammon  wrote:
>
> I think you're saying that it's more convenient for you to work with a
> pointer than directly with an array.  If so, another way you can defeat
> write barriers is with a cast to void*:
> void func(id *ptr) {
>    ptr[0] = @"foo"; // <--- write barrier
>    ((void **)ptr)[0] = @"bar"; // < no write barrier
> }
> Of course, this is only safe if the pointer points at something not in the
> GC heap, e.g. on the stack or in malloc()ed memory.  If you store into the
> GC heap this way, your object is likely to be prematurely collected.

This particular idea did occur to me, but I choose not to pursue it.
The reason for this is because it's for RegexKitLite
(http://regexkit.sourceforge.net/RegexKitLite/index.html).  This is
compiled directly by the end user, under a wide variety of conditions,
so I have to err on the side of 'correctness'.  I made a judgement
call that this one (tricking the compiler with void *) cut it just a
bit too close.

Your objc_memmove suggestion, however, is pretty elegant.  If the
compiler chooses not to emit write barriers when storing to an 'id
strings[1024];' local variable, well.. I've met all my obligations
regarding strong pointers, now, and in the future, without hiding the
strong nature of the pointer from the compiler.  This should be able
to correctly handle any future GC changes as well, which is important.
 Strikes a good balance between being 'correct' while taking advantage
of 'observed implementation details'.

Again, thanks for the suggestion.  It's pretty clever and elegant,
even if it does make swiss cheese of the code with #ifdef statements.
:)
___

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

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

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

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


Re: How to create an NSDecimal?

2009-03-14 Thread WT

On Mar 15, 2009, at 1:50 AM, Michael Vannorsdel wrote:

The only other way is to do it is manually by setting the struct  
members.


typedef struct {
signed int _exponent:8;
unsigned int _length:4;
unsigned int _isNegative:1;
unsigned int _isCompact:1;
unsigned int _reserved:18;
unsigned short _mantissa[NSDecimalMaxSize];
} NSDecimal;


I don't think so. As I pointed out in my original post, the struct  
fields are private, according to "Foundation Data Types Reference". I  
don't know if Obj-C enforces a restriction such as struct fields being  
private but if it doesn't, I'd rather not write code that could break  
in the future if Apple decides to change the struct.


I'll stick with creating an NSDecimalNumber and then extracting the  
NSDecimal struct using -decimalValue.


Thanks to everyone who contributed to answer my question.
Wagner
___

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

Please do not post admin requests or moderator comments to the list.
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: iPhone UIWebView height?

2009-03-14 Thread Jesse Armand
This is also what I'm looking for.

I want to create a UIWebView with a frame size that will adjust itself
according to the contents of the HTML string, or even more simpler an
image.

Anybody have any experiences with this ?

Jesse Armand

(http://jessearm.blogspot.com)



On Sun, Mar 15, 2009 at 8:12 AM, William Jon Shipley
 wrote:
> Is it possible to set an HTML string on a UIWebView and have it resize
> automatically to the right height, but NOT take up the entire screen?
>
> I sure can't figure it out. I feel like the iPhone really HATES rich text.
>
> Here's what I've tried so far. Most of these are "Hail Mary" attempts, which
> I didn't expect to work:
>
>        UIWebView *synopsisWebView = [[UIWebView alloc]
> initWithFrame:(CGRect){CGPointZero, {CGRectGetWidth(self.scrollView.frame),
> 30.0}}];
>        synopsisWebView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
> // unrelated?
>        synopsisWebView.scalesPageToFit = YES; // just shrinks text
>        [synopsisWebView loadHTMLString:synopsisHTMLString baseURL:nil];
>        [self.scrollView addSubview:synopsisWebView];
>        [synopsisWebView layoutIfNeeded]; // no visible effect
>        [synopsisWebView release];
>        NSLog(@"synopsisWebView frame %@",
> NSStringFromCGRect(synopsisWebView.frame)); // still 30 high!
>
>
> -W
> ___
>
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/mnemonic.fx%40gmail.com
>
> This email sent to mnemonic...@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


[Q] inconsistent naming for Core Graphics and Foundation?

2009-03-14 Thread JongAm Park

Hello, all

I'm just curious about the naming convention for Core Graphics and  
Foundation.
For example, NSMakeRect and CGRectMake are similar but different about  
where the "Rect" is in its method name.

What is even worse is NSPointInRect and CGRectContainsPoint.
So, if a person is used to the Foundation convention, it is not  
intuitive to find proper method in Core Graphics.


Is there any reason they are named like that?

Thank you.

___

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

Please do not post admin requests or moderator comments to the list.
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