If your app is a pure iOS Swift app, you can use the GiPStech Way-Fi Library as an XCFramework. However, since the library is written in Kotlin Multiplatform, there are certain aspects to take into account.
Singleton
Sezione intitolata “Singleton”In Kotlin, you can define a singleton using the object keyword, which ensures that only one instance of the class exists. Swift, on the other hand, does not have a built-in object construct for singletons.
To achieve similar behavior in Swift, singletons define a static property called shared, which holds the sole instance of the class. For example, you can access the singleton instance of the WayFi class using WayFi.shared.
Exceptions
Sezione intitolata “Exceptions”Kotlin exceptions are not directly mapped to Swift exceptions. When an exception is thrown from Kotlin, it is exposed in Swift as an NSError. To handle it, you need to catch the error as an NSError and access its kotlinException property.
You can then use the is operator to check whether the kotlinException is an instance of a specific subclass of WayFiException, and safely cast it to the appropriate type if needed.
Example
Sezione intitolata “Example”do { ...} catch let error as NSError { if error.kotlinException is WayFiException { ... }}Exception mapping
Sezione intitolata “Exception mapping”Another important aspect to consider is that all exceptions in the Way-Fi Library are nested within the WayFiException class, or even within its subclasses. Since Swift does not support this level of exception nesting, Kotlin/Native flattens the hierarchy by appending the base class name to all subclasses. For example, WayFiException.Activation.Failed in Kotlin becomes WayFiException.ActivationFailed in Swift.