BFKit-Swift
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.
Top Related Projects
Elegant HTTP Networking in Swift
Network abstraction layer written in Swift.
Reactive Programming in Swift
The better way to deal with JSON data in Swift.
A lightweight zero-config image cache for iOS, in Objective-C.
Quick Overview
BFKit-Swift is a collection of Swift extensions, utilities, and custom UI components that aim to simplify and accelerate iOS/macOS/tvOS/watchOS development. It provides a wide range of functionality, from UI elements to networking and data management tools, all wrapped in a clean and easy-to-use API.
Pros
- Comprehensive Functionality: BFKit-Swift offers a diverse set of features and utilities, covering a wide range of common development tasks.
- Consistent and Intuitive API: The library's API is well-designed, making it easy to discover and use the available functionality.
- Cross-Platform Support: The project supports multiple Apple platforms, including iOS, macOS, tvOS, and watchOS.
- Active Development and Community: The project is actively maintained, with regular updates and a responsive community.
Cons
- Potential Dependency Overhead: Depending on the specific needs of a project, the inclusion of the entire BFKit-Swift library may result in a larger dependency footprint.
- Learning Curve: While the API is generally intuitive, the breadth of functionality may require some initial learning for developers unfamiliar with the library.
- Potential Performance Concerns: Some of the more complex features or UI components may have performance implications, which developers should be aware of.
- Limited Documentation: The project's documentation, while generally helpful, could be more comprehensive in some areas.
Code Examples
Networking
let request = BFNetworkRequest(url: URL(string: "https://api.example.com/data")!)
request.method = .get
request.headers = ["Authorization": "Bearer \(accessToken)"]
BFNetworkManager.shared.send(request) { (response, error) in
if let error = error {
print("Error: \(error)")
} else if let data = response?.data {
let json = try? JSONSerialization.jsonObject(with: data, options: [])
print("Response: \(json ?? "No data")")
}
}
This example demonstrates how to use the BFNetworkRequest
and BFNetworkManager
classes to make a GET request to an API endpoint, with custom headers.
UI Components
let button = BFButton(type: .system)
button.setTitle("Click me", for: .normal)
button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside)
view.addSubview(button)
This code creates a custom BFButton
instance and adds it to the view hierarchy. The button can be configured with a title and a target action.
Data Management
let user = BFUser(name: "John Doe", email: "john.doe@example.com")
BFUserDefaults.set(user, forKey: "currentUser")
if let storedUser = BFUserDefaults.object(forKey: "currentUser") as? BFUser {
print("Stored user: \(storedUser.name) (\(storedUser.email))")
}
This example demonstrates how to use the BFUser
and BFUserDefaults
classes to store and retrieve a user object in the app's user defaults.
Getting Started
To get started with BFKit-Swift, follow these steps:
-
Add the BFKit-Swift library to your project using a dependency manager like CocoaPods or Carthage.
# CocoaPods pod 'BFKit-Swift'
-
Import the BFKit-Swift module in your Swift files.
import BFKit
-
Start using the various components and utilities provided by the library. For example, you can create a custom
BFButton
and add it to your view hierarchy:let button = BFButton(type: .system) button.setTitle("Click me", for: .normal) button.addTarget(self, action: #selector(buttonTapped(_:)), for: .touchUpInside) view.addSubview(button)
-
Explore the library's documentation and sample projects to learn more about the available features and how to use them
Competitor Comparisons
Elegant HTTP Networking in Swift
Pros of Alamofire
- Alamofire is a well-established and widely-used networking library for Swift, with a large and active community.
- It provides a simple and intuitive API for making HTTP requests, handling responses, and managing session tasks.
- Alamofire has excellent documentation and a wealth of online resources, making it easy to get started and troubleshoot issues.
Cons of Alamofire
- Alamofire may be considered overkill for simple networking tasks, as it adds some overhead and complexity compared to using the built-in URLSession API.
- The library is tightly coupled to the Swift ecosystem, which may be a drawback for developers working in a mixed environment.
Code Comparison
Alamofire:
Alamofire.request("https://httpbin.org/get")
.responseJSON { response in
if let value = response.result.value {
print("JSON: \(value)")
}
}
BFKit-Swift:
let url = URL(string: "https://httpbin.org/get")!
URLSession.shared.dataTask(with: url) { (data, response, error) in
if let data = data, let json = try? JSONSerialization.jsonObject(with: data, options: []) {
print("JSON: \(json)")
}
}.resume()
Network abstraction layer written in Swift.
Pros of Moya
- Provides a higher-level abstraction over networking, making it easier to work with APIs.
- Supports a wide range of authentication methods, including OAuth, Basic Auth, and more.
- Includes built-in support for handling response data, including automatic JSON parsing.
Cons of Moya
- Adds an additional layer of complexity compared to using a lower-level networking library.
- May have a steeper learning curve for developers who are new to the library.
- Requires more boilerplate code to set up and configure.
Code Comparison
Moya:
let provider = MoyaProvider<GitHub>()
provider.request(.zen) { result in
switch result {
case let .success(response):
let status = response.statusCode
let data = response.data
// do something with the response data
case let .failure(error):
print("Error: \(error)")
}
}
BFKit-Swift:
let url = URL(string: "https://api.github.com/zen")!
URLSession.shared.dataTask(with: url) { data, response, error in
if let error = error {
print("Error: \(error)")
return
}
if let httpResponse = response as? HTTPURLResponse {
let status = httpResponse.statusCode
// do something with the response data
}
} .resume()
Reactive Programming in Swift
Pros of ReactiveX/RxSwift
- Provides a powerful and flexible reactive programming model for building complex, event-driven applications.
- Extensive ecosystem of operators, schedulers, and other utilities that simplify common programming tasks.
- Strong community support and active development, with a large number of third-party libraries and tools.
Cons of ReactiveX/RxSwift
- Steeper learning curve compared to FabrizioBrancati/BFKit-Swift, especially for developers new to reactive programming.
- Can be overkill for simpler projects that don't require the full power of the reactive paradigm.
- Potential performance overhead for certain use cases, depending on the complexity of the reactive chain.
Code Comparison
FabrizioBrancati/BFKit-Swift:
let label = UILabel()
label.text = "Hello, World!"
label.textColor = .white
label.backgroundColor = .black
ReactiveX/RxSwift:
let disposeBag = DisposeBag()
Observable.just("Hello, World!")
.map { $0.uppercased() }
.subscribe(onNext: { text in
let label = UILabel()
label.textColor = .white
label.backgroundColor = .black
label.text = text
})
.disposed(by: disposeBag)
The better way to deal with JSON data in Swift.
Pros of SwiftyJSON
- SwiftyJSON provides a more concise and readable syntax for working with JSON data in Swift, compared to the more verbose and error-prone standard JSON parsing methods.
- The library offers a wide range of utility functions and properties for easily accessing and manipulating JSON data.
- SwiftyJSON is well-documented and has a large community, making it a popular choice for Swift developers.
Cons of SwiftyJSON
- SwiftyJSON is a standalone library, while BFKit-Swift is a more comprehensive utility framework that includes a wide range of additional features beyond just JSON parsing.
- SwiftyJSON may not be as actively maintained or updated as BFKit-Swift, which is actively developed and supported by its creator.
- The performance of SwiftyJSON may not be as optimized as the built-in JSON parsing capabilities in Swift, especially for large or complex JSON data.
Code Comparison
SwiftyJSON:
let json = JSON(data: data)
if let name = json["name"].string {
print("Name: \(name)")
}
BFKit-Swift (JSON parsing):
let json = try? JSON(data: data)
if let name = json?["name"].string {
print("Name: \(name)")
}
While the code for both libraries is similar, BFKit-Swift provides a more comprehensive set of utility functions and extensions beyond just JSON parsing, making it a more versatile choice for Swift development.
A lightweight zero-config image cache for iOS, in Objective-C.
Pros of Haneke
- Haneke provides a simple and efficient way to cache and retrieve images, making it a great choice for apps that need to display a lot of images.
- The library has a well-documented API and is easy to integrate into existing projects.
- Haneke supports a variety of image formats, including JPEG, PNG, and GIF.
Cons of Haneke
- Haneke is a relatively lightweight library, so it may not have as many features as some other image caching solutions.
- The library is not actively maintained, with the last commit being over 5 years ago.
- Haneke may not be as performant as some other image caching libraries, especially for large or complex image sets.
Code Comparison
FabrizioBrancati/BFKit-Swift
let image = UIImage(named: "example.jpg")
let imageView = UIImageView(image: image)
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
view.addSubview(imageView)
Haneke/Haneke
let imageView = HanekeImageView()
imageView.hnk_setImage(from: URL(string: "https://example.com/image.jpg"))
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 100)
view.addSubview(imageView)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Example • Todo • Author • License
Features
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.
For example you can use every iOS font with just an enum!
It also adds some useful functions with Custom classes and extends Foundation, UIKit, AppKit and WatchKit classes.
Classes and Extensions Compatibility
BFKit
iOS | macOS | watchOS | Linux | |
---|---|---|---|---|
BFApp | ||||
BFBiometric | ||||
BFButton | ||||
BFDataStructures (List - Queue - Stack) | ||||
BFLog | ||||
BFPassword | ||||
BFSystemSound | ||||
BFTextField | ||||
BFTouchID |
Foundation
iOS | macOS | watchOS | Linux | |
---|---|---|---|---|
Array | ||||
Collection | ||||
Data | ||||
Date | ||||
FileManager | ||||
Number | ||||
NSObject | ||||
NSAttributedString | ||||
NSPointerArray | ||||
ProcessInfo | ||||
Set | ||||
String | ||||
Thread |
Core Graphics
iOS | macOS | watchOS | Linux | |
---|---|---|---|---|
CGPoint |
UIKit / AppKit
WebKit
iOS | macOS | watchOS | Linux | |
---|---|---|---|---|
UIWebView |
WatchKit
iOS | macOS | watchOS | Linux | |
---|---|---|---|---|
WKInterfaceController |
Requirements
Swift | Xcode | BFKit-Swift | iOS | macOS | watchOS | Linux |
---|---|---|---|---|---|---|
1.2 | 6.3 | 1.0.0...1.4.1 | 7.0+ | |||
2.0...2.1 | 7.0 | 1.5.0...1.6.2 | 7.0+ | |||
2.2 | 7.3 | 1.6.3...1.7.0 | 7.0+ | |||
2.3 | 8.0 | 1.8.0 | 7.0+ | |||
3.0...3.1 | 8.0...8.3 | 2.0.0...2.3.0 | 8.0+ | |||
3.0...3.1 | 8.0...8.3 | 2.4.0...2.5.0 | 8.0+ | 2.0+ | ||
3.0...3.2 | 8.0...9.0 | 2.6.0 | 8.0+ | 10.10+ | 2.0+ | |
4.0 | 9.0...9.2 | 3.0.0...3.1.1 | 8.0+ * | 10.10+ * | 3.0+ * | |
4.1 | 9.3...9.4 | 3.1.2...3.2.1 | 8.0+ * | 10.10+ * | 3.0+ * | |
4.2 | 10.0 | 4.0.0...4.1.0 | 8.0+ * | 10.10+ * | 3.0+ * | |
5.0 | 10.2...10.3 | 5.0.0 | 8.0+ * | 10.10+ * | 3.0+ * | |
5.1 | 11.2 | 6.0.0...6.0.1 | 8.0+ * | 10.10+ * | 3.0+ * |
*
With App Extension Support
Communication
- If you need help, open an issue
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, see Contributing section.
Contributing
See CONTRIBUTING.md file.
Installing and Usage
See Requirements section to check Swift, Xcode, BFKit-Swift and OS versions.
Manual
- Open and build the framework from the project (BFKit.xcodeproj)
- Import BFKit.framework into your project
- Import the framework with
import BFKit
- Enjoy!
CocoaPods
-
Create a Podfile in your project directory and write into:
platform :ios, '8.0' xcodeproj 'Project.xcodeproj' use_frameworks! pod 'BFKit-Swift'
-
Change "Project" with your real project name
-
Open Terminal, go to your project directory and type:
pod install
-
Import the framework with
import BFKit
-
Enjoy!
Carthage
-
Create a Cartfile in your project directory and write into:
github "FabrizioBrancati/BFKit-Swift"
-
Open Terminal, go to project directory and type:
carthage update
-
Include the created Framework in your project
-
Add Build Phase with the following contents:
/usr/local/bin/carthage copy-frameworks
Add the paths to the BFKit-Swift framework under Input Files
$(SRCROOT)/Carthage/Build/iOS/BFKit.framework
Add the paths to the copied frameworks to the Output Files
$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/BFKit.framework
This script works around an App Store submission bug triggered by universal binaries and ensures that necessary bitcode-related files are copied when archiving
-
(Optional) Add Build Phase with the following contents
/usr/local/bin/carthage outdated --xcode-warnings
To automatically warn you when one of your dependencies is out of date
-
Import the framework with
import BFKit
-
Enjoy!
Swift Package Manager
-
Create a Package.swift file in your project directory and write into:
// swift-tools-version:5.1 import PackageDescription let package = Package( name: "Project", products: [ .executable(name: "Project", targets: ["Project"]) ], dependencies: [ .package(url: "https://github.com/FabrizioBrancati/BFKit-Swift.git", .upToNextMajor(from: "4.0.0")) ], targets: [ .target(name: "Project", dependencies: ["BFKit"]) ] )
-
Change "Project" with your real project name
-
Open Terminal, go to project directory and type:
swift build
-
Import the framework with
import BFKit
-
Enjoy!
Documentation
Documentation
Jazzy generated documentation - 100% Documented
Changelog
To see what has changed in recent versions of BFKit-Swift, see the CHANGELOG.md file.
Example
Open and run the BFKitExample project in Example folder in this repo with Xcode and see BFKit-Swift in action!
Todo
- Add tvOS support
- Create a new Example App that shows all the functionalities of BFKit-Swift
- ~100% of code coverage with Unit Tests
- Improve code to get an A from codebeat
- Add macOS support
- Add watchOS support
- Create Unit Tests and add Codecov badge
- Add Linux support (Foundation extensions only)
- Add Carthage support
- Add to CocoaPods
- Create a great documentation
Author
Fabrizio Brancati
Website: https://www.fabriziobrancati.com
Email: fabrizio.brancati@gmail.com
License
BFKit-Swift is available under the MIT license. See the LICENSE file for more info.
Top Related Projects
Elegant HTTP Networking in Swift
Network abstraction layer written in Swift.
Reactive Programming in Swift
The better way to deal with JSON data in Swift.
A lightweight zero-config image cache for iOS, in Objective-C.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot