尝试将import Foundation
struct YourClass: Codable {
let format, formatVersion, status: String
let numToReturn: Int
let allResults: [AllResult]
enum CodingKeys: String, CodingKey {
case format = "Format"
case formatVersion = "FormatVersion"
case status = "Status"
case numToReturn = "NumToReturn"
case allResults = "AllResults"
}
}
struct AllResult: Codable {
let conversationState: ConversationState
enum CodingKeys: String, CodingKey {
case conversationState = "ConversationState"
}
}
struct ConversationState: Codable {
let conversationStateTime: String
let queryEntities: QueryEntities
enum CodingKeys: String, CodingKey {
case conversationStateTime = "ConversationStateTime"
case queryEntities = "QueryEntities"
}
}
struct QueryEntities: Codable {
let queryEntitiesWhere: [Where]
enum CodingKeys: String, CodingKey {
case queryEntitiesWhere = "Where"
}
}
struct Where: Codable {
let type, label, spokenLabel, address: String
let city, admin2, admin1, country: String
let countryCode, iata, geohash: String
let verified, highConfidence, currentLocation: Bool
let latitude, longitude: Double
let referenceDatum, timeZone: String
let radius: Int
let links: [Link]
let typeID, sourceID, recordID: Int
enum CodingKeys: String, CodingKey {
case type = "Type"
case label = "Label"
case spokenLabel = "SpokenLabel"
case address = "Address"
case city = "City"
case admin2 = "Admin2"
case admin1 = "Admin1"
case country = "Country"
case countryCode = "CountryCode"
case iata = "IATA"
case geohash = "Geohash"
case verified = "Verified"
case highConfidence = "HighConfidence"
case currentLocation = "CurrentLocation"
case latitude = "Latitude"
case longitude = "Longitude"
case referenceDatum = "ReferenceDatum"
case timeZone = "TimeZone"
case radius = "Radius"
case links = "Links"
case typeID = "TypeID"
case sourceID = "SourceID"
case recordID = "RecordID"
}
}
struct Link: Codable {
let label: String
let url: String
enum CodingKeys: String, CodingKey {
case label = "Label"
case url = "URL"
}
}
插入createSwitchNavigator()
时收到此错误消息。
createAppContainer()
我的代码-router.js
TypeError: Cannot call a class as a function
index.js
export const RootNavigator = (signedIn = false) => {
return createSwitchNavigator(
{
SignedIn: {
screen: SignedIn
},
SignedOut: {
screen: SignedOut
}
},
{
initialRouteName: signedIn ? "SignedIn" : "SignedOut"
}
);
};
export const createRootNavigator = createAppContainer(RootNavigator());
答案 0 :(得分:2)
您正尝试将函数返回到createAppContainer
,但是它需要create*Navigator
将其用作
export const RootNavigator = createSwitchNavigator(
{
SignedIn: {
screen: SignedIn
},
SignedOut: {
screen: SignedOut
}
},
{
initialRouteName: signedIn ? "SignedIn" : "SignedOut"
}
)
或
export const createRootNavigator = createAppContainer(RootNavigator());
用于调用createRootNavigator
作为方法
export function createRootNavigator (signedIn) {
return createAppContainer(RootNavigator(signedIn));
}
index.js
const Layout = createRootNavigator(signedIn);