NSString's category to make stringWithFormat callable from ASOC?

Is it possible to add a category to NSString (in ObjC) to make this call from ASOC:

NSString stringWithFormat_(“SomethingWithAInteger%03d”,k) → “SomethingWithAInteger001”

work ? I get only “SomethingWithAInteger1”, without leading zeroes.

A kind of myString stringWithSpecialFormat_ . and please, not the AS trick :

       set numString to get text -3 thru -1 of ("00" & c)
       set the end of theArray to "SomethingWithAInteger" & numString

Thank you (ObjC programmers : please remember that Objective-C is only a name for me)

I’ve looked into doing this, because I think it would be useful for a lot of ASOC users. However, the problem is in the definition: + (id)stringWithFormat:(NSString *)format, …

That ellipsis means the method takes a variable number of arguments, and the way that works is complicated. It will take a much better objC programmer than me to tackle this.


Does anybody knows if ASOC will survive MacOS 10.7 or will the Lion eat it?

From Apple’s web site:

What a relief. Thank you Shane.

ObjC categories are not accessible from ASOC.
That’s one of the reasons I always recommend to spend the time to learn Objective-C.
There are none of the silly restrictions and coercion problems you have in ASOC.

AppleScript is the perfect solution for inter-application communication but for an stand-alone app
you should use the “adult” language :wink:

Yes they are. You can’t write them in ASObjC, but that’s not what the OP is asking.

But not everyone has the time or inclination.

But there are more than enough other things to deal with.

I think that could be put in a less patronising way…

Er… what about the Intel Xeon assembler ? THIS would be really adult ! :slight_smile:

Anyway, I’m maybe not a good example for ASOC programming, because I’m coding a stand-alone application, which pilots no other app – the Finder was the last one, and it’s gone – and has some very specific features which were originally developed in the native MacOS language (pascal).

But the aficionados at MacScripters (including you, Stefan) have always solved my problems so far, with 98% ASOC solutions. I have to admit that ASOC is a main entrance to Cocoa, not just a peephole. And for the coercion problem, well, you learn you live with it, the compiler gives us no “wrong type” warnings so far, but the debug panel helps.

I know there is nothing that the “real thing” but if I try ObjC it won’t be for this app, because I’m too far with it.

Thanks to everybody!