This post is originally published in Japanese a half years ago. I want someone to know how create an iOS app with modern technology and how I struggled with that. Please enjoy!!
I built an OSS news app for iOS with SwiftUI.
Please give me stars on GitHub!
Apple had released a lot of new API in WWDC 2021. Everything is very exciting and motivated me to create a new app though, I just wanted to experiment the new feature like Searchable and Refreshable or new feature of Swift language like Concurrency.
Therefore, the app itself requires Xcode 13 or higher and iOS 15 or higher.
About App
This app uses the newsapi.org API to search for the world's top news and specific words.
It consists of three tabs and implements only the minimum necessary functions.
I'm personally satisfied with it because it accomplished the purpose of trying out the new features I mentioned above.
Headline
Search
Publishers
NewsAPI: Concurrency
With the creation of the app, I wrapped the API of newsapi.org and released it as an iOS library.
I could have left it as an internal implementation, but I cut it out as a library for the following reasons.
There was no Swift library for newsapi that supported asynchronous processing.
I want people who want to make iOS apps to use it.
I wanted to do it as a part of OSS activity.
From here, I will lightly introduce the API that uses async/await syntax, the most significant language feature added in Swift 5.5.
The following is a sample code that uses the NewsAPI to get the headline news.
funcgetHeadlines()async->[NewsArticle]{do{letarticles=tryawaitNewsAPI(apiKey:"YOUR_API_KEY").getTopHeadlines()returnarticles}catch{// do something}}
If you read the above code, you will see that instead of using traditional closures, the keyword async is added to the method and the keyword await is used inside.
This method, getHeadlines, is defined as an asynchronous function, so it needs the await keyword right before it.
Since await suspends the process immediately after it is written, it is more intuitive to write.
Not only does it improve readability by reducing the number of lines of code and the depth of nesting, but it also expands the scope of expression by allowing multiple asynchronous processes to be handled simultaneously.
NewsUI: App Architecture
Here is an explanation of the application itself.
The following image shows an easy-to-understand diagram of the app structure.
As mentioned in the above section, NewsAPI (red part) has been cut out as an external library.
Only the internal NewsClient depends on the NewsAPI, and each feature depends on it.
All the features in the yellow part of the image are managed as Packages, and the Package.json file is structured as follows.
The app is divided into multiple modules, and each module is divided into different functions (in this case, tabs) so that they cannot be cross-referenced.
Multi-module system has some merits such as clear dependencies and optimized compilation, but for a small app like this one, you won't get much benefit from it.
Though it is an unnecessary addition, we call it Hyper-modularization, and isowords is being developed with 86 modules.
Open source game built in SwiftUI and the Composable Architecture.
isowords
This repo contains the full source code for isowords, an iOS word search game played on a vanishing cube. Connect touching letters to form words, the longer the better, and the third time a letter is used its cube is removed, revealing more letters inside!
isowords is a large, complex application built entirely in Swift. The iOS client's logic is built in the Composable Architecture and the UI is built mostly in SwiftUI with a little bit in SceneKit. The server is also built in Swift using our experimental web server libraries.
This is a brief introduction to NewsUI and NewsAPI, which I have been working on.
I'm happy to publish it now that I have a breakthrough for now.
Please star if you find it helpful!
Thank you for reading.