错误已解决。事实证明,我的json文件中存在不匹配的记录,导致应用崩溃...
我正在以新的SwiftUI格式构建应用程序。但是在代码旁边的预览中,该应用程序将无法启动,我也不知道自己做错了什么。
我收到以下错误消息: “无法在此文件中预览-Antwan van Enk.app在启动时崩溃”
现在我有一个崩溃日志,但是我不知道它是如何工作的。 在哪里可以找到错误?
我试图删除我添加的最后一些代码,以使再次工作。但事实并非如此。
这是崩溃日志:
Process: routined [23493]
Path: /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/routined
Identifier: routined
Version: 663.0.3
Code Type: X86-64 (Native)
Parent Process: launchd_sim [5183]
Responsible: routined [23493]
User ID: 501
Date/Time: 2019-06-16 13:47:57.284 +0200
OS Version: Mac OS X 10.15 (19A471t)
Report Version: 12
Anonymous UUID: 2DC21AAC-7550-3CAC-BCCB-BFAE7451643B
Sleep/Wake UUID: 99E439A9-2515-4382-AA42-56F4D922C6D1
Time Awake Since Boot: 50000 seconds
Time Since Wake: 7200 seconds
System Integrity Protection: enabled
Crashed Thread: 8 Dispatch queue: RTAssetManager-0x7f988151e470
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSFileManager copyItemAtPath:toPath:options:error:]: destination path is nil'
terminating with uncaught exception of type NSException
abort() called
CoreSimulator 643.8.4 - Device: iPhone X (7EA9E6A6-C176-4104-B63B-608199A3ED74) - Runtime: iOS 13.0 (17A5492t) - DeviceType: iPhone X
这些是我的文件: Image of files
我将列出添加新代码的文件的代码,直到出现此错误为止。
Launcher.swift:
import SwiftUI
struct Launcher : View {
var body: some View {
TabbedView() {
CategoryHome().tabItemLabel(
//Image(systemName: "star")
Text("Home")
).tag(1)
Badges().tabItemLabel(
//Image(systemName: "star")
Text("Badges")
).tag(2)
AppInfo().tabItemLabel(
//Image(systemName: "star")
Text("Info")
).tag(3)
}.edgesIgnoringSafeArea(.top)
}
}
#if DEBUG
struct Launcher_Previews : PreviewProvider {
static var previews: some View {
Launcher()//.previewLayout(.fixed(width: 500, height: 1000))
}
}
#endif
Badges.swift:
import SwiftUI
struct Badges : View {
@EnvironmentObject var userData: UserData
var body: some View {
NavigationView {
List {
ForEach(userData.applestore) { applestore in
if applestore.gotBadge == true {
Badge(applestore: applestore)
.scaleEffect(2)
}
}
.padding()
}
.navigationBarTitle(Text("Badges"))
}
}
}
#if DEBUG
struct Badges_Previews : PreviewProvider {
static var previews: some View {
Badges()
}
}
#endif
Badge.swift:
import SwiftUI
struct Badge : View {
var applestore: AppleStore
var body: some View {
VStack {
Image(applestore.badgeUrl)
.resizable()
.frame(width: 100, height: 100)
.cornerRadius(12)
Text(applestore.store)
}
}
}
#if DEBUG
struct SwiftUIView_Previews : PreviewProvider {
static var previews: some View {
Badge(applestore: applestoreData[0])
}
}
#endif
applestoreData.json:
[
{
"name": "Apple Park",
"category": "Special",
"city": "Cupertino",
"state": "San Jose",
"id": 1,
"isFeatured": true,
"isFavorite": true,
"store": "Apple Park",
"coordinates": {
"longitude": -122.010980,
"latitude": 37.332280
},
"imageName": "applepark",
"badgeUrl": "applepark_b",
"gotBadge": false
},
{
"name": "Apple Park Visitor Center",
"category": "Special",
"city": "Cupertino",
"state": "San Jose",
"id": 2,
"isFeatured": true,
"isFavorite": true,
"store": "Apple Park Visitor Center",
"coordinates": {
"longitude": -122.005386,
"latitude": 37.332829
},
"imageName": "appleparkvisitor",
"badgeUrl": "appleparkvisitor_b",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Amsterdam",
"state": "The Netherlands",
"id": 3,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Amsterdam",
"coordinates": {
"longitude": 4.882420,
"latitude": 52.363548
},
"imageName": "amsterdam",
"badgeUrl": "amsterdam_b",
"gotBadge": true
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Haarlem",
"state": "The Netherlands",
"id": 4,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Haarlem",
"coordinates": {
"longitude": 4.632720,
"latitude": 52.378510
},
"imageName": "haarlem",
"badgeUrl": "haarlem_b",
"gotBadge": true
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Den Haag",
"state": "The Netherlands",
"id": 5,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Den Haag",
"coordinates": {
"longitude": 4.311350,
"latitude": 52.077980
},
"imageName": "denhaag",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Aberdeen",
"state": "United Kingdom",
"id": 6,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Union Square",
"coordinates": {
"longitude": -2.096531,
"latitude": 57.143113
},
"imageName": "aberdeen",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Basingstoke",
"state": "United Kingdom",
"id": 7,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Festival Place",
"coordinates": {
"longitude": -1.086198,
"latitude": 51.262826
},
"imageName": "basingstoke",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Bath",
"state": "United Kingdom",
"id": 8,
"isFeatured": false,
"isFavorite": false,
"store": "Apple SouthGate",
"coordinates": {
"longitude": -2.359696,
"latitude": 51.381386
},
"imageName": "bath",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Belfast",
"state": "United Kingdom",
"id": 9,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Victoria Square",
"coordinates": {
"longitude": -5.930276,
"latitude": 54.596441
},
"imageName": "belfast",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Birmingham",
"state": "United Kingdom",
"id": 10,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Birmingham",
"coordinates": {
"longitude": -1.902691,
"latitude": 52.479699
},
"imageName": "birmingham",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Brighton",
"state": "United Kingdom",
"id": 11,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Churchill Square",
"coordinates": {
"longitude": -0.137406,
"latitude": 50.822040
},
"imageName": "brighton",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Bristol",
"state": "United Kingdom",
"id": 12,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Cabot Circus",
"coordinates": {
"longitude": -2.597299,
"latitude": 51.453802
},
"imageName": "bristol",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Bristol",
"state": "United Kingdom",
"id": 13,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Cribbs Causeway",
"coordinates": {
"longitude": -2.597299,
"latitude": 51.453802
},
"imageName": "bristol2",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Bromley",
"state": "United Kingdom",
"id": 14,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Bromley",
"coordinates": {
"longitude": 0.061709,
"latitude": 37.332280
},
"imageName": "bromley",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Cambridge",
"state": "United Kingdom",
"id": 15,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Grand Arcade",
"coordinates": {
"longitude": 0.123582,
"latitude": 52.203482
},
"imageName": "cambridge",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Cardiff",
"state": "United Kingdom,
"id": 16,
"isFeatured": false,
"isFavorite": false,
"store": "Apple St David's 2",
"coordinates": {
"longitude": -3.179193,
"latitude": 51.481655
},
"imageName": "cardiff",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Edinburgh",
"state": "United Kingdom",
"id": 17,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Princes Street",
"coordinates": {
"longitude": -3.188991,
"latitude": 55.952148
},
"imageName": "edinburgh",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Exeter",
"state": "United Kingdom",
"id": 18,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Princesshay",
"coordinates": {
"longitude": -3.526911,
"latitude": 50.725562
},
"imageName": "exeter",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Gateshead",
"state": "United Kingdom",
"id": 19,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Metrocentre",
"coordinates": {
"longitude": -1.605700,
"latitude": 54.958554
},
"imageName": "gateshead",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Glasgow",
"state": "United Kingdom",
"id": 20,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Braehead",
"coordinates": {
"longitude": -4.297989,
"latitude": 55.869128
},
"imageName": "glasgow",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Glasgow",
"state": "United Kingdom",
"id": 21,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Buchanan Street",
"coordinates": {
"longitude": -4.250167,
"latitude": 55.861139
},
"imageName": "glasgow2",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Grays",
"state": "United Kingdom",
"id": 22,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Lakeside",
"coordinates": {
"longitude": 0.323313,
"latitude": 51.478090
},
"imageName": "grays",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Greenhithe",
"state": "United Kingdom",
"id": 23,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Bluewater",
"coordinates": {
"longitude": 0.281763,
"latitude": 51.450745
},
"imageName": "greenhithe",
"badgeUrl": "",
"gotBadge": false
},
{
"name": "Apple Store",
"category": "Stores",
"city": "Kingston upon Thames",
"state": "United Kingdom",
"id": 24,
"isFeatured": false,
"isFavorite": false,
"store": "Apple Bentall Centre",
"coordinates": {
"longitude": -0.276987,
"latitude": 51.381776
},
"imageName": "kingston",
"badgeUrl": "",
"gotBadge": false
},
]
AppleStore.swift:
import SwiftUI
import CoreLocation
struct AppleStore: Hashable, Codable, Identifiable {
var id: Int
var name: String
fileprivate var imageName: String
fileprivate var coordinates: Coordinates
var city: String
var state: String
var store: String
var category: Category
var isFavorite: Bool
var isFeatured: Bool
var gotBadge: Bool
var badgeUrl: String
var locationCoordinate: CLLocationCoordinate2D {
CLLocationCoordinate2D(
latitude: coordinates.latitude,
longitude: coordinates.longitude)
}
var featureImage: Image? {
guard isFeatured else { return nil }
return Image(
ImageStore.loadImage(name: "\(imageName)_feature"),
scale: 2,
label: Text(verbatim: name))
}
func image(forSize size: Int) -> Image {
ImageStore.shared.image(name: imageName, size: size)
}
enum Category: String, CaseIterable, Codable, Hashable {
case stores = "Stores"
case special = "Special"
}
}
struct Coordinates: Hashable, Codable {
var latitude: Double
var longitude: Double
}
希望有人现在可以帮助我。如果有人需要查看文件的其他代码,请告诉我。