最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

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

Swift crifan 2425浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
84 queries in 0.184 seconds, using 22.09MB memory