简体   繁体   中英

Why the different NSFileHandle flavors and how are they implemented?

Relatively new to Cocoa here. This question is about NSFileHandle, but I got a feeling the answer may be relevant in a broader Cocoa programming context.

I'm just wondering:

  • why there are different NSFileHandle constructor flavors (ie: one each for reading, writing and both).
  • how the control of access to these file manipulation functions is implemented, especially given that all of these constructors return generic (id) that don't give away at all whether they are of R/W/RW type.

Thanks!

1) Because on most operating systems (Mac OS X/iOS included), reading and writing are two separate operations, and a file handle that can do one is generally not able to do the other (unless explicitly opened with both access types.)

2) We don't know how NSFileHandle is implemented. :) Or maybe we do know, but it's an implementation detail , so even if we know we should pretend we don't.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM