Well, I have seen and tried most of tutorials referenced from similar questions "How to integrate Unity iOS code into Swift project". But all my attempts were failed with linker error "No such symbol for architecture arm_64" or "No such symbol for architecture x86_64". I have tried different build options in Unity side, no success. Common minus of all of that tutorials / articles is: all of them outdated, latest version of Unity I have found article is 2018.2.2f1, my version of Unity is 2018.2.20f1. So, anyone have idea how integrate Unity 2018.2.20+ iOS builded code into Swift 4.2 (XCode 10) project? Any help will be great appreciated.
Here is how I have integrated unity in my swift project.
Create new Xcode project (using swift)
(create bridging header step) Create new class File -> New -> Cocoa touch class and select language Objective C it will ask for create bridging header choose create
Goto https://github.com/jiulongw/swift-unity and download zip file
Open downloaded file and unzip it. Go to Xcode folder -> DemoApp-> You will find Unity Folder copy paste to your project (if you drag and drop it make sure you check the check box for copy at destination)
open your new Xcode project and auto generated unity project side by side so you can copy paste it easily
copy Classes Folder from unity Xcode project to your Xcode project to the unity Folder of step 4
copy Library Folder from unity Xcode project to your Xcode project to the unity Folder of step 4
copy Data Folder from unity Xcode project to your Xcode project to the unity Folder of step 4
Important Goto Xcode project tap on name of project on left side there will be two options Project and target. Select project on centre main window you can see Configuration Expand it and against the name of your project choose Unity from drop drown
Goto Classes Folder that you have copied in step And either delete main.mm file or comment everything
goto folder you have downloaded in step3 Copy all code of AppDelegate.swift
to your AppDelegate.swift
file
In your Xcode project search for YourProjectFileName-Bridging-Header and copy paste
#ifndef BRIDGING_HEADER #define BRIDGING_HEADER
#import <UIKit/UIKit.h> #import "UnityUtils.h" #import "UnityAppController.h" #import "UnityInterface.h"
#endif /* BRIDGING_HEADER */
Copy paste LaunchScreen-iPad.xib and LaunchScreen-iPhone.xib to your project and delete LaunchScreen.storyboard
Compile it :] it should compile successfully (not in my case I got error that DeviceSettings.mm there is return statement missing so I just added return deviceUnknown; before the })
You can see step3 downloaded view controller.swift file for see how to show unity view in your screen
Notes: After integrate unity you are not able to run in simulator so you have to run in real device. it is better to have unity and xcode in same machine. sometime all the framework only get ref of folder so in different machine you may face the issue
at last your project should look like
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With