Best way to write a CalDAV client library in Objective-C?
-
22-10-2019 - |
Question
I am needing to write a CalDAV client library for the Mac, and I just wanted to make sure on what would be the best way to write it.
I am wondering if I should just use NSURLRequest or should I go to the socket level, or something in between?
My concern about using just NSURLRequest is that a new connection would be made for each call, instead of having 1 open connection that all "requests" go through.
Am I missing something?
Thoughts? Suggestions?
Solution
NSURLRequest
doesn't actually create any connections. It just encapsulates the parameters of the request. NSURLConnection
actually creates the connection to the server and sends the request. Under the covers, NSURLConnection
instances share and reuse TCP connections, according to this answer:
NSURLConnection is run many times
So you should just use NSURLRequest
and NSURLConnection
if their APIs suit you.
OTHER TIPS
Use NSURLRequest
. Despite the naming, an NSURLConnection
object does not have a one-to-one correspondence with a TCP connection. In fact, NSURLConnection
might be more appropriately named NSURLRequestLoadingManager
or something—it's just an object that tracks the progress of that particular request.
The underlying TCP connections are managed by Cocoa, and you don't need to worry about their lifecycle.