久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

'CGFloat' 不能轉換為 'UInt8' 和 Swift 和

‘CGFloat’ is not convertible to ‘UInt8#39; and other CGFloat issues with Swift and Xcode 6 beta 4(CGFloat 不能轉換為 UInt8 和 Swift 和 Xcode 6 beta 4 的其他 CGFloat 問題)
本文介紹了'CGFloat' 不能轉換為 'UInt8' 和 Swift 和 Xcode 6 beta 4 的其他 CGFloat 問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如果這能說明問題,這里是原始的 Objective-C 代碼.

In case this illuminates the problem, here's the original Objective-C code.

int x = (arc4random()%(int)(self.gameView.bounds.size.width*5)) - (int)self.gameView.bounds.size.width*2;
int y = self.gameView.bounds.size.height;
drop.center = CGPointMake(x, -y);

我從這段代碼開始.第 2 行和第 3 行很好,為了清楚起見,我稍后再展示它們.

I started out with this code. Lines 2 and 3 are fine, I'm presenting them for clarity later.

let x = CGFloat(arc4random_uniform(UInt32(self.gameView.bounds.size.width * 5))) - self.gameView.bounds.size.width * 2
let y = self.gameView.bounds.size.height
dropView.center = CGPointMake(x, -y)

在 Xcode 6 beta 3 中,必須將 arc4random_uniform UInt32 結果轉換為 CGFloat 才能使減法和乘法起作用.這不再起作用,編譯器顯示錯誤:

In Xcode 6 beta 3, it was necessary to cast the arc4random_uniform UInt32 result to CGFloat in order for the minus and multiplication to work. This doesn't work anymore and the compiler shows an error:

‘CGFloat’不能轉換為‘UInt8’

‘CGFloat’ is not convertible to ‘UInt8’

發行說明狀態:

CGFloat 現在是一種獨特的浮點類型,它在 32 位架構上封裝了 Float 或在 64 位架構上封裝了 Double.它提供了 Float 和 Double 的所有相同比較和算術運算,并且可以創建使用數字文字.使用 CGFloat 將您的代碼與您的代碼可能出現的情況隔離開來! 適用于 32 位,但在構建 64 位時失敗,反之亦然.(17224725)"

"CGFloat is now a distinct floating-point type that wraps either a Float on 32-bit architectures or a Double on 64-bit architectures. It provide all of the same comparison and arithmetic operations of Float and Double and may be created using numeric literals. Using CGFloat insulates your code from situations where your code would be !fine for 32-bit but fail when building for 64-bit or vice versa. (17224725)"

我只是在類型上做錯了嗎?我什至不知道如何更好地描述這個問題,以便向 Apple 提交 beta 4 的錯誤報告.我擁有的幾乎每個 Swift 項目都受到了這個問題的影響,所以我尋找一些理智.

Am I just doing something wrong with types? I don't even know how to describe this problem better to submit a bug report to Apple for beta 4. Pretty much every single Swift project I have that does any kind of point or rect manipulation got hit by this issue, so I'm looking for some sanity.

推薦答案

由于 Swift 沒有隱式類型轉換,您必須指定所有發生的類型轉換.讓這個案例特別乏味的是,目前 Swift 似乎缺乏 CGFloatUInt32 等類型之間的直接轉換,你必須像你一樣通過一個中間類型發現了.

Since Swift doesn't have implicit type conversions, you must specify all the type conversions that take place. What makes this case particularly tedious, is that currently Swift seems to lack direct conversions between CGFloat and types such as UInt32, and you must go through an intermediate type as you've discovered.

最后,arc4random_uniform需要進行兩次雙重轉換:

In the end, two double conversions are needed for the arc4random_uniform:

let bounds = CGRectMake(0.0, 0.0, 500.0, 500.0)
var x = CGFloat(UInt(arc4random_uniform(UInt32(UInt(bounds.size.width) * 5))))
x -= bounds.size.width * 2
let center = CGPointMake(x, -bounds.size.height)

這篇關于'CGFloat' 不能轉換為 'UInt8' 和 Swift 和 Xcode 6 beta 4 的其他 CGFloat 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
UIImageView zoom and pinch in UIScrollView(UIImageView 在 UIScrollView 中縮放和捏合)
laying out images in UIScrollView automatically(自動在 UIScrollView 中布局圖像)
Make background color change during scroll(在滾動期間更改背景顏色)
主站蜘蛛池模板: 在线国产一区 | 97caoporn国产免费人人 | 一区欧美 | 日韩一区二区三区四区五区 | 成人午夜毛片 | 欧美日韩精品一区二区三区蜜桃 | 亚洲国产乱码 | 日韩精品在线一区 | 成人免费在线观看 | 精品国模一区二区三区欧美 | 日韩欧美在线视频一区 | 国产精品久久九九 | 久久成人免费 | 日韩精品成人一区二区三区视频 | 欧美日韩视频网站 | 成人不卡 | 国产亚洲成av人片在线观看桃 | 国产精品色综合 | 日韩高清在线 | 夜夜爽99久久国产综合精品女不卡 | 欧美成人猛片aaaaaaa | 国产精品亚洲片在线播放 | 欧美午夜精品理论片a级按摩 | 国产 欧美 日韩 一区 | 日韩一区二区三区在线观看视频 | 99久久婷婷国产综合精品电影 | 天堂网中文 | 午夜精品一区二区三区免费视频 | 在线中文一区 | 久久久久久久av麻豆果冻 | 精品毛片 | 精品一区二区不卡 | 国产在线精品一区二区 | 国产视频1区 | 日韩精品在线观看一区二区 | 狠狠躁夜夜躁人人爽天天高潮 | 国产午夜在线 | 91一区二区| 国产一区二区三区精品久久久 | 91精品国产色综合久久不卡98 | 久久久免费电影 |