使用Swift5.7,XCode14.0,iOS16.0,
当我试图使一个XCode示例工作时,我在我的MapKit控制台中会收到非常奇怪的错误消息和警告。
这是日志:
2022-11-01 17:26:51.756834+0100 myApp[3999:834036] Metal API Validation Enabled
2022-11-01 17:26:52.139973+0100 myApp[3999:834036] [PipelineLibrary] Mapping the pipeline data cache failed, errno 22
2022-11-01 17:26:52.192482+0100 myApp[3999:834036] [core] "Error returned from daemon: Error Domain=com.apple.accounts Code=7 "(null)""
2022-11-01 17:26:53.884031+0100 myApp[3999:834036] [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.
2022-11-01 17:26:53.900265+0100 myApp[3999:834036] [SwiftUI] Publishing changes from within view updates is not allowed, this will cause undefined behavior.在SwiftUI中,发布的变量与绑定结合起来的处理方式似乎发生了变化。
我认为,核心问题是很好地描述了这里。
我假设苹果公司还没有完成他们自己的SwiftUI4行为的转变。
或者我有没有办法让Publishing changes bla bla警告消失??
请参阅下面的“我的整个代码”:
//
// MyView.swift
// myApp
//
import SwiftUI
import MapKit
struct MyView: View {
@State private var showMap = false
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 37.8879948,
longitude: 4.1237047
),
span: MKCoordinateSpan(
latitudeDelta: 0.05,
longitudeDelta: 0.05
)
)
@State private var locations: [Location] = [Location(name: "Test", description: "", latitude: 37.8879948, longitude: 4.1237047)]
@State private var isLoading = false
var body: some View {
Map(coordinateRegion: $region,
annotationItems: locations,
annotationContent: { location in
MapAnnotation(
coordinate: CLLocationCoordinate2D(latitude: location.latitude, longitude: location.longitude)
) {
VStack {
Image("THPin")
.resizable()
.scaledToFit()
.frame(width: 44, height: 44)
ZStack {
Text(location.name)
.padding(5)
.font(.subheadline)
.background(.white.opacity(0.5), in: Capsule())
}
}
}
}
)
}
}发布于 2022-12-03 12:03:19
同样的问题!我发现,如果将MapAnnotation替换为MapMarker,问题就会消失。这个问题很可能发生在图书馆本身。
https://stackoverflow.com/questions/74278985
复制相似问题