HyperSwift

SwiftUI apps with React Hooks and HyperScript

   
Target the entire Apple Ecosystem Code in pure, modern JavaScript
Natively support iOS (iPhone / iPod Touch), iPadOS, macOS, tvOS and watchOS through the SwiftUI framework Next-generation ECMAScript compliance powered always by the most recent JavaScriptCore engine
Leverage the most advanced React APIs Additional features
Take full advantage of functional components, the complete Hooks API and HyperScript syntax (JSX) Tiniest footprint, zero third-party dependencies, install via Swift Package Manager (SPM), share the same code with the Web version of your app, live previews on simulator and device!

Sample code

The following widget displays the current value of the banana counter along with a button to increase the number of bananas.

// We define our app
let App = () => {

  // Declare state hook for counter
  const [count, setCount] = useState(0)

  // h is for HyperScript, it is equivalent to React's createElement
  return h(Div, {},
    `Total bananas: ${count}`,
     h(Button, { onClick: () => { setCount(count + 1) } },
       'Add one 🍌!'
     ),
  )
}

// Render app to SwiftUI
render(h(App), HyperBridge.getRootContainer())

The components used mimic standard HTML tags like Div and Button. Other component packs available: React Native (View, Text, Touchable) and SwiftUI (HStack, Button, Text)

Quick Start

import SwiftUI
import HyperSwift
import HyperHTML // Not required if using SwiftUI-style components

struct ContentView: View {

  init() { HHxRegistry.registerHtml() } // Or for SwiftUI-style, .registerSwiftUI()

  var body: some View {
    HHxRootView( withMainJsUrl: Bundle.main.url(
      forResource: "main", withExtension: "js"
    )! )
  }
}

# SwiftUI live previews!
struct ContentView_Previews: PreviewProvider {
  static var previews: some View {
    ContentView()
  }
}

Alternatively hit ▶️ to see your app in full action in the simulator or on device.

Examples

Find out more in our examples repo including HyperHooks code to target the Web simultaneously