Introduction
Welcome to the official documentation of Hermod – a powerful communication library for iOS and macOS developers. This library aims to simplify the process of sending and receiving data over the network, providing a seamless experience for developers.
Installation
To install Hermod library, follow the steps below:
- Open your project in Xcode.
- Go to “File” > “Swift Packages” > “Add Package Dependency”.
- In the dialog that appears, enter the repository URL: https://github.com/hermod-io/hermod.git.
- Choose the version or branch you want to use and click “Next”.
- Finally, click “Finish” to add the Hermod library to your project.
Getting Started
Before you can start using Hermod library, you need to import it into your project. Open the Swift file where you want to use Hermod and add the following import statement:
// Swift
import Hermod
// Objective-C
@import Hermod;
Once you have imported Hermod, you can start using its features.
Features
Sending Data
Hermod enables you to send data over the network easily. Follow the steps below:
- Create an instance of the `HermodClient` class.
- Set the appropriate delegate to receive callbacks for sending events.
- Call the `send(_:)` method to send your data.
// Create HermodClient instance
let hermodClient = HermodClient()
// Set delegate
hermodClient.delegate = self
// Sending data
hermodClient.send("Hello, world!")
Receiving Data
To receive data using Hermod, follow the steps below:
- Create an instance of the `HermodServer` class.
- Set the appropriate delegate to receive callbacks for incoming data.
- Implement the `didReceive(_:)` method to handle received data.
// Create HermodServer instance
let hermodServer = HermodServer()
// Set delegate
hermodServer.delegate = self
// Implement didReceive(_:) method
func didReceive(_ data: Data) {
if let receivedString = String(data: data, encoding: .utf8) {
print("Received data: \(receivedString)")
}
}
SSL/TLS Support
Hermod supports SSL/TLS encryption for secure data transmission. To enable SSL/TLS, follow the steps below:
- Generate an SSL certificate and private key.
- Create an instance of the `HermodServerTLS` class instead of `HermodServer`.
- Set the appropriate SSL certificate and private key using the `setSSLCertificate(_:privateKey:)` method.
- Configure your server to use the SSL/TLS certificate for secure connections.
Error Handling
Error handling in Hermod involves handling specific error cases and implementing the appropriate delegate methods. If an error occurs during data sending or receiving, the corresponding delegate method will be called to notify you of the error.
// Implement HermodClientDelegate method
extension YourViewController: HermodClientDelegate {
func didFailToSend(_ error: Error) {
print("Failed to send data: \(error.localizedDescription)")
}
}
// Implement HermodServerDelegate method
extension YourViewController: HermodServerDelegate {
func didFailToReceive(_ error: Error) {
print("Failed to receive data: \(error.localizedDescription)")
}
}
Conclusion
Congratulations! You have successfully installed and integrated the Hermod library into your project. Now you can start utilizing its powerful communication features to send and receive data over the network.
For more information and advanced usage scenarios, please refer to the complete documentation available at the Hermod GitHub repository.