Skip to content

CausalLabs/ios-client-sdk

Repository files navigation

Causal Labs iOS SDK

CI CocoaPods Integration

The Causal Labs iOS SDK integrates Causal with native iOS apps.

Requirements

  • iOS 13.0+
  • Swift 5.8+
  • Xcode 14.0+

Package Installation

pod 'CausalLabsSDK', '~> 0.11.0'

Note

If you check-in the Pods/ directory into git, we recommend that you git ignore Pods/CausalLabsSDK/compiler/.

Causal Compiler Configuration

  1. Install Java 11 (via homebrew)
brew install java11
  1. Update your .zprofile or .zshrc (or equivalent)
export PATH="/usr/local/opt/openjdk@11/bin:$PATH"
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include $CPPFLAGS"

Note

Homebrew should indicate the path to java when installation completes.

Depending on your machine configuration, java may be located somewhere else. If so, you need to replace the path /usr/local/opt/openjdk@11/libexec/openjdk.jdk to correspond to your Java installation location.

  1. Verify java is successfully installed and in your PATH
$ which java
/usr/local/opt/openjdk@11/bin/java
$ java -version
openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment Homebrew (build 11.0.18+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.18+0, mixed mode)
  1. Symlink the JDK so that causalc (and /usr/libexec/java_home) can find it
sudo ln -s /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk

Xcode Project Configuration

After integrating the SDK via CocoaPods and installing Java, you'll need to add a build script phase to your Xcode project.

  1. Navigate to your main application target's Build Phases tab.
  2. Add a new Run Script Phase before the Compile Sources phase.
  3. Name the script phase FDL Generation.
  4. Set the shell to /bin/sh.
  5. Create your Features.fdl file and place it in your project directory.
  6. Add a new file to your project called Causal.generated.swift.
  7. Add the following script to invoke the compiler and generate your Swift code from your FDL.
${PROJECT_DIR}/Pods/CausalLabsSDK/compiler/bin/compiler --swift \
    ${PROJECT_DIR}/PATH_TO_YOUR/Causal.generated.swift \
    ${PROJECT_DIR}/PATH_TO_YOUR/Features.fdl

Note

Remember to replace PATH_TO_YOUR above with the paths to your own files.

Now you can build and run! If your build succeeds, you should see your generated code in Causal.generated.swift. If your build fails, check the build logs and ensure your paths to the compiler and source files are correct.

Examples

Documentation

License

See LICENSE.txt for details.

Copyright © 2023-present Causal Labs, Inc. All rights reserved.