【发布时间】:2015-07-28 21:18:28
【问题描述】:
在 Xcode 中,编译器抱怨以下转换:
CGFloat width = 5.6f;
NSInteger num = (NSInteger)floor(width);
说“从'double'类型的函数调用转换为不匹配类型'NSInteger'(又名'int')”
一种解决方法是将 CGFloat 简单地转换为截断的 NSInteger,但我想通过显式地板使代码清晰/易于阅读。是否有返回 int 的地板函数?或者其他一些(干净的)方法?
我在“Apple LLVM 6.0 - 编译器标志”下的编译器设置,在“其他 C 标志”中,我有 -O0 -DOS_IOS -DDEBUG=1 -Wall -Wextra -Werror -Wnewline-eof -Wconversion -Wendif -labels -Wshadow -Wbad-function-cast -Wenum-compare -Wno-unused-parameter -Wno-error=deprecated
谢谢!
【问题讨论】:
-
我尝试了代码,它运行良好,没有任何错误。您是否尝试再次编译它?这有时会有所帮助。
-
我认为这可能与编译器设置有关——我的设置相当严格(并且必须保持这种设置)。
-
我试过你指定的代码,没有错误。你有什么设置?
-
在我的构建设置中的“Apple LLVM 6.0 - 自定义编译器标志”中,我有: -O0 -DOS_IOS -DDEBUG=1 -Wall -Wextra -Werror -Wnewline-eof -Wconversion -Wendif -labels -Wshadow -Wbad-function-cast -Wenum-compare -Wno-unused-parameter -Wno-error=deprecated
标签: ios objective-c iphone xcode