var img : CGImageRef
do {
img = try assetImgGenerate.copyCGImageAtTime(time, actualTime: nil)
} catch let error as NSError {
print(error.localizedDescription)
}
let frameImg : UIImage = UIImage(CGImage: img)
return frameImg
私はライン「frameImgましょう」をから取得エラー:偽のCGImageRefオブジェクトをインスタンス化するにはどうすればよいですか?
Variable 'img' used before being initialized
だから私は私が行う括弧の前に「IMG」オブジェクトを初期化する必要があると思います。これを行う最も簡単な方法は何ですか?
AppleドキュメントのCGImageRefオブジェクトのためのシンプルで使いやすいコンストラクタはないようです。
私はこのコードを完全に間違って設計しましたか?
do {
var img = try assetImgGenerate.copyCGImageAtTime(time, actualTime: nil)
let frameImg: UIImage = UIImage(CGImage: img)
return frameImg
} catch {
fatalError(error.localizedDescription)
// it's up to you how to handle error; you can crash the app or return some other CGImageRef
}
メイクは ' – dirkgroten
コンパイラは' img'はケース 'copyCGImageAtTimeに初期化前に使用されることを通知し、オプションをimg'と(' UIImage frameImg'にそれを割り当てるときに)それはそれを使用する前に、適切に設定されたされて確認してください'失敗するでしょう。 – Avt