SwiftUI

Yesterday, apart from revealing a $999 monitor stand, Apple announced SwiftUI which got me quite excited.

SwiftUI is an innovative, exceptionally simple way to build user interfaces across all Apple platforms with the power of Swift. Build user interfaces for any Apple device using just one set of tools and APIs. With a declarative Swift syntax that’s easy to read and natural to write, SwiftUI works seamlessly with new Xcode design tools to keep your code and design perfectly in sync.

The code samples feels very React Native like imho:

List(landmarks) { landmark in
   HStack {
      Image(landmark.thumbnail)
      Text(landmark.name)
      Spacer()
      
      if landmark.isFavorite {
         Image(systemName: "star.fill")
            .foregroundColor(.yellow)
      }
   }
}

As @orta noted:

SwiftUI →

🤔 Wondering how fast one could build stuff when SwiftUI is combined with the also announced Combine Framework

PanelKit 2.0

Version 2.0 of the aforementioned PanelKit.

PanelKit is a UI framework that enables panels on iOS. A panel can be presented in the following ways:

  • Modally
  • As a popover
  • Floating (drag the panel around)
  • Pinned (either left or right)

This framework does all the heavy lifting for dragging panels, pinning them and even moving/resizing them when a keyboard is shown/dismissed.

Next to an underlying upgrade to Swift 4, these are the main changes:

  • Multi-pinning, pin multiple panels to a side
  • Panel resizing
  • State restoring, save and load panel states

PanelKit is featured – and was built for – Pixure (version 3 just got released). It’s always great to see a product getting built, and a part of it being spun off into open source.

PanelKit →

NYSKeyboardHelper – A helper for all your iOS keyboard needs

Matthias Nys, a former student of mine, has released his first pod NYSKeyboardHelper, a helper which resizes a scrollview so that it doesn’t go under the keyboard.

Add a constraint to your project’s Storyboard and set NYSKeyboardHelper as the custom class, or add it programmatically:

let keyboardConstraint = NYSKeyboardHelper(item: self.view, attribute: .bottom, relatedBy: .equal, toItem: scrollView, attribute: .bottom, multiplier: 1.0, constant: 0.0)
keyboardConstraint.extraIndent = 10.0
self.view.addConstraint(keyboardConstraint)

NYSKeyboardHelper – A Helper for all your keyboard needs →

In React Native, use the KeyboardAvoidingView to make sure the keyboard doesn’t overlap with the content 😉

Vapor – Server Side Swift

Interesting to see that Swift can also be used as a serverside language.

One can clearly see parallels with other languages and frameworks. For example Vapor comes with an HTTP Package, which – amongst other things – contains a Request class.

// http://vapor.codes/example?query=hi#fragments-too
let scheme = request.uri.scheme // http
let host = request.uri.host // vapor.codes

let path = request.uri.path // /example
let query = request.uri.query // query=hi
let fragment = request.uri.fragment // fragments-too

// Route “hello/:name/age/:age”
let name = request.parameters["name"] // String?
let age = request.parameters["age"]?.int // Int?

// Headers
let contentType = request.headers["Content-Type"]

// …

Vapor →

Mission Control – Remote Config Utility for iOS, OSX, …

swift

Have you ever wished you could change some config parameter for your app without deploying a new version? Of course you have! Wouldn’t it be great if you had whole config for your app in the cloud and change it as you see fit? Of course it would! Well, go ahead, just put some config somewhere in the cloud and MissionControl will take care of the rest for you.

This code will get you started:

// Local Config 
let config: [String : AnyObject] = [
    "Ready" : true,
    "LaunchForce" : 0.21
]

// Remote Config Endpoint
// Format the config as a JSON payload
let remoteURL = NSURL(string: "http://appculture.com/mission-control")!

// Initialize Misson Control.
// Settings from the remote config will overwrite the local config
MissionControl.launch(localConfig: config, remoteConfigURL: remoteURL)

// Get config values using helper accessors
let ready = ConfigBool("Ready", fallback: false)
let numberOfSeconds = ConfigInt("CountdownDuration", fallback: 10)
let launchForce = ConfigDouble("LaunchForce", fallback: 0.5)
let color = ConfigString("ReadyColor", fallback: "#7ED321")

Mission Control →

At work we build things like in all of our apps. Last year – for a Hybrid App named “De Allesweter” – we did exactly the same thing using JavaScript. That’s how we roll.

Implementing this yourself is fairly easy: fetch() the remote config, and merge it with your local one using Object.assign().

WebViewBridge.Swift

swift

Like JockeyJS, written in Swift, and with support for WKWebView:

A bridge for WebView(UIWebView, WKWebView), using JavaScriptCore, handles communications between native(Swift) and js.

Example usage (call native function from JS):

// XCode
override func viewDidLoad() {

    // …

    let webView = WKWebView()
    let bridge = ZHWebViewBridge.bridge(webview)

    bridge.registerHandler("Video.Play") { (args:[AnyObject]) -> (Bool, [AnyObject]?) in
        self.player.play()
        return (true, nil)
    }

    // …
}
// JavaScript
<-- orig source: /Pods/WebViewBridge.Swift/Sources/bridge.js -->
<script src="bridge.js"></script>
<script>
    ZHBridge.Core.ready(function() {
        ZHBridge.Core.callNativeHandler('Video.Play');
    });
</script>

WebViewBridge.Swift →