All Projects → tuarua → Swift-IOS-ANE

tuarua / Swift-IOS-ANE

Licence: Apache-2.0 License
FlashRuntimeExtensions.swift. Example Air Native Extension written in Swift 5 for iOS, macOS and tvOS

Programming Languages

swift
15916 projects
actionscript
884 projects
objective c
16641 projects - #2 most used programming language
shell
77523 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Swift-IOS-ANE

DesktopToastANE
Adobe Air Native Extension for displaying adaptive and interactive toast notifications in Windows 8, 10 and OSX
Stars: ✭ 28 (-50%)
Mutual labels:  adobe-air, native-extension, ane
AR-ANE-Samples
MyAR is an augmented reality Air Native Extension supporting Android and iOS based on Wikitude SDK
Stars: ✭ 39 (-30.36%)
Mutual labels:  adobe-air, ane, air-native-extensions
AIRFacebook-ANE
Native extension for Adobe AIR providing cross-platform API to Facebook SDK 4
Stars: ✭ 19 (-66.07%)
Mutual labels:  adobe-air, native-extension, ane
common-dependencies-ANE
In this repository find all the required shared libraries for our Air Native Extensions to make sure your final app will have the minimum required libraries so your app won't be unnecessarily huge in size.
Stars: ✭ 24 (-57.14%)
Mutual labels:  adobe-air, ane, air-native-extensions
Kvconstraintkit
An Impressive Auto Layout DSL for iOS, tvOS & OSX. & It is written in pure swift.
Stars: ✭ 91 (+62.5%)
Mutual labels:  osx, tvos
Extendable
Blocks Based Bluetooth LE Connectivity framework for iOS/watchOS/tvOS/OSX. Quickly configure centrals & peripherals, perform read/write operations, and respond characteristic updates.
Stars: ✭ 88 (+57.14%)
Mutual labels:  osx, tvos
Metal Tutorial
Metal入门资料,涉及到iOS平台,OSX平台,TvOS平台,其中,OSX平台可以直接运行,iOS平台,TvOS平台都需要使用真机设备测试运行。下面是相关博客,欢迎拍砖
Stars: ✭ 156 (+178.57%)
Mutual labels:  osx, tvos
ANE-AndroidSupport
Android Support Library Native Extension
Stars: ✭ 21 (-62.5%)
Mutual labels:  adobe-air, ane
Xcake
🍰 Describe Xcode projects in a human readable format and (re)generate one on demand.
Stars: ✭ 549 (+880.36%)
Mutual labels:  osx, tvos
Fire
🔥A delightful HTTP/HTTPS networking framework for iOS/macOS/watchOS/tvOS platforms written in Swift.
Stars: ✭ 243 (+333.93%)
Mutual labels:  osx, tvos
QuoteKit
A framework to use the free APIs provided by https://quotable.io
Stars: ✭ 17 (-69.64%)
Mutual labels:  tvos, swift5
Fab
🛍️ A Floating Action Button for macOS. Inspired by Material Design, and written in Swift.
Stars: ✭ 24 (-57.14%)
Mutual labels:  osx, swift5
Nord Xcode
An arctic, north-bluish clean and elegant Xcode color theme.
Stars: ✭ 63 (+12.5%)
Mutual labels:  osx, tvos
Swiftfortunewheel
The ultimate spinning wheel view that supports dynamic content and rich customization.
Stars: ✭ 114 (+103.57%)
Mutual labels:  osx, tvos
Sqlitelib
Easily build a custom SQLite static library for use in macOS and iOS frameworks and apps.
Stars: ✭ 38 (-32.14%)
Mutual labels:  osx, tvos
stinsen
Coordinators in SwiftUI. Simple, powerful and elegant.
Stars: ✭ 563 (+905.36%)
Mutual labels:  tvos, swift5
ANE-GooglePlayServices
Shared library including the Google Play Services Client Library
Stars: ✭ 19 (-66.07%)
Mutual labels:  adobe-air, ane
Darklightning
Simply the fastest way to transmit data between iOS/tvOS and OSX
Stars: ✭ 286 (+410.71%)
Mutual labels:  osx, tvos
Layoutframeworkbenchmark
Benchmark the performances of various Swift layout frameworks (autolayout, UIStackView, PinLayout, LayoutKit, FlexLayout, Yoga, ...)
Stars: ✭ 316 (+464.29%)
Mutual labels:  osx, tvos
ANE-LAB
ANE-LAB installs AIR Native Extension files in your project automatically.
Stars: ✭ 29 (-48.21%)
Mutual labels:  adobe-air, air-native-extensions

FreSwift

Example Xcode projects showing how to create AIR Native Extensions for iOS, tvOS & macOS using Swift.
It supports iOS 9.0+, tvOS 9.2+, macOS 10.10+

Xcode 13.2.1 (13C100) must be used with Apple Swift version 5.5.2 (swiftlang-1300.0.47.5 clang-1300.0.29.30)

It is not possible to mix Swift versions in the same app. Therefore all Swift based ANEs must use the same exact version.

This project is used as the basis for the following ANEs
Firebase-ANE
Vibration-ANE
GoogleMaps-ANE
AdMob-ANE
WebViewANE
AR-ANE
ML-ANE


paypal

Getting Started

A basic Hello World starter project is included for each target

How to use

Full documentation is provided

The following table shows the primitive as3 types which can easily be converted to/from Swift types

