如何在iOS SDK中使用Swift REPL

编程入门 行业动态 更新时间:2024-10-22 12:28:19
本文介绍了如何在iOS SDK中使用Swift REPL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我可以使用iOS SDK运行Swift REPL吗?

Can I run Swift REPL with iOS SDK?

我想在REPL中导入并使用 UIKit ,但没有成功。

I want to import and use UIKit in REPL, but no success.

$ xcrun --sdk iphonesimulator8.1 --show-sdk-path /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk $ xcrun --sdk iphonesimulator8.1 swift Welcome to Swift! Type :help for assistance. 1> import UIKit /var/folders/kb/xgglxb597sv6h8b744d5vft00000gn/T/lldb/92014/repl1.swift:2:8: error: no such module 'UIKit' import UIKit ^ $ swift -sdk `xcrun --sdk iphonesimulator8.1 --show-sdk-path` Welcome to Swift! Type :help for assistance. 1> import UIKit /var/folders/kb/xgglxb597sv6h8b744d5vft00000gn/T/lldb/91881/repl1.swift:2:8: error: no such module 'UIKit' import UIKit ^ 1> import Cocoa 2>

我正在使用Xcode版本6.1(6A1052d)

I'm using Xcode Version 6.1 (6A1052d)

推荐答案

您可以通过从 lldb 运行 repl 来实现它,附加到iOS应用程序进程(您的Xcode项目)。

You may achieve it by running repl from lldb, which attached to iOS application process (of your Xcode project).

  • 在Xcode中构建项目,或:

  • Build project in Xcode, or: $ xcrun xcodebuild -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.3' clean build

  • 开始独立 lldb :

    $ xcrun lldb -- $DerivedData/$AppName/Build/Products/Debug-iphonesimulator/$AppName.app (lldb) process attach --name '$AppName' --waitfor

    您可能会发现有用的平台选择ios-simulator 和平台连接$ UDID 命令。

    You may find useful platform select ios-simulator and platform connect $UDID commands here.

    运行您在Xcode的iOS模拟器中的iOS应用程序

    Run your iOS application in iOS simulator from Xcode

    • 或者从命令行:

    • Or from command line:

  • 启动模拟器

  • Boot simulator

    • 来自乐器:

    $ xcrun instruments -w "`xcrun instruments -s | grep 'iPhone 7 (10.3)' | head -1`"

  • 或作为申请表:

  • Or as an application:

    $ open -a "Simulator" --args -CurrentDeviceUDID "`xcrun instruments -s | grep 'iPhone 7 (10.3)' | head -1 | sed -E -e 's/[^][]*\[([^][]*)\][^][]*/\1/g'`"

  • 在模拟器上安装应用程序,然后启动它:

    Install the application on simulator, and launch it:

    $ xcrun simctl install booted $DerivedData/$AppName/Build/Products/Debug-iphonesimulator/$AppName.app $ xcrun simctl launch booted $AppBundleID

    此外,你甚至可以使用 xcrun simctl启动 - -wait-for-debugger 并稍后启动 lldb 。

    Also, you can even use xcrun simctl launch --wait-for-debugger and start lldb later.

  • 或使用 ios-sim :

  • 可选择启动模拟器并安装应用程序:

  • Optionally boot simulator & install the application: $ ios-sim start --devicetypeid 'iPhone-7, 10.3' $ ios-sim install --devicetypeid 'iPhone-7, 10.3' $DerivedData/$AppName/Build/Products/Debug-iphonesimulator/$AppName.app

  • 启动它:

  • Launch it:

    $ ios-sim launch --devicetypeid 'iPhone-7, 10.3' $DerivedData/$AppName/Build/Products/Debug-iphonesimulator/$AppName.app

  • 附加到iOS模拟器中的进程 lldb :

    Attach to process in iOS simulator in lldb:

    (lldb) continue (lldb) process interrupt

  • 运行 swift repl。

    (lldb) repl 1> import UIKit 2>

  • 此外,与 swift repl 在Xcode调试终端模拟器中,这里我们有工作源自动完成和命令历史导航。

    Furthermore, as opposed to swift repl in Xcode debug terminal emulator, here we have working source autocompletion and command history navigation.

    更多推荐

    如何在iOS SDK中使用Swift REPL

    本文发布于:2023-11-28 07:23:25,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1641458.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何在   iOS   SDK   Swift   REPL

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!