ios swift - load multiple data source in one tableview synchronously - swift

i want a make a feed reader...i want load politics news from multiple data dource in one tableview synchronously.
what do i do?
i went to this link: table view with multiple data sources/nibs
but this solution is not synchronously
So basically what should be the approach when we have multiple data source but single instance of table view to show the data?

What I would do is to create a backend service where the news are merged into one list. This allows you to easily edit the algorithm without the user having to update the app. And your backend also only have to crawl the websites once instead of every client having to do it every time a user wants to see the news.
When you fetch data from that service it will come in one list, and you already know how to do that :)

It shouldn't be synchronously, because you wait for the rss response.
You better show a spinner and reload the tableview data once you collect all the responses.

Related

Flutter achieving ui/data synchrony

I have two screens:
Homefeed.dart
Profile.dart
On Homefeed screen all the data from various users is fetched from a server and is shown in a list of cards form.
On the Profile screen, only data that belongs to the logged in user is fetched.
The problem is that, there will be an overlap in the data that is fetched on the both the screens. For example if a user writes a post, it can show up on the Homefeed. Now if the user decides to perform any action such as like, delete, edit etc on thir post from the profile screen, then it should also update the same post that was fetched on the Homefeed screen.
Now unless user explictly refreshes the data, and send a request to server to fetch the updated data, what would be an ideal way to achieve this synchrony.
I did consider using a realtime database, but this will mean migrating current project and it might get expensive and might have problem of it own.
The other "hacky" way would be to maniuplate data somehow (I still havent figured it out) on the client side and show the update instead of fething new data from the server.
Or some other, more ideal way of achiving this, that I don't know of.
The best way is to reflect any changes of the user post i.e edit, delete in Profile.dart is by updating the database without tricking the just in the client side. Because you may reduce the database calls by tricking, but you are giving high chances of inconsistent data in database. Your database wouldn't be reliable.
Database should be the single source of truth
I would suggest, Every time HomeFeed.dart page is loaded , try loading the latest data from the database. If you are using real-time database, you dont have to check on every page load.

What is better: one large REST API call or many small for a Cordova/Backbone app?

This is my first Cordova/Backbone application.
I have grasped the whole deal with Models, Views, etc. somewhat, and now I have gotten to actually making proper view structure for my app.
It is a user centered app, which means that views are dynamic depending on who the user is and their status in the app.
Could you please help me to understand what is a better choice: making one (large-ish) api call to the server to get the data for all user-related app views (that would get all user info, various menus for the current user etc) and put them in one User model or make several smaller api calls that each get a fragment of the information (let's say, profile information, newsfeed information and options for two menus, so 4 ajax calls total) and keep the models separate? All the relevant views (UserProfile, SideMenu, UserProfileMenu and ActivityFeed) are rendered on user login. Some of them are available for user at all times (SideBar menu for example), some get switched out as user navigates elsewhere.
I design the server-side API myself, so I can freely choose what data is returned and when.
"it depends". If you need all the info (from 4 ajax calls) from start, it would be better to create one big api call, because callig server 4 times will last longer than one big call - 4x server ping time. you could use the big call on app start and still create the 4smaller ones to refresh data when needed.

Approach regarding web service call restricted to the visible cell only

creating a listing component(a tabl view) for iPhone app, the list content must be dynamic (can be read from a web service or local file system) and the app should only fetch the content that is viewable in the list(table) view and each scroll will request for more data from the server(file system or web service). The viewable content should auto-refreshed every 30 seconds.
till now i am successfull in creatin table view with dumy data(from an array).
But what approach should i take foe requesting web service only viewable to the current cell ,
any guidence here will be very appreciated.
To solve your problem I will suggest following steps.
1. Keep one data array and keep refreshing you table sing that every 30 sec, as you have already done.
2. Make a separate thread for calling web service and update you array when response comes available.
Thus, even if internet is down some time or slow, your GUI will not be affected with that.
3. Make sure your array is being accessed synchronously between threads.
4. if web service content is too big, then keep version number for data and send request with current version no. so if web service has updated version of data it will send you only updates or difference. OR it will send you all the data on condition that your current version is older.
If answer is not relevant than please post further details so that I can have better understanding of problem.

Should loaded images and text be stored in memory or retrieved each time

My app has various pins that drop onto a map and when you click on the pins you get more information about this entity.
Each time you click on the entity it retrieves the information from a web service. Should I only retrieve this information once and store it in memory or should I retrieve it each time that page loads?
It's a small about of text and 3 small images?
If its just 3 small images and some text that will not change i would probably cache them in the application instead of retriving them over and over, it will provide a better user expirience in my opinion...
Also I have a Core Data application that uses images...
I tried both methods but I chose to retrieve it every time because for my goal is the best practice. However this method causes me to write some code and a lot of if and else!
How Daniel said, cache each image can be a better solution for your problem because if an user would like to retrieve these images from internet but the connections isn't fast, he'll wait a lot of time...

Caching results from a PHP webservice for iPhone

I'm building an app that retrieves a JSON dataset from a PHP server. The app has a view that displays a "feed" of several different newly added or updated items from the web server.
The app loads 20 of the newest items to start with, and the user can subsequently load 20 more older items, and 20 more, and so on. I want this data to persist between subsequent view changes, and quitting/launching the app.
So far I have a PHP webservice handling the JSON response by accepting a last_updated timestamp, which is sent by the iphone client with the webservice query. The server then returns any items it finds that are newer than the last_updated time.
On the iPhone side I have the connection to the webservice returning results to the iphone and displaying them in custom UITableViewCell cells. However as of right now the app will request the data from the webservice every single time.
I'm a little confused as to what's a good way to cache this data. Do I store the actual cells themselves, or create an object for each feed item type and store that? Or something else? Do I use core storage, sqlite, or some other custom method?
Thanks for any insight.
You never store data of any kind in a table view cell. Cells are intended to be reused to create the illusion of an arbitrarily long table. If you keep creating and retaining the cells as a data store you will eat all your memory very quickly.
It sounds like you do want to create a Core Data store although a plist and SQL are inferior options. The learning curve for Core Data is relatively steep but once you learn it it makes everything easier.