Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 26, 2009, 11:13 AM   #1
subsonix
macrumors 68040
 
Join Date: Feb 2008
Some general Cocoa questions about files

So I have started to look into objc and Cocoa and have come accross NSFileManager and NSData. Are there any methods to read in just the data part of a file into an NSData object, what I mean is to strip of the header?

And are there any templates for common file formats, so that raw data can be packed and written corectly to these formats?

Also are there a similar level of control over the content of an NSData object as with NSArray?
subsonix is offline   0 Reply With Quote
Old Jan 26, 2009, 11:31 AM   #2
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by subsonix View Post
So I have started to look into objc and Cocoa and have come accross NSFileManager and NSData. Are there any methods to read in just the data part of a file into an NSData object, what I mean is to strip of the header?

And are there any templates for common file formats, so that raw data can be packed and written corectly to these formats?

Also are there a similar level of control over the content of an NSData object as with NSArray?
You use NSFileManager when _you_ determine the exact file format and nobody else. With NSFileManager you just get the raw data (or you could use Posix calls instead, if you want code that runs on other OSes as well).

There are special classes for XML files, classes for Preference files, classes for RTF and HTML, classes for image data and so on.
gnasher729 is offline   0 Reply With Quote
Old Jan 26, 2009, 12:14 PM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
There's also NSFileHandle which might be of interest to you.
kainjow is offline   0 Reply With Quote
Old Jan 26, 2009, 12:26 PM   #4
subsonix
Thread Starter
macrumors 68040
 
Join Date: Feb 2008
Quote:
Originally Posted by gnasher729 View Post
You use NSFileManager when _you_ determine the exact file format and nobody else. With NSFileManager you just get the raw data (or you could use Posix calls instead, if you want code that runs on other OSes as well).

There are special classes for XML files, classes for Preference files, classes for RTF and HTML, classes for image data and so on.
Hmm, ok so say that I have an application that perform some manipulation on audio file data. Does this mean that I manually will have to check for all possible fileformats that could be used with the program, and set different offsets accordingly? I was hoping that there was a way for this to be handled in the background, since the os allready know this stuff.
subsonix is offline   0 Reply With Quote
Old Jan 26, 2009, 12:29 PM   #5
subsonix
Thread Starter
macrumors 68040
 
Join Date: Feb 2008
kainjow, IŽll look into NSFileHandle. Thanks
subsonix is offline   0 Reply With Quote
Old Jan 26, 2009, 12:44 PM   #6
gnasher729
macrumors G5
 
gnasher729's Avatar
 
Join Date: Nov 2005
Quote:
Originally Posted by subsonix View Post
Hmm, ok so say that I have an application that perform some manipulation on audio file data. Does this mean that I manually will have to check for all possible fileformats that could be used with the program, and set different offsets accordingly? I was hoping that there was a way for this to be handled in the background, since the os allready know this stuff.
No, it doesn't mean that, and that is not what I wrote. If you use NSFileManager, then you have to understand all possible file formats. That's why you wouldn't use NSFileManager, but something more appropriate. For audio files, I would have a good look at the Quicktime or CoreAudio documentation.

It also shows that when you ask questions, you should ask about what you actually want to know, and not about the things that you think you want to know. You wanted to know about handling audio files, but you asked about NSFileManager. Obviously you get answers about NSFileManager, because we are all not very good at distance mind reading.
gnasher729 is offline   0 Reply With Quote
Old Jan 26, 2009, 01:03 PM   #7
subsonix
Thread Starter
macrumors 68040
 
Join Date: Feb 2008
Quote:
Originally Posted by gnasher729 View Post
No, it doesn't mean that, and that is not what I wrote. If you use NSFileManager, then you have to understand all possible file formats. That's why you wouldn't use NSFileManager, but something more appropriate. For audio files, I would have a good look at the Quicktime or CoreAudio documentation.

It also shows that when you ask questions, you should ask about what you actually want to know, and not about the things that you think you want to know. You wanted to know about handling audio files, but you asked about NSFileManager. Obviously you get answers about NSFileManager, because we are all not very good at distance mind reading.
To be fair though, the title of the thread is: Some general Cocoa questions about files.

I then continued to say that I have started to look into Cocoa and have come accross NSFileManager and NSData. If there are better methods to achive what I want to know, I want to know, that is the purpose of the thread, a general discussion. So the audio file example served as an example, could have been graphic formats as well.
subsonix is offline   0 Reply With Quote
Old Jan 26, 2009, 01:15 PM   #8
Catfish_Man
macrumors 68030
 
Catfish_Man's Avatar
 
Join Date: Sep 2001
Location: Portland, OR
Send a message via AIM to Catfish_Man
For graphics you'd use NSImage, or CGImage, or ImageIO. The point is that in general you're better off using APIs designed for the type of file you're working with, rather than general file reading APIs.
Catfish_Man is offline   0 Reply With Quote
Old Jan 26, 2009, 01:30 PM   #9
subsonix
Thread Starter
macrumors 68040
 
Join Date: Feb 2008
Quote:
Originally Posted by Catfish_Man View Post
The point is that in general you're better off using APIs designed for the type of file you're working with, rather than general file reading APIs.
Ok, get it. Just starting to look into Cocoa and it helps to get a sense of some of the benefits it presents when dealing with files, as well as how things are organised.

Cheers
subsonix is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Basic Objective-C Cocoa questions? cpuin Mac Programming 8 Jun 3, 2013 07:10 PM
iPhone: General JB Questions xybadog Jailbreaks and iOS Hacks 2 Apr 9, 2013 08:01 PM
General Mac Questions CelticLenny Mac Basics and Help 7 Mar 26, 2013 10:52 AM
A few general questions about Apple TV Italianblend Apple TV and Home Theater 8 Nov 5, 2012 09:44 AM
Cocoa bindings questions jeanlain Mac Programming 3 Oct 6, 2012 03:20 PM

Forum Jump

All times are GMT -5. The time now is 07:23 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC