26. Sep 2023
iOSExploring our iOS toolbox: sharing our codebase with the world
As iOS app development becomes more prevalent around the world, developers are increasingly relying on libraries and packages to improve their productivity and add functionality to their apps. That is why we in GoodRequest decided to share our codebase with the world with these four libraries that make our life easier.
GRProvider
Use GRTableViewProvider
and GRCollectionViewProvider
to simplify working with UITableView
and UICollectionView
These classes provide a set of methods and bindings that make it easy to implement multiple sections and items in a structured and reactive way.
Simply create a struct that conforms to the Sectionable
protocol in a factory class, declare the table/collection view, and use the provided methods to configure and populate it with data.
Read more here
Good Networking
Swift's built-in networking capabilities can have disadvantages, such as lack of standardisation and flexibility.
But using the GoodNetworking Swift package can make handling network requests more efficient. First, define the base URL and endpoint for your network request. Then, specify the expected response with a struct. Next, create a GRSession
instance to manage network requests, taking two generic parameters: the endpoint and the API server. Finally, make a network request with the session.request
method, and use Combine's sink
or assign
methods to show the fetched data.
Read more here
Exploring our iOS toolbox - Handling network requests in Swift
Good Reactor
To use reactive programming in Swift, the GoodReactor package can be used for managing complex, reactive code. GoodReactor uses a protocol-based architecture and integration with Combine to create a reactive component that can be easily reused throughout an application.
To create a reactive view, define a BaseViewController
class that takes a generic type T, which is expected to be a viewModel
that provides the data and business logic for the view. The viewModel
class should implement the GoodReactor protocol and define a State struct representing the current state of the view, an Action enum representing user actions, and a Mutation enum representing state changes in response to user actions.
The viewModel
class should also define methods such as navigate, mutate, and reduce to handle navigation, state mutations, and state reduction.
Finally, create a ViewController
class that uses the viewModel
class to display and interact with the data provided.
Read more here
Exploring our iOS toolbox - How we make reactive applications in Swift?
Good Persistence
Use Swift's UserDefaults
to store small amounts of data, such as user preferences, settings, and application state. The GoodPersistence
package simplifies working with UserDefaults
and Keychain
in Swift. Use the UserDefaultValue
property wrapper to store any Codable
value in UserDefaults
To observe changes using Combine, declare a publisher for the variable. Use the KeychainValue
wrapper to store sensitive data securely in Keychain
Specify the accessibility parameter to determine when the stored data is accessible. The UserDefaultValue
and KeychainValue
wrappers also offer a convenient feature for observing value changes using Combine. Use the sample provided in the package to explore its functionality.