Search code examples
iosobjective-c.netobjective-c++io-completion-ports

iOS / objective-c(++) equivalent to Windows I/O Completion Ports?


Suppose I want to implement a method that loads a file asynchronously and returns some task with the file's content as its result. In .NET, I could say:

public async Task<byte[]> GetFileContentsAsync(string path)
{
  using (var fs = File.OpenRead(path))
  using (var ms = new MemoryStream())
  { 
      await fs.CopyToAsync(ms);
      return ms.ToArray();
  }
}

Under the covers, CopyToAsync will utilize IO completion ports to ensure that a thread won't be wasted idling, waiting for IO.

Is there an equivalent in Objective-C(++)? Can I implement the following contract efficiently?

ppl::task<StorageBufferPtr> GetFileContentsAsync(const shared_ptr<string> path) 
{    
    ??? 
}

Solution

  • The documentation you are looking for is here:

    https://developer.apple.com/library/ios/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/TechniquesforReadingandWritingCustomFiles/TechniquesforReadingandWritingCustomFiles.html