Fetching and Displaying Countries in a UITableView
This section describes how to fetch a list of countries from a JSON API and display them in a UITableView. The table displays each country's name, region, code, and capital, and allows users to scroll through the entire list. Additionally, a UISearchController enables filtering by name or capital as the user types.
- Fetching Countries:
The code fetches a list of countries in JSON format from the following URL:
- Displaying Countries in a UITableView:
The countries are displayed in a UITableView, ordered by their position in the JSON data. Each table cell shows the following information using the provided format:
| "name", "region" "code" |
|---|
| "capital" |
Example:
| United States of America, NA US |
|---|
| Washington, D.C. |
| Uruguay, SA UY |
|---|
| Montevideo |
Users can scroll through the entire list to view all countries.
- Search Functionality:
A UISearchController is implemented to allow users to filter the list of countries by name or capital as they type each character.
- Implementation Details:
The implementation is robust, handling errors and edge cases. It supports Dynamic Type for accessibility. It functions correctly on both iPhone and iPad devices. It adapts to device rotation. UIKit is used for this exercise, not SwiftUI.