我知道我可以查看自动翻译的Cocoa API的Swift版本的方法是在Xcode中按住命令并单击Cocoa类型。例如,以下是为UITableViewController生成的内容:
class UITableViewController : UIViewController, UITableViewDelegate, NSObjectProtocol, UIScrollViewDelegate, UITableViewDataSource {
init(style: UITableViewStyle)
var tableView: UITableView!
var clearsSelectionOnViewWillAppear: Bool // defaults to YES. If YES, any selection is cleared in viewWillAppear:
var refreshControl: UIRefreshControl!
}
有没有其他方法可以让Xcode生成这个Swift版本?最好是从命令行?
发布于 2016-08-30 10:47:14
事实证明,现代的(非“弃用”) REPL也有一种方法可以做到这一点。您可以使用:type lookup
而不是:print_module
echo -e "import CoreGraphics\n:type lookup CoreGraphics" | swift
发布于 2021-05-05 02:44:05
从Xcode12.5开始,接受的答案不再起作用,因为不再支持-deprecated-integrated-repl
标志。在@jtbandes的answer之外,下面的代码适用于我的Xcode12.5:
// iOS
echo "import UIKit\n:type lookup UIKit" | swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.5.sdk -target arm64-apple-ios14.5
// macOS
echo "import AppKit\n:type lookup AppKit" | swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -target x86_64-apple-macosx11.3
// tvOS
echo "import UIKit\n:type lookup UIKit" | swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS14.5.sdk -target arm64-apple-tvos14.5
// watchOS
echo "import WatchKit\n:type lookup WatchKit" | swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/WatchOS.platform/Developer/SDKs/WatchOS7.4.sdk -target arm64_32-apple-watchos7.4
// macCatalyst
echo "import UIKit\n:type lookup UIKit" | swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -target x86_64-apple-ios14.5-macabi -Fsystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk/System/iOSSupport/System/Library/Frameworks
当然,无论您在计算机上安装了什么SDK,这看起来都会略有不同,但命令中的其他所有内容都是相同的。
https://stackoverflow.com/questions/24887454
复制相似问题