Installation¶
Easy installation¶
This option gives a simple iOS app that integrates swix:
This method gives a command-line tool that can be run on OSX.
Running Python/NumPy on iOS¶
Two projects exist that allow Python to run on iOS, kivy-ios and beeware.
kivy-ios:As of 2016-05-02, a new xcodeproj can be created by
exactly following the instructions in the readme. Importantly, don’t forget to
run ./toolchain.py build numpy
then updating the xcodeproj. On GitHub, they
have instructions to get kivy-ios running.
This tool can run NumPy.
When creating a GUI with the Kivy framework in your app “main.py”, the GUI looks like Kivy, not native. This is suitable if you’re trying to create the same application across many devices, which the Kivy framework allows.
beeware: An example iOS project can be found at beeware-ios-template. In this, the app is written completely in Python and can call native APIs naturally (i.e., you have access to all possible iOS APIs).
The BeeWare framework can not run NumPy as of 2016-05-02, but it’s on the roadmap. This depends on Python-iOS-support and there’s issue #23 tracks it.
Manual installation¶
This method can be generalized to any Swift project, whether it be iOS or OSX.
- Download the repo or this file
- Include the folder
swix-master/swix/swix/swix
in your project. The folder you want is right next to amain.swift
- Add (or modify) your Swift bridging header to include some Objective-C/C
functions. Essentially, this means copying the image below to include
swix/objc/swix-Bridging-Header.h
in “Swift Compiler – Code Generation” under “Project”.
Done! To test, try inserting in
main.swift
or inviewDidLoad
var x = arange(10) var y = sqrt(x) print(x) print(y)
How to creat a new iOS app that includes swix¶
This is a more detailed version of the section on manual installation.
- Open Xcode and select to make a new iOS project.
- Be sure to select the source language as Swift
- Add the swix folder to your iOS app and copy the files. The swix folder is
in the same folder and right next to a
main.swift
. The path should beswix-master/swix/swix/swix/
3a. Make sure to check the box “Copy files if needed”!
- Go to your main project settings (the blue thing file at the very top of the left sidebar) and change the Swift bridging header in “Swift Compiler – Code Generation”
- Build your project with ⌘R!
Optional¶
These steps are optional but can have nice results.
- Change your compiler optimization flag which can lead to
incredible speed gains. Be careful – this skips
assert
. I would recommend testing with-Onone
before switching. - If you plan on using
read_csv, write_csv, savefig, imshow
you need to change theS2_PREFIX
innumbers.swift
. This should point to the swix folder; something likethe/path/to/yourXcodeProjectName/swix/
Notes¶
- I have not spent time on package management. There should be an
import swix
and is not (but I welcome pull requests!) - During my testing, swix doesn’t work in Playgrounds although it’s possible.
Possible bugs¶
I have marked other installation issues on GitHub with the “question” tag, viewable with the search is:issue label:question
- Xcode can’t find the functions but seems to compile/etc correctly.
- Cleaning before building can help with this . More details are described in issue #24. Part of this is making sure “Copy if needed” is selected copying swix into an Xcode project.
"Unresolved identifier *_objc"
- The bridging header probably hasn’t been added correctly. Ensure
swix/objc/swix-Bridging-Header.h
has the correct path.
- The bridging header probably hasn’t been added correctly. Ensure
Unresolved identifier vDSP_*
or similar,- The Accelerate framework hasn’t been added to Build Phases/Link Binary with Libraries.
- The Accelerate framework can’t be found when running an iOS xcodeproj in the iOS simulator. For me it works on a physical device.
".../swix/objc/OpenCV.h:12: 'opencv2/opencv.hpp' file not found".
- Under Build Phases/Link Binary with library add
swix/objc/opencv2.framework
. If you don’t see the “Link Binary with Libraries” hit the plus button in the upper left (at least for XCode 6). - When clicking on “Add files to *” and in the diaglog that came up I
should have hit the checkbox next to
swix-OSXTests
.
- Under Build Phases/Link Binary with library add