FMPWrapper - framework written in Swift based on HHFW. This block has a more object-oriented approach. However, you should note that it is based on a HHFW singleton. FMPWrapper is optional because it as a wrapper for HHFW but it simplifies work with code due to its architecture. To connect the framework, see the Connecting the FMPWrapper Framework section.
FMPWrapper contains:
The main work element is an object of the FMP class that is a factory used for initialization of builders for all used classes:
// Initialize factory
let fmp: FMP = FMP.Builder().build()
// Initialize builder for object that describes local database
let databaseBuilder: FMPDatabase.Builder = fmp.database
// Build and initialize object that describes local database
let database: FMPDatabase = databaseBuilder
.path(databasePath)
.build()
// Call object method
database.open()
The FMPWrapper framework also uses global encryption. It means that when an instance of the FMP class is initialized, the encryption key is specified that will be used to encrypt databases and files. If encryption is not used, the encryptionKey(_:) method call is optional.
// Initialize factory
let fmp: FMP = FMP.Builder()
.encryptionKey(key)
.build()
Description of examples for classes has the fmp variable that is initialized as follows:
let fmp: FMP = FMP.Builder().build()
FMPWrapper methods return handled data (objects).
In case of server requests, at the end of the request a close of the FMPRequestResponseHandler type (or other depending on the method in use) is called. In this closing, the argument is the tuple, in which the first two parameters are Bool request status and FMPError? optional error. The third parameter of the closing is request result. It can be both a NSDictionary dictionary with data and an object or an objects array (depending on the method).
let file: FMPFile = fmp.file.build()
// typealias FMPRequestResponse = (success: Bool, error: FMPError?, result: NSDictionary?)
// typealias FMPRequestResponseHandler = (_ response: FMPRequestResponse) -> Void
file.download { (response) in
if response.success {
// Hurray!
} else {
print(response.error?.description)
}
}
// typealias FMPFileMetaHandler = (_ success: Bool, _ error: FMPError?, _ meta: FMPFile.Meta?) -> Void
file.loadMeta { (success, error, result) in
if success {
print(meta?.size)
}
}
See also: