📦 SwiftyLaunch Modules
🔗 SharedKit
Helper Functions
Identify current Platform

Identify current Platform the code is running on

SharedKit Helper Function (SwiftyLaunch Module) - currentPlatform

Since the introduction of iPad Support in SwiftyLaunch 1.4, it was necessary to be able to detect what platform the code is being executed on to provide the correct layout and functionality.

For this, we have introduced a convenient currentPlatform global computed variable. It simply returns either .phone or .pad depending on the platform it's being run on.

Variable declaration:

currentPlatform.swift
public var currentPlatform: Platform {
    return UIDevice.current.userInterfaceIdiom == .pad ? .pad : .phone
}
currentPlatform.swift
public enum Platform {
    case phone
    case pad
}

Note that we only use this variable when there is more than one platform selected during project generation.

Usage Example

From the AIVisionExampleView() of AIKit utilizing the Flexible Stack View:

AIVisionExampleView.swift
import SwiftUI
import SharedKit
// ...Other imports
 
struct AIVisionExampleView: View {
 
    // ...
 
    // VStack on iPhone, HStack on iPad
    // iPhone: Camera Feed on top, Shutter Button at the bottom
    // iPad: Camera Feed on the left, Shutter Button on the right
    Stack(currentPlatform == .phone ? .vertical : .horizontal, spacing: 25) {
 
        CameraView()
 
        // VStack on iPad, HStack on iPhone
        Stack(currentPlatform == .phone ? .horizontal : .vertical) {
 
            // ...Photos Picker Button
 
            Button {
                // ...
            } label: {
                Circle()
                    .fill(.white)
                    .frame(width: 75, height: 75)
            }
            .buttonStyle(ShutterButton())
 
            // ... Selfie / Rear Camera Switch Button
        }
 
    }
}

SharedKit Helper Function Example (SwiftyLaunch Module) - currentPlatform