Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
For a new app I am designing I want to implement a Request Manager Class (swift) that will handle all the calls to the backend.
Which is the right way to do it? Class Methods or a Singleton and can you please provide me with a pattern or some sample code for me to get started?
Thank you in advance
First of all use Alamofire instead of AFNetworking. Alamofire was made by the same team as AFNetworking, but it's written in pure Swift.
Singleton pattern is a good choice for APIClient. My approach is to make generic wrapper on Alamofire which handles requests with unified error handling and completions, takes care of authentication headers and stuff.
Next step is to extend generic wrapper (i.e by subclassing) to handle application's domain-specific behavior -> all calls that connects to API goes here.
Big plus of this approach is fact that you can reuse this generic wrapper in another app.
Try Alamofire (AFNetworking for swift)
Alamofire.request(.POST, "http:/www.abc.com" , parameters: ["consumer_key": "Og5pRGI2V"]).responseJSON { response in
print(response)
}
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm interested in how to properly abstract Firebase in order to decouple it with my app in case I want to switch back ends in the future.
Right now I have a single class with static methods that access the Realtime Database and Storage. I call these static methods throughout the app.
Is this the best way to use Firebase in a production environment? My app is written in Swift.
You can create a Wrapper class
class YourWrapperClass: NSObject {
}
Import the frameworks like Firebase that you want to use with this wrapper.
import Firebase
Create the methods with the use of Completion Handler/Closures/Blocks
That’s It. By this way you can use the code reusability.
Whenever you want to stop using Firebase, you will have to just stop calling methods from this wrapper class & implement alternative methods you want to call/use instead. Hope this will help.
I think the best way here is to have struct with static members for each main node in your Firebase database and also separate models for each main folder of Firebase storage. It should look like API's. You can change it in the future without any problems.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I want to make rest api call. I m confused to use Afnetworking or NSurlsession or alamofire with SWIFT 3.0. Can anyone suggest me to use which one.
NSURLSession is newer than NSURLConnection, if you are using swift language then you can use your own custom methods by using NSURLSession or you can use Alamofire.
The NSURLConnection used in AFNetworking frameworks, If you are using objective - c then you can use it, that means not that you cannot use NSURLSession.
NSURLSession launch after iOS 7.0 or 8.0. It is more efficient that NSURLConnection.
At last,
If you want to make your own custom API framework then you can use NSURLSession(for swift)(I also used this).
If you don't required the custom framework then use Alamofire Framework.
For more details you can refer this link:
What are the difference among NSURLConnection, NSURLSession and AFNetworking?
For Swift 3.0 Alamofire is best because it is well Optimized and also reusable and it has also many Build in features.
If You are using Objective- C then you can use AFNetworking.
AFNetworking and Alamofire are from same Developers but in Different Languages.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
So, i just want to know what the best way to display image from URL.
I have to display few post from the server into my iOS app using UITableView with title and image in it.
I had already created the WebServer for my app and fetching is done through TBXML and using Core Data to store the title and description from the server.
and i saw some library available to cache the image like https://github.com/path/FastImageCache
Now my question is that how can i display image from the URL ?
And what is the best method to do it.
Thanks
The best way is to write your own code. Using a library will work but it will be generic and by definition slower than what you can write for your specific use case.
You are far, far better off learning the few lines of code it takes to download an image and display it. Learn how to use a NSURLSession. Learn how to consume NSData and turn it into a UIImage. Learn how to use a NSNotification or a block to propagate the loaded image to your user interface.
Your code will be stronger and you will become a better developer.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
new to iOS
My app has to communicate with a backend java server to handle login , download image data etc. I'm confused on how to implement the network module. Should there be a separate network module for each view controller ? Or should there be a central network module to handle all the calls ? I know its a vague question but I don't know where else to ask.
You can check below mentioned link,
AFNetworking Crash Course
AFNetworking Document/Source
Hi you can try with this
https://github.com/tonymillion/Reachability
thanks
Use ASIHTTPRequest can easily to implement network action (like GET, POST, download, upload, etc...)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Since most mobile apps need to communicate with server, thus they need handle http request in the app. My question is that, is it better to put all requests in one controller or separate to different controller?
For example, I have a SignInViewController and ContactsViewController. Both of them need to get some data or post some data to server. I can either handle requests in each ViewControllers, or put them in one ServerController. Which is better or standard way?
Thanks
I would and have used a separate object similar to what you describe as the ServerController. It depends on the situation but I have found these are easier to work with if they are not singletons so that you can manage state, progress, etc. of each of your HTTP requests independently.