Swift fail: MIDIClientCreate

Swift Language

Swift fail: MIDIClientCreate

There is a problem with calling Core MIDI’s MIDIClientCreate function from Swift.

N.B.

This article was true when published. Apple has since fixed the problem.

Introduction

Let’s start with a simple call to Core MIDI’s client create function. You need the midi client to create MIDI input and output ports.

Works great!

Table of Contents

Problem

So, what’s the problem?

The above code compiled just fine when the scheme was an iPhone 6. I then plugged in my iPhone 4s and the problem raised its ugly head. If you don’t have an older iOS device, just select the scheme in XCode.

To verify that this was the problem I tried checking the arch and then calling separate init methods. The initial code for both was what you see in the first example here.

XCode will give you this love letter for 32 bit devices. This refers to the line where you create the client variable. (var client = MIDIClientRef())

Ok, just do this then.

Nope.

Ok, then

Works!

Go back to 64 bits.
Problem.

[expletive deleted]

Here are the definitions in CoreMIDI/MIDIServices.h

Well, actually in Objective-C:

Suggestions?

Table of Contents

Summary

You can’t create a MIDI client on older iOS devices using Swift.
If you have a solution, I’d love to hear it!

In the meantime, I’ll create the Core MIDI code (i.e. creating the client and ports) in Objective-C and call that from my Swift code.

Resources

2 thoughts on “Swift fail: MIDIClientCreate”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.