Re: Low-level File Access
Re: Low-level File Access
- Subject: Re: Low-level File Access
- From: David Remahl <email@hidden>
- Date: Sun, 17 Mar 2002 09:54:57 +0100
This has been said a few times over the years...
Objective-C is a superset of C. Anything that is in C is also in
Objective-C.
All you need to do is to #include or #import the header. Documentation for
stdio.h you should be able to find in just about any book teaching C.
If the rest of your class-mates are doing this in C++, then you may want to
do the same thing and utilize Objective-C++. Just name your source file *.mm
and use whatever C++ you want (within some limits - study the release
notes).
That said, how do you suppose we should know how your binary tree is
serialized? I would guess that as long the number of nodes remain the same
the tree won't grow, but I could never know. But if it does work this way in
C++ then it works the same way here. They're both dealing with bytes, you
know :).
However, you should not use NSArchiver for this. If not for another reason
then because I don't thing your CS teacher would like it very much.
The documentation for NSFileHandle will serve you well. For example, it
states that +fileHandleForReadingAtPath:... will "If no file exists at path
the method returns nil", and the same is true for
+fileHandleForWritingAtPath:.... You will therefore need to explicitly
create the file using NSFileManager if you choose the cocoa approach. Then
it will work just fine for random access, although depending on the size you
may want to load it all into an NSData.
Finally, it is *not* a good idea to create a file inside of your app bundle.
If you were to do such a thing, you would get the path to your app bundle
using [NSBundle mainBundle]. The reason why you shouldn't is, that it is
very possible that the user running the application does not have write
access to the bundle.
/ Sincerely, David Remahl
>
That sounds like a simple enough solution. Where can I get
>
documentation for stdio.h? Is this built into Cocoa natively or are
>
there special steps that need to be taken to include C functions?
>
>
Does anyone know of any examples (or have any to share) that show direct
>
file access in a Cocoa application?
>
>
Thanks,
>
Nick
>
email@hidden
>
>
>
On Sunday, March 17, 2002, at 10:49 AM, Andrew Pinski wrote:
>
>
> I would just use the ANSI (ISO) C functions (from stdio.h) for random
>
> access on a file.
>
>
>
> Thanks,
>
> Andrew Pinski
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.