Appcelerator Hyperloop - using 3rd party swift library

450 views Asked by At

I'm trying to use Hyperloop in order to use a third-party open source library. The library I want to use is Sweet Alert iOS.

The library has a swift file. I have put this file inside an src directory inside my project's main folder (does it have to be inside src folder? can I use other folder in my project? what about sub-directories?).

According to the Titanium documentation:

Any *.swift files found in your src directories will automatically be compiled

In my app when I do something like this:

var UIView = require('UIKit/UIView');
Ti.API.info('UIView => ' + UIView);

It works. But if I try to require any of the classes in the swift file I get an error that it can't find architecture x86_64 module.

var sweetAlert = require('SweetAlert');
var cancelAnimatedView = require('CancelAnimatedView');

When looking at the SweetAlert source code, I also notice that SweetAlert class is open while other classes are just regular classes:

open class SweetAlert

I'm not a swift developer so I don't really know what it means.

What am I missing here?

EDIT

Some progress... So I found that I need to have an appc.js file that's defining the src frame work and a name for MyFramework. And that the require I do should match the filename of the swift file. Now when I compile I see some more interesting output about the swift compilation, but getting an error:

[INFO]  Generating metabase for swift MyFramework /Users/ophir/Documents/Appcelerator_Studio_Workspace/HyperloopTest1/src/SweetAlert.swift

2017-06-29T14:43:44.061Z | ERROR  | An uncaught exception was thrown!
Cannot read property '1' of null

2017-06-29T14:43:44.064Z | ERROR  | Cannot read property '1' of null 

EDIT 2

I've cleared all the script in the swift file, and narrowed it down to the following failing script:

import Foundation import UIKit import QuartzCore

public enum AlertStyle {
    case success,error,warning,none
    case customImag(imageFile:String)
}

class SweetAlert: UIViewController {
}

class AnimatableView: UIView {
    func animate(){

    }
}

If I remove the func animate() { } it will not fail. Even if this function is inside that one SweetAlert class then it will fail. And from what I've read this is a pretty standard swift code.

So this makes me wonder - is Hyperloop 2.0.0(!) ready for production apps?

1

There are 1 answers

1
Daniel Gump On

I receive a similar error when creating a simple Swift class and including it in a Titanium/Appcelerator project with the appc.js file set up just how they show in the sparse documentation. The project will compile with no issues and run in the Xcode Simulator, as long as I don't reference the class from the Swift file. If I reference that class in the project, the error arises. Based on the compile log, Swift files do compile into the project, but the classes don't seem to properly link in the end for "require"-ing into the JavaScript code.

When I search online for solutions, this same issue shows up all over, and the Titanium/Appcelerator team never presents a solution. I've tried Titanium SDK 6.0.1, 6.1.2, and 6.2.0, with all the same results; I've tried adding Swift code to existing projects and to new ones; I've also uninstalled and reinstalled Titanium/Appcelerator. (I've even tried running their sample app with no luck!)

Hyperloop does work when I use native frameworks, like UIKit, but it doesn't seem ready for production apps for 3rd party frameworks and classes.

I hope my discoveries help you and others to debug projects, but, unfortunately, I don't think I will be able to offer much help outside that.