开发者

Best way to share a resource inside an iPhone Application

开发者 https://www.devze.com 2023-02-07 01:42 出处:网络
I am kinda new to Objective-C and iPhone development and I have a question. I\'m creating an app that retrieved data from the internet using JSON-RPC. I\'ve created a JSON-RPC client that performs the

I am kinda new to Objective-C and iPhone development and I have a question. I'm creating an app that retrieved data from the internet using JSON-RPC. I've created a JSON-RPC client that performs the requests and passes down the results using a delegate.

However I need to use the client quite a few times in my application, so I have been thinking. What is the best way to share the Client resource? From my understanding (from what I've read so far at 开发者_如何学Cleast) I have the following options:

  1. Instantiate a seperate client on each of my controllers that need access to remote data
  2. Pass the already instantiated client down on each new controller instance
  3. Add the client to the AppDelegate
  4. Create a singleton of Client and use that
  5. Use global variable

1,2 options seem to be a waste of resources. I've been reading that 3,5 is not the best way to go. That leaves us with 4. However I don't think you can use a singleton with delegates. I should switch to NSNotification?

Is there any other way to go about?


From what i understand, are you trying to say you want to connect to the server on the internet multiple times to download data? If that is so you should use NSURLConnection class and create a NSURLConnection object each time you request for the JSON data and implement the delegate methods. You could look up NSURLConnection class in the Apple Documentations for further information.

Cheers.

0

精彩评论

暂无评论...
验证码 换一张
取 消