Welcome to the documentation for EmptyKit, a powerful framework for building amazing apps.
Getting Started
Before starting with EmptyKit, make sure you have the following prerequisites:
- Xcode 12.0 or later
- iOS 13.0 or later
- Swift 5.3 or later
Installation
To install EmptyKit, you have a few options:
CocoaPods
To install via CocoaPods, add the following line to your Podfile:
pod 'EmptyKit'
Swift Package Manager
To install via Swift Package Manager:
.package(url: "https://github.com/your/repo", from: "1.0.0")
Manual Installation
If you prefer to install EmptyKit manually, follow these steps:
- Download the latest version from the GitHub releases page.
- Drag and drop the EmptyKit framework into your Xcode project.
- Make sure to add EmptyKit to the framework dependencies of your target.
Usage
To begin using EmptyKit, follow these steps:
Initialize
Initialize EmptyKit in your AppDelegate.swift file:
import EmptyKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
EmptyKit.initialize()
return true
}
Configure
Configure EmptyKit by defining empty views for various states:
import EmptyKit
extension EmptyConfiguration {
static func configureForEmptyState() {
EmptyKit.configure {
emptyView(for: .noData) {
let emptyView = EmptyView()
emptyView.title = "No Data"
emptyView.description = "There is no data available."
emptyView.image = UIImage(named: "no-data")
return emptyView
}
emptyView(for: .error) {
let emptyView = EmptyView()
emptyView.title = "Error"
emptyView.description = "An error has occurred."
emptyView.image = UIImage(named: "error")
return emptyView
}
}
}
}
Call the configureForEmptyState()
function in your application setup:
import EmptyKit
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
EmptyKit.initialize()
EmptyConfiguration.configureForEmptyState()
return true
}
Show Empty State
Show the empty state when needed:
import EmptyKit
class MyViewController: UIViewController {
private var data: [String] = []
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if data.isEmpty {
emptyStateDelegate?.showEmptyState(.noData)
}
}
}
Features
EmptyKit offers the following features:
- Create customized empty views for different states like no data, error, loading, etc.
- Easily show and hide the empty state view.
- Highly customizable with various configuration options.
Examples
Here are some examples of how EmptyKit can be used:
No Data State
Display a custom empty view when there is no data available:
import EmptyKit
extension EmptyConfiguration {
static func configureForNoDataState() {
EmptyKit.configure {
emptyView(for: .noData) {
let emptyView = EmptyView()
emptyView.title = "No Data"
emptyView.description = "There is no data available."
emptyView.image = UIImage(named: "no-data")
return emptyView
}
}
}
}
Show the no data empty state view:
import EmptyKit
class MyViewController: UIViewController {
private var data: [String] = []
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if data.isEmpty {
emptyStateDelegate?.showEmptyState(.noData)
}
}
}
Error State
Display a custom empty view when an error occurs:
import EmptyKit
extension EmptyConfiguration {
static func configureForErrorState() {
EmptyKit.configure {
emptyView(for: .error) {
let emptyView = EmptyView()
emptyView.title = "Error"
emptyView.description = "An error has occurred."
emptyView.image = UIImage(named: "error")
return emptyView
}
}
}
}
Show the error empty state view:
import EmptyKit
class MyViewController: UIViewController {
private var errorOccurred: Bool = true
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if errorOccurred {
emptyStateDelegate?.showEmptyState(.error)
}
}
}
Additional Resources
For more information, check out the following resources: