前提・実現したいこと
トップ画面で画像をランダムで表示させたいのですが、エラーが出てしまいます。
発生している問題・エラーメッセージ
エラーメッセージ ```Cannot invoke initializer for type 'Int' with an argument list of type'(0 ->UInt32)' ### 該当のソースコード ```swift3 import UIKit class ViewController: UIViewController { var img01 :UIImage = UIImage(named:"IMG_0001")! var img02 :UIImage = UIImage(named:"IMG_0002")! var img03 :UIImage = UIImage(named:"IMG_0003")! var imgArray:[UIImage] = [] @IBOutlet weak var backimage: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func poi(){ imgArray = [img01,img02,img03] let ret = Int{arc4random_uniform(3)} backimage.image = imgArray[ret] } }
試したこと
Intに問題があるのかなと思って
let ret = arc4random_uniform(3)
にしてみると今度は一番下の行がエラーを起こしてこちらにもUInt32と書いてあったのですが、そもそもこのUInt32というのを入力していないので直し方がわかりません。
補足情報(FW/ツールのバージョンなど)
xcode8.2
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/03/03 07:24