AS3 type Swift type AS3 param->Swift return Swift->AS3
String String let str = String(argv[0]) return str.toFREObject()
int Int let i = Int(argv[0]) return i.toFREObject()
Boolean Bool let b = Bool(argv[0]) return b.toFREObject()
Number Double let dbl = Double(argv[0]) return dbl.toFREObject()
Number CGFloat let cfl = CGFloat(argv[0]) return cfl.toFREObject()
Date Date let date = Date(argv[0]) return date.toFREObject()
Rectangle CGRect let rect = CGRect(argv[0]) return rect.toFREObject()
Point CGPoint let pnt = CGPoint(argv[0]) return pnt.toFREObject()
Vector int [Int] let a = [Int](argv[0]) return a.toFREObject()
Vector Boolean [Bool] let a = [Bool](argv[0]) return a.toFREObject()
Vector Number [Double] let a = [Double](argv[0]) return a.toFREObject()
Vector String [String] let a = [String](argv[0]) return a.toFREObject()
Object [String, Any]? let dct = Dictionary.init(argv[0]) N/A
null nil return nil

Basic Types

let myString: String? = String(argv[0])
let myInt = Int(argv[1])
let myBool = Bool(argv[2])

let swiftString = "I am a string from Swift"
return swiftString.toFREObject()

Creating new FREObjects

let newPerson = FREObject(className: "com.tuarua.Person")

// create a FREObject passing args
// 
// The following param types are allowed: 
// String, Int, UInt, Double, Float, CGFloat, NSNumber, Bool, Date, CGRect, CGPoint, FREObject
let frePerson = FREObject(className: "com.tuarua.Person", args: "Bob", "Doe", 28, myFREObject)

Calling Methods

// call a FREObject method passing args
// 
// The following param types are allowed: 
// String, Int, UInt, Double, Float, CGFloat, NSNumber, Bool, Date, CGRect, CGPoint, FREObject
let addition = freCalculator.call(method: "add", args: 100, 31) {

Getting / Setting Properties

let oldAge = Int(person["age"])
let newAge = oldAge + 10

// Set property using braces access
person["age"] = (oldAge + 10).toFREObject()

// Create using FreObjectSwift allowing us to get/set properties using inferred types
// The following param types are allowed: 
// String, Int, UInt, Double, Float, CGFloat, NSNumber, Bool, Date, CGRect, CGPoint, FREObject
if let swiftPerson = FreObjectSwift(className: "com.tuarua.Person") {
    let oldAge:Int = swiftPerson.age
    swiftPerson.age = oldAge + 5
}

Arrays

let airArray: FREArray = FREArray(argv[0])
// convert to a Swift [String]
let airStringVector = [String](argv[0])

// create a Vector.<com.tuarua.Person> with fixed length of 5
let myVector = FREArray(className: "com.tuarua.Person", length: 5, fixed: true)
let airArrayLen = airArray.length

// loop over FREArray
for fre in airArray {
    trace(Int(fre))
}

// set element 0 to 123
airArray[0] = 123

// push 2 elements to a FREArray
airArray.push(66, 77)

// return Int Array to AIR
let swiftArr: [Int] = [99, 98, 92, 97, 95]
return swiftArr.toFREObject()

Sending Events back to AIR

trace("Hi", "There")

// with interpolation
trace("My name is: \(name)")

dispatchEvent("MY_EVENT", "this is a test")

Bitmapdata

if let img = UIImage(freObject: argv[0]) {
    if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
        let imgView: UIImageView = UIImageView(image: img)
        imgView.frame = CGRect(x: 0, y: 0, width: img.size.width, height: img.size.height)
        rootViewController.view.addSubview(imgView)
    }
}

ByteArrays

let asByteArray = FreByteArraySwift(freByteArray: argv[0])
if let byteData = asByteArray.value { // NSData
	let base64Encoded = byteData.base64EncodedString(options: .lineLength64Characters)
}

Error Handling

FreSwiftLogger.shared.context = context

guard FreObjectTypeSwift.int == expectInt.type else {
    return FreError(stackTrace: "",
        message: "Oops, we expected the FREObject to be passed as an int but it's not",
        type: .typeMismatch).getError(#file, #line, #column)
}

Advanced Example - Extending. Convert to/from SCNVector3

public extension SCNVector3 {
    init?(_ freObject: FREObject?) {
        guard let rv = freObject else { return nil }
        let fre = FreObjectSwift(rv)
        self.init(fre.x as CGFloat, fre.y, fre.z)
    }
    func toFREObject() -> FREObject? {
        return FREObject(className: "flash.geom.Vector3D", args: x, y, z)
    }
}

public extension FreObjectSwift {
    public subscript(dynamicMember name: String) -> SCNVector3? {
        get { return SCNVector3(rawValue?[name]) }
        set { rawValue?[name] = newValue?.toFREObject() }
    }
}

applicationDidFinishLaunching

The static library contains a predefined +(void)load method in FreMacros.h. This method can safely be declared in different ANEs. It is also called once for each ANE and very early in the launch cycle. In here the SwiftController is inited and onLoad() called. This makes an ideal place to add observers for applicationDidFinishLaunching and any other calls which would normally be added as app delegates, thus removing the restriction of one ANE declaring itself as the "owner".
Note: We have no FREContext yet so calls such as trace, dispatchEvent will not work.

@objc func applicationDidFinishLaunching(_ notification: Notification) {
   appDidFinishLaunchingNotif = notification //save the notification for later
}
func onLoad() {
    NotificationCenter.default.addObserver(self, selector: #selector(applicationDidFinishLaunching),
    name: UIApplication.didFinishLaunchingNotification, object: nil)    
}

Required AS3 classes

com.tuarua.fre.ANEUtils.as and com.tuarua.fre.ANEError.as and avmplus.DescribeTypeJSON are required by FreSwift and should be included in the AS3 library of your ANE

Prerequisites

You will need

  • Xcode
  • IntelliJ IDEA
  • AIR 33.1.1.713+
  • wget on macOS via brew install wget
  • Carthage
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].