我想显示图库中的图像。我正在使用 imagePicker 加载图像。
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
guard let image = info[.originalImage] as? UIImage else { return }
if let imgUrl = info[UIImagePickerController.InfoKey.imageURL] as? URL{
self.photoEntity = createPhotoEntity(fileUrl: imgUrl, fileName: imgName)
}
dismiss(animated: true)
}
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个像这样的 modelEntity 。
private func createPhotoEntity(fileUrl: URL, fileName: String) -> ModelEntity? {
// Create a TextureResource by loading the contents of the file URL.
do {
let texture = try TextureResource.load(contentsOf: fileUrl)
let planeMesh = MeshResource.generatePlane(width: 0.5, depth: 0.5) …Run Code Online (Sandbox Code Playgroud) 我在操场上玩了一段时间的计时器发布者。下面是我的代码
let timer = Timer
.publish(every: 1.0, on: .main, in: .common)
.autoconnect()
var counter = 0
let subscriber = timer
.map({ (date) -> Void in
counter += 1
})
.sink { _ in
print("I am printing the counter \(counter)")
}
if counter > 5 {
timer.upstream.connect().cancel() //1.nothing happened
subscriber.cancel() //2. nothing happened too. :(
}
Run Code Online (Sandbox Code Playgroud)
但是我无法通过使用第 1 行和第 2 行来停止计时器。我实际上错过了什么?