Repository: expo/expo
File: packages/expo-modules-core/ios/Core/Modules/CoreModule.swift (Swift)

Code before:
      FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first?.path ?? ""
    }

    Constant("documentsDir") {
      FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path ?? ""
    }

    Function("installOnUIRuntime") {
      guard let appContext = appContext else {
        throw Exceptions.AppContextLost()
      }

      // Check if was already installed
      if appContext._uiRuntime != nil {
        return
      }

      let runtime = try appContext.runtime

      if !runtime.global().hasProperty(WORKLET_RUNTIME_KEY) {
        throw WorkletUIRuntimeException()
      }

      let pointerHolder = runtime.global().getProperty(WORKLET_RUNTIME_KEY)
      assert(pointerHolder.isObject())

      let uiRuntimePointer = WorkletRuntimeFactory.extractRuntimePointer(pointerHolder, runtime: runtime)
      if uiRuntimePointer == 0 {
        throw WorkletUIRuntimePointerExtractionException()
      }

      DispatchQueue.main.sync {
        let workletRuntime = WorkletRuntimeFactory.createWorkletRuntime(appContext, fromPointer: uiRuntimePointer)
        appContext._uiRuntime = workletRuntime
      }
    }

    // Expose some common classes and maybe even the `modules` host object in the future.
    Function("uuidv4") { () -> String in
      return UUID().uuidString.lowercased()
    }

    Function("uuidv5") { (name: String, namespace: String) -> String in
      guard let namespaceUuid = UUID(uuidString: namespace) else {
        throw InvalidNamespaceException(namespace)
      }

      return uuidv5(name: name, namespace: namespaceUuid).uuidString.lowercased()
    }

    // swiftlint:disable:next unused_closure_parameter

Review comment (suggestion):
```suggestion
      let pointerHolder = runtime.global().getProperty(WORKLET_RUNTIME_KEY)
      
      guard pointerHolder.isObject() else {
        throw WorkletUIRuntimeException()
      }
```

Code after:
      // Check if was already installed
      if appContext._uiRuntime != nil {
        return
      }

      let runtime = try appContext.runtime
      if !runtime.global().hasProperty(WORKLET_RUNTIME_KEY) {
        throw WorkletUIRuntimeException()
      }

      let pointerHolder = runtime.global().getProperty(WORKLET_RUNTIME_KEY)
      if !pointerHolder.isObject() {
        throw WorkletUIRuntimeException()
      }

      let uiRuntimePointer = WorkletRuntimeFactory.extractRuntimePointer(pointerHolder, runtime: runtime)
      if uiRuntimePointer == nil {
        throw WorkletUIRuntimePointerExtractionException()
      }

      let block = {
        let workletRuntime = WorkletRuntimeFactory.createWorkletRuntime(appContext, fromPointer: uiRuntimePointer)
        appContext._uiRuntime = workletRuntime
      }

      if Thread.isMainThread {
        block()
      } else {
        DispatchQueue.main.sync {
          block()
        }
      }
    }

    // Expose some common classes and maybe even the `modules` host object in the future.
    Function("uuidv4") { () -> String in
      return UUID().uuidString.lowercased()
    }

    Function("uuidv5") { (name: String, namespace: String) -> String in
      guard let namespaceUuid = UUID(uuidString: namespace) else {
        throw InvalidNamespaceException(namespace)
      }

      return uuidv5(name: name, namespace: namespaceUuid).uuidString.lowercased()
    }

    // swiftlint:disable:next unused_closure_parameter
    Function("getViewConfig") { (moduleName: String, viewName: String?) -> [String: Any]? in
      var validAttributes: [String: Any] = [:]
      var directEventTypes: [String: Any] = [:]