首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何检索Cocoa API的Swift“头”文件?

如何检索Cocoa API的Swift“头”文件?
EN

Stack Overflow用户
提问于 2014-07-22 20:29:09
回答 2查看 2.9K关注 0票数 16

我知道我可以查看自动翻译的Cocoa API的Swift版本的方法是在Xcode中按住命令并单击Cocoa类型。例如,以下是为UITableViewController生成的内容:

代码语言:javascript
复制
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版本?最好是从命令行?

EN

回答 2

Stack Overflow用户

发布于 2016-08-30 10:47:14

事实证明,现代的(非“弃用”) REPL也有一种方法可以做到这一点。您可以使用:type lookup而不是:print_module

代码语言:javascript
复制
echo -e "import CoreGraphics\n:type lookup CoreGraphics" | swift
票数 6
EN

Stack Overflow用户

发布于 2021-05-05 02:44:05

从Xcode12.5开始,接受的答案不再起作用,因为不再支持-deprecated-integrated-repl标志。在@jtbandesanswer之外,下面的代码适用于我的Xcode12.5:

代码语言:javascript
复制
// 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,这看起来都会略有不同,但命令中的其他所有内容都是相同的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24887454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档