Swift Playgrounds(iPad)不使用实现的ArsessionDelegate.Session(_:didupdate :)函数构建应用程序
我在尝试实现arview
的SwiftUI表示时发现了一个错误/resealykit/building_an_immersive_experience_with_realitykit“ rel =“ nofollow noreferrer”>“使用RealityKit建立沉浸式体验” 。
有错误
方法'__preview__ sessession(_:didupdate :)'objective-c selector'__preview__sessess:didupdate:'与以前的声明与同一objective-c Selector
发生冲突
我准备了以下样本以轻松重现此样本。
import ARKit
import RealityKit
import SwiftUI
struct ContentView: View {
var body: some View {
RealityKitView()
}
}
private struct RealityKitView: UIViewRepresentable {
class Coordinator: NSObject, ARSessionDelegate {
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) { }
func session(_ session: ARSession, didUpdate frame: ARFrame) { }
}
func makeCoordinator() -> Coordinator { Coordinator() }
func makeUIView(context: Context) -> ARView {
let view = ARView()
let session = view.session
let config = ARWorldTrackingConfiguration()
config.planeDetection = [.horizontal]
session.run(config)
session.delegate = context.coordinator
return view
}
func updateUIView(_ view: A. RView, context: Context) { }
}
一个非常有趣的时刻是,上面的代码可以通过一般的Swift Playgrounds的操场或Xcode成功构建,而不是在Swift Playgrounds的应用程序中。
I found an error while trying to implement a SwiftUI representation of ARView
with ARSessionDelegate
based on Apple’s official example “Building an immersive experience with RealityKit”.
There is the error
Method '__preview__session(_:didUpdate:)' with Objective-C selector '__preview__session:didUpdate:' conflicts with previous declaration with the same Objective-C selector
I prepared the following sample to easily reproduce this.
import ARKit
import RealityKit
import SwiftUI
struct ContentView: View {
var body: some View {
RealityKitView()
}
}
private struct RealityKitView: UIViewRepresentable {
class Coordinator: NSObject, ARSessionDelegate {
func session(_ session: ARSession, didUpdate anchors: [ARAnchor]) { }
func session(_ session: ARSession, didUpdate frame: ARFrame) { }
}
func makeCoordinator() -> Coordinator { Coordinator() }
func makeUIView(context: Context) -> ARView {
let view = ARView()
let session = view.session
let config = ARWorldTrackingConfiguration()
config.planeDetection = [.horizontal]
session.run(config)
session.delegate = context.coordinator
return view
}
func updateUIView(_ view: A. RView, context: Context) { }
}
A quite interesting moment is that this code above can be successfully built with a general Swift Playgrounds’ playground or Xcode but not within Swift Playgrounds' app. ????
Are there any workarounds?
Also, found another weird error 'Scene' is ambiguous for type lookup in this context
from the same Apple’s Underwater example (FoodPool.swift
). I simplified the content to clarify where the problem is, however, there is nothing wrong with this code.
import RealityKit
class FoodPool {
private let arView: ARView
private var scene: Scene { arView.scene } // Error: 'Scene' is ambiguous for type lookup in this context
init(arView: ARView) {
self.arView = arView
}
}
Apart from the ARSessionDelegate
problem this one can be resolved with using arView.scene
directly (removed line 5 will help).
Overall, seems like there is hidden much more complicated problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方法
给定一个具有 fake 的文件:d错误,而计划的更改则在文件中完成,选择另一个有效的文件,然后项目重新加载(或重述了Swift操场),然后,如果没有其他错误,则可以成功地运行该项目。
这帮助我解决了
arsessionDelegate
问题,并且运行在iPad上。Workaround
Given a file with a fake :D error, and planned changes are done in the file, when another valid file is chosen, and the project is reloaded (or Swift Playgrounds is restated), then the project could be run successfully straight away if there are no other errors.
This helped me with the
ARSessionDelegate
problem and running the Underwater example on iPad.