我正在将视频文件上传到Firebase Storage,并且正在使用进度指示器显示进度。一切正常,除了我无法显示Int
(整数),它显示Doubles
,如:
数字应为整数,例如0%, 33%, and 96%
我尝试将casting
类型的percentLabel Double
改成Int
,但它一直崩溃:
let percentComplete: Double = 100.0 * Double(completedUnitCount) / Double(totalUnitCount)
self?.progressLabel.text = "\(Int(percentComplete))%"
如何使这些双打成为Int?
var uploadTask: StorageUploadTask?
uploadTask = videoIdRef?.putFile(from: videoUrl)
uploadTask?.observe(.progress, handler: {
[weak self] (snapshot) in
if let completedUnitCount = snapshot.progress?.completedUnitCount, let totalUnitCount =
snapshot.progress?.totalUnitCount {
let uploadProgress:Float = Float(completedUnitCount) / Float(totalUnitCount)
self?.progressView.progress = uploadProgress
let percentComplete = 100.0 * Double(completedUnitCount) / Double(totalUnitCount)
self?.progressLabel.text = "\(percentComplete)%"
}
})
答案 0 :(得分:1)
您可以为此使用简单的String初始化器
@PostMapping
public @ResponseBody CurriculumVitaeViewModel addCurriculumVitae(@RequestBody SaveCurriculumVitaeRequest model){
CurriculumVitae newCv = new CurriculumVitae();
curriculumVitaeModelMapper.Map(model, newCv);
for (EducationViewModel ed:model.getEducations()
) {
Education newEd = new Education();
educationModelMapper.Map(ed, newEd);
newCv.addEducation(newEd);
}
CurriculumVitae savedCv = curriculumVitaeRepository.save(newCv);