繁体   English   中英

如何在iOS SDK中使用Swift REPL

[英]How can I use Swift REPL with iOS SDK

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

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

$ 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)

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

  1. 在Xcode中构建项目,或:

     $ xcrun xcodebuild -configuration Debug -destination 'platform=iOS Simulator,name=iPhone 7,OS=10.3' clean build 
  2. 启动iOS项目的独立 lldb

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

    您可以在此处找到有用的platform select ios-simulatorplatform connect $UDID命令。

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

    • 或者从命令行:

      1. 启动模拟器

        • instruments

           $ xcrun instruments -w "`xcrun instruments -s | grep 'iPhone 7 (10.3)' | head -1`" 
        • 或作为申请:

           $ open -a "Simulator" --args -CurrentDeviceUDID "`xcrun instruments -s | grep 'iPhone 7 (10.3)' | head -1 | sed -E -e 's/[^][]*\\[([^][]*)\\][^][]*/\\1/g'`" 
      2. 在模拟器上安装应用程序,然后启动它:

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

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

    • 或者使用ios-sim

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

         $ ios-sim start --devicetypeid 'iPhone-7, 10.3' $ ios-sim install --devicetypeid 'iPhone-7, 10.3' $DerivedData/$AppName/Build/Products/Debug-iphonesimulator/$AppName.app 
      2. 启动它:

         $ ios-sim launch --devicetypeid 'iPhone-7, 10.3' $DerivedData/$AppName/Build/Products/Debug-iphonesimulator/$AppName.app 
  4. lldb附加到iOS模拟器中的lldb

     (lldb) continue (lldb) process interrupt 
  5. 运行swift repl。

     (lldb) repl 1> import UIKit 2> 

此外,与Xcode调试终端仿真器中的swift repl相反,这里我们有工作源自动完成和命令历史导航。

Swift REPL目前不支持iOS设备或iOS模拟器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM