Some general Cocoa questions about files

Discussion in 'Mac Programming' started by subsonix, Jan 26, 2009.

  1. macrumors 68040

    Joined:
    Feb 2, 2008
    #1
    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?
     
  2. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    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.
     
  3. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    There's also NSFileHandle which might be of interest to you.
     
  4. thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #4
    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.
     
  5. thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #5
    kainjow, I´ll look into NSFileHandle. Thanks
     
  6. macrumors G5

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    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.
     
  7. thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #7
    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.
     
  8. macrumors 68030

    Catfish_Man

    Joined:
    Sep 13, 2001
    Location:
    Portland, OR
    #8
    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.
     
  9. thread starter macrumors 68040

    Joined:
    Feb 2, 2008
    #9
    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
     

Share This Page