CptS 479 Homework 10 “Health News” App…

$30.00

Category: Tags: , , , , You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

This homework will be a standalone version of HealthApp that allows us to download the latest
headline health news from newsapi.org and view the articles in Safari. See screenshots below.
Specifically,
1. Create a new Xcode project called HealthApp that has a table view controller embedded in
a navigation controller with title “Health News” and prompt “Health App”. Add a bar
button called “Update” in the upper right.
2. Create a NewsItem class with string properties for the news story’s source, title and URL,
and an image property to hold an image pertaining to the story. All four properties should
be optionals and the table should display a default string or image if the story does not
provide this information. For example, the last row in the screenshots below is a news story
that provided no URL to an image, so that row shows a default image.
3. When the app starts, and whenever the Update button is tapped, the app should make a
URLSession datatask request to the following newsapi URL (where the ??? should be
replaced by your personal API key from https://newsapi.org). You can use a different
“country” parameter, or omit it altogether, if you want.
https://newsapi.org/v2/top-headlines?country=us&category=health&apiKey=???
4. The response from the request will be a JSON object from which the app will need to
extract each story’s title, source, image URL, and main URL. You can see an example of
this JSON object at https://newsapi.org/s/us-health-news-api. If a story’s main URL is not
available, then that story should be discarded and not appear in the table.
5. The general approach to updating the table is to create new NewsItem class instances for
each story based on the initial response, but with the image property set to the default
image, and then reload the table data source. Next, the app should attempt to load the
images by following the urlToImage URLs. As each one returns, the app should create an
image from it, load it into the corresponding NewsItem instance, and then reload the table
data source. This way, the news story titles and sources will refresh quickly, and the images
will refresh as they become available.
2
6. The table view cells should use the “Subtitle” style. The cell should set the imageView to
the image from the story’s urlToImage (or default image, if not available), the textLabel to
the story’s title, and the detailTextLabel to the story’s source name. Again, each of these
should have some default value if the information is not provided in the response.
7. If the user selects a row in the table, then the app should present a SFSafariViewController
to display the main URL for the story.
8. Test your app using the iPhone 11 simulator, which is the same simulator we will use to
grade your app.
9. Be sure that auto layout constraints are set so that all view elements are appropriately
displayed with no overlap or trimming regardless of device orientation. Long titles or
sources can be abbreviated with an ellipsis, and images may vary in their width (as seen in
the screenshots below). You are welcome to use a custom table view cell that better controls
the size and margins of images, but this is optional.
Simulator: