         } catch {
             throw PlaygroundError.codeDownloadFailed(error)
         }
+    }
+
+    private func addFrameworkImportsIfNeeded(to code: String) -> String {
+        var frameworks = ["Foundation", "PlaygroundSupport"]
+
+        switch platform {
+        case .iOS, .tvOS:
+            frameworks.append("UIKit")
+        case .macOS:
+            frameworks.append("Cocoa")
+        }
+
+        let imports = frameworks.flatMap { framework in
+            guard !code.contains(framework) else {
+                return nil
+            }
+
+            return "import \(framework)"
+        }
+
+        guard !imports.isEmpty else {
+            return code
+        }
+
+        return imports.joined(separator: "\n") + "\n\n" + code
     }
 }
 

        }

        return nil
    }
}


            case .forceOverwrite:
                forceOverwrite = true
            case .addViewCode:
                code = .view
            case .code:
                code = .fromClipboard
            case .help:
                displayHelp = true
            }
        }

        if code != nil && (try? Folder(path: targetPath)) != nil {
            targetPath += "-\(UUID().uuidString)"
        }
    }
