Core ML

Here’s a quick setup-guide for using custom Core ML models into your iOS project.


If you haven’t set up the SDK yet, make sure to go through those directions first. You’ll need to add the Core library to the app before using the specific feature or custom model libraries.

For the purpose of this guide, let’s assume you have the following:

  1. A Core ML model file called Digits.mlmodel that recognizes the numbers 0-9 in an image.
  2. You have dragged this model into Xcode and can access the model let model = Digits() in your code.
  3. Your Fritz api key is api-key-12345
  4. Your Fritz model id for the Digits model is model-id-abcde

1. Conform Your Model

In order to expose Fritz functionality to your Xcode generated Digits class, you must conform that class to a Fritz protocol that tells the SDK the about your api key and model id for that model.

Create a new file called Digits+Fritz.swift and conform your class like so:

import Fritz

extension Digits: Fritz.SwiftIdentifiedModel {

    static let modelIdentifier = "model-id-abcde"

    static let packagedModelVersion = 1

Create a new extension called Digits+Fritz and conform your class like so:

// Digits+Fritz.h
@import Fritz;

@interface Digits(Fritz) <FritzObjcIdentifiedModel>
// Digits+Fritz.m
#import "Digits+Fritz.h"

@implementation Digits(Fritz)
+ (NSString * _Nonnull)fritzModelIdentifier {
    return @"model-id-abcde";

+ (NSInteger)fritzPackagedModelVersion {
    return 1;

2. Update Model Usage

By conforming the Digits class to the Fritz protocol we have exposed a .fritz() function which injects an instrumented MLModel into the instance of that class.

Find any calls that look like this:

let model = Digits()

And change them to:

let model = Digits().fritz()

Find any calls that look like this:

Digits *model = [[Digits alloc] init];

And change them to:

Digits *model = [[Digits alloc] init].fritz;

All of your prediction calls stay the same and they will be instrumented by the SDK.

3. Build and run your app

Test out each part of your app that uses the prediction, then look at the Fritz dashboard to see if data is showing up.