IOSΒΆ
After adding tags to models, you can query tags in the iOS SDK.
import Fritz let tagManager = ModelTagManager(tags: ["handwriting-model", "digits"])
2. Fetch list of FritzManagedModel from the API:
Results will contain models that match all tags. Thus, tag queries for the above
tagManager
will match models that contain bothhandwriting-model
anddigits
.tagManager.fetchManagedModelsForTags { managedModels, error in guard let fritzManagedModels = managedModels, error == nil else { return } }The result of the tag query (when successful) is a FritzManagedModel list. These are not instantiated models. They contain the configuration of models stored in Fritz. You can download them as needed.
3. Download models from API:
Using the
FritzManagedModel
list from the previous query, you can download the models and instantiate theMLModel
:var allModels: [FritzMLModel] = [] tagManager.fetchManagedModelsForTags { managedModels, error in guard let fritzManagedModels = managedModels, error == nil else { return } for managedModel in fritzManagedModels { managedModel.fetchModel { downloadedModel, error in guard let fritzMLModel = downloadedModel, error == nil else { return } allModels.append(fritzMLModel) } }Once the model is downloaded the first time, calling
managedModel.fetchModel
again will load that model from disk.
Note
Depending on the size of your model, you may want to force downloads to happen over WiFi. To do so, set wifiRequiredForModelDownload
to true
. By default, all models will download over both WiFi and cellular connections:
tagManager.fetchManagedModelsForTags(wifiRequiredForModelDownload: true) { managedModels, error in // ... } let fritzManagedModels = tagManager.getManagedModelsForTags(wifiRequiredForModelDownload: true)
All tag requests are cached and stored locally. If you wish to query locally cached models, you can call getManagedModelsForTags
:
let fritzManagedModels = tagManager.getManagedModelsForTags() for managedModel in fritzManagedModels { managedModel.fetchModel { downloadedModel, error in guard let fritzMLModel = downloadedModel, error == nil else { return } allModels.append(fritzMLModel) } }