最新消息:服务器现已从linode换到fzhost.net,且主题已从retina 0.2换为大前端D8

[已解决]Swift 代码出错:Use of undeclared type BOOL did you mean to use ObjCBool

Swift crifan 21浏览 0评论

[问题]

将OC代码转换为swift期间,代码:

    func setSelectedIndex(newSelectedIndex:UInt, animated:BOOL) {

出错:

Use of undeclared type ‘BOOL’; did you mean to use ‘ObjCBool’?

如图:

Use of undeclared type BOOL did you mean to use ObjCBool

[解决过程]

1.感觉swift中的布尔变量,应该不是ObjCBool才对。

要去搞清楚Swift中的布尔类型变量如何写。

搜:

swift Use of undeclared type BOOL did you mean to use ObjCBool

swift  BOOL  ObjCBool

参考:

ios – Cleanly converting an Objective-C Boolean to a Swift Bool? – Stack Overflow

好像是Boolean

Swift Boolean Literals (Obj-C @YES @NO equivalent) – Stack Overflow

好像都属于NSNumber

Boolean – Swift Blog – Apple Developer

应该是Bool

2.搜:

swift bool

参考:

The Swift Programming Language (Swift 2.1): The Basics

 

[总结]

swift中的布尔类型变量叫做:Bool

常量值真和假是true和false

所以,此处的变量类型声明:

OC中的 BOOL

就变成了:

Swift的Bool

改为:

    func setSelectedIndex(newSelectedIndex:UInt, animated:Bool) {

即可。

-》果然和我猜的不错,应该不是用ObjCBool,直接用Bool就好了。

转载请注明:在路上 » [已解决]Swift 代码出错:Use of undeclared type BOOL did you mean to use ObjCBool

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
51 queries in 0.498 seconds, using 12.75MB memory