Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa stuff

Cocoa stuff
Thread Tools
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 22, 2001, 04:00 PM
 
Few questions:

If I find documentation on GNUstep, can this serve as documentation for Cocoa? They seem to have the same classes, methods, &c.

Where can I find a tutorial on building an application in Cocoa that's not the Vermont Recipes? Do you recommend I learn it any other way?

How can I convert a "char buf[1000]" to an NSString?

Thanks.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 22, 2001, 05:32 PM
 
Read Apple's documentation. In NSString you can use

+ (id)stringWithCString const char *)cString length unsigned)length

to convert a character array to an NSString Object. I don't think that you can just give it an array I think that you must give it a pointer to the array so instead of statically creating the character array do something like:

char *buf;
buf = (char*)malloc(sizeof(char)*1000);

I'd reccommend against using character arrays at all. You should use unichar instead of char. Char is usually only 1 byte unichar is two or more. Without unichar your program can't support languages like Japanese. To convert a unichar array to an NSString object you'll want to use the method:

+ (id)stringWithCharacters const unichar *)chars length unsigned)length

But... the moral of this little exercise is that all of this is in Apple's documentation and you could have looked it up yourself.

[This message has been edited by Dalgo (edited 01-22-2001).]
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jan 23, 2001, 10:58 AM
 
Terribly sorry :-)

The problem is, I wrote some UNIX programs, and I want to give them a Cocoa front-end just so they're easier to use, but it would be mighty cumbersome to convert all of the character arrays to NSStrings within the code.

Now what about the other stuff? Is GNUstep the same (pretty much?)
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Dedicated MacNNer
Join Date: Oct 2000
Location: Pasadena, CA, USA
Status: Offline
Reply With Quote
Jan 23, 2001, 11:25 AM
 
From the GNUStep FAQ:

> Is GNUstep following Apple's Changes to OpenStep?
>
> Yes - gstep-base already contains the documented changes
> in the Foundation library. GNUstep aims to be compatible with
> both the OpenStep specification and with MacOS-X It should be
> easy to write an application that compiles cleanly under both
> GNUstep and Yellow Box.

Based on that question and others, I would say that yes, you could use the GNUStep documentation. However, it will likely lag behind Apple's documentation.

There are tutorials included with the developer tools that include samples of developing Cocoa applications both in Obj C and Java. The Java examples are a little simplistic; I haven't looked at the Obj C examples in detail.

Others have pointed out the stringWithCString method.

     
Mac Enthusiast
Join Date: Feb 2000
Location: Storrs,Connecticut, USA
Status: Offline
Reply With Quote
Jan 23, 2001, 04:51 PM
 
If all you want to to is slap a front end onto some sort of a console based app then don't worry about converting all of your car arrays to NSString objects. Simply, when you take input, convert it from an NSString object to a character array, and then when you want to do output convert it back again. There's no problem there.

As for internationalization, you could probably do a replace all in Project Builder to convert all occurrences char to unichar. They basically behave the same way. With unichar you can still say stuff like:

if (unicharCharacter == 'a')
doSomething();

Unless you did something special that requires that your characters are explicitly char and nothing else, then I see no reason in switching to unichar. This is why if you use malloc it's good to use something like sizeof(char) in it when dynamically allocating memory, instead of assuming that char is 1 byte. If you allocated stuff with malloc and assumed that a character was one byte then you'd have to go through your code and fix it on your own.

So: Don't worry about changing lost of occurrences of char to NSString objects. Just do it on input and output.

[This message has been edited by Dalgo (edited 01-23-2001).]
     
Fresh-Faced Recruit
Join Date: Jan 2001
Location: San Jose, CA USA
Status: Offline
Reply With Quote
Jan 23, 2001, 11:14 PM
 
The Cocoa API documentation is pretty good; it's my major reference. Look online at http://developer.apple.com/techpubs/...coaTopics.html and follow the "framework reference" links. The same stuff's also available on disk down in /Developer/Documentation/Cocoa.
I would definitely trust this over GNUstep.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2