Value of type 'Error' has no member 'code'
Figured the answer out on my own minutes later. Xcode decided to give me a did you mean
suggestion and .code
is now ._code
.
swift error: Value of type _ has no member _
You are trying to assign the subscript values from an array object without specifying the index.
Try this:
class ViewController: UIViewController {
@IBOutlet weak var prizeLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var timeLabel: UILabel!
@IBOutlet weak var categoryLabel: UILabel!
@IBOutlet weak var ContentLabel: UILabel!
@IBOutlet weak var TopicLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
if let url = URL(string: "http://{Local-Host}/post") {
URLSession.shared.dataTask(with: url) { data, response, error in
if let data = data {
do {
let parsedJSON = try JSONDecoder().decode(parsingss.self, from: data)
print(parsedJSON)
DispatchQueue.main.async {
self.TopicLabel.text = parsedJSON.scrims[0].topic
self.ContentLabel.text = parsedJSON.scrims[0].content
self.categoryLabel.text = parsedJSON.scrims[0].category
self.timeLabel.text = parsedJSON.scrims[0].time
self.priceLabel.text = parsedJSON.scrims[0].price
self.prizeLabel.text = parsedJSON.scrims[0].prize
}
}
catch {
print(error)
}
}
}.resume()
}
}
}
Value of type User has no member 'logStatus Swift Error
You should take logStatus() out of your initializer
struct SomeStruct {
let name: String
var email: String
var followers: Int
var isActive: Bool
init(name: String, email: String, followers: Int, isActive:Bool) {
self.name = name
self.email = email
self.followers = followers
self.isActive = isActive
}
func logStatus() {
if (isActive) {
print("\(name) is working hard" )
} else {
print("\(name) has left Earth")
}
}
}
keep getting error 'value of type ' ' has no member ' '
Well I did not check logic, but below fixed code at least compilable, so hope it will be helpful
import SwiftUI
import Combine
class Setting: ObservableObject {
@Published var playerChoice : Int = 0
var questionCount : Int = 0
@Published var questionCountArray = [String]()
var pcRandom : Int = 0
var correctAnswer = 0
var question : String = ""
var buttonArray = [Int]()
@Published var enteredAnswer = ""
var gameRound : Int = 0
var scoreCount : Int = 0
var title2 = ""
var alertTitle = ""
var alertMessage = ""
@Published var alertEndGame = false
func refreshGame() {
pcRandom = Int.random(in: 1 ... 12)
correctAnswer = playerChoice * pcRandom
question = "\(playerChoice) times \(pcRandom) is??"
}
func compareAnswer() {
let answerModified = enteredAnswer
let answerModified2 = answerModified.trimmingCharacters(in: .whitespacesAndNewlines)
if Int(answerModified2) == correctAnswer {
scoreCount += 1
title2 = "RIGHT"
}
else {
title2 = "WRONG"
}
if gameRound > questionCount {
alertTitle = "Game Ended"
alertMessage = "You got \(scoreCount) over \(questionCount)"
alertEndGame = true
}
else {
refreshGame()
}
gameRound += 1
gameRound += 1
}
}
struct ASFContentView: View {
@ObservedObject var settings = Setting()
var body: some View {
VStack {
Section (header: Text("Getting Your Settings Righttt").font(.title)) {
Form {
Stepper(value: $settings.playerChoice, in: 1...13, step: 1) { //value of type 'setting' ha no member '$playerChoice'
if settings.playerChoice == 13 {Text("All")}
else {
Text("Multiplication table \(settings.playerChoice)")
}
}
}
Form {
Text("Number of Questions?")
Picker(selection: $settings.questionCount, label: Text("Number of Questions?")) { //value of type 'setting' has no member '$questionCount'
ForEach (settings.questionCountArray, id: \.self) {Text("\($0)")} } ////value of type 'setting' ha no member '$questionCountArray'
.pickerStyle(SegmentedPickerStyle())
}
Spacer()
Button("Tap to start") {
self.settings.refreshGame()
}
}
Section (header: Text("Game Play").font(.title)){
Text(settings.question)
TextField("Enter your answer", text: $settings.enteredAnswer, onCommit: settings.compareAnswer) //value of type 'setting' ha no member '$enteredAnswer'
Text("Your score is currently \(settings.scoreCount)")
Text("This is game round \(settings.gameRound) out of \(settings.questionCount)")
}
Spacer()
}
.alert(isPresented: $settings.alertEndGame) {
Alert(title: Text("Game Ended"), message: Text("You reached score \(settings.scoreCount) out of \(settings.questionCount)"), dismissButton: .default(Text("Play Again"))) //game doesnt restart and refresh
}
}
}
Value of type 'UITableView' has no member 'sectionHeaderTopPadding'
You can make a condition for compilation
#if compiler(>=5.5)
if #available(iOS 15.0, *) {
myTableView.sectionHeaderTopPadding = 0.0
}
#endif
SwiftUI - Firebase: Value of type 'String' has no member 'documentID'
Let me take the first part of your code to show where the issue is. Note how much easier it is to read when properly formatted
func checkUser() {
let ref = Firestore.firestore()
if let currentUser = Auth.auth().currentUser {
//NOTE! Note that this area is encapsulated with brackets { and }
//That means it's is own 'space' and anything defined in this area
//only exists in this area
let uid = currentUser.uid //<- uid only exists here
} else {
print("No Authenticated User")
return
}
//uid no longer exists and cannot be referenced
// e.g. it's not in 'scope' at this point
ref.collection("Users").whereField("uid", isEqualTo: uid)
However, if you look at where the let ref = Firestore
line is located, it's at the top level within the checkUser function and will exist throughout the function.
There are many way to do this; here's one using a guard
statement
func checkUser() {
let ref = Firestore.firestore()
guard let currentUser = Auth.auth().currentUser else {
print("no user!")
return
}
// currentUser flows through to here because it was created with
// a guard statement, so now we know it's populated and can
// get the uid property value from it
let uid = currentUser.uid
ref.collection("Users").whereField("uid", isEqualTo: uid)
guard
is pretty neat in that it not only allows you to instantiate a var while a the same time as protecting your code from a nil situation, it also allows the var to flow through to the code following the guard.
SwiftUI value of type [x] has no member [y], but the struct has the member
You can't do remedydata?.remedy.content.screens.elements
since remedydata?.remedy.content.screens
is an Array. In the question, you have multiple Element
inside multiple Screen
, which means you have two options:
- Display each
Element
for a specificScreen
. - Display a specific
Element
for eachScreen
.
To "Display each Element
for a specific Screen
":
ForEach(remedydata?.remedy.content.screens.first?.elements ?? []) { element in
Text(element.text)
}
To "Display a specific Element
for each Screen
":
ForEach(remedydata?.remedy.content.screens ?? []) { screen in
Text(screen.elements.first?.text ?? "")
}
Related Topics
How to Create a Pfquerytableviewcontroller with Parse in Swift
Masked Uivisualeffectview Does Not Work on iOS 10
Receipt Validation on iOS In-App-Purchase Returns Multiple Transaction
App Crashes When User Starts Typing in Uisearchbar
How Is This Slide-Up Menu from the iPhone Messages App Implemented
How to Change the Font Size of a Uilabel in Swift
Cannot Set Color of Button's Label Inside Menu in Swiftui
How to Get the Nondecoded Attributes from a Decoder Container in Swift 4
Errortype' Is Not Convertible to 'Nserror'
Wake Up Application in Background Using Audiosession Like Alarmy iOS App
Swift Continuous Rotation Animation Not So Continuous
Validate Jwt Token with Rs256 or Rs512 with Swift iOS
Xcode6/Swift: Unrecognized Selector Sent to Instance
Present Specific View Controller in Didreceiveremotenotification with Swift