You are on page 1of 8

Stack Overflow

1. Products
1.
2.

Raza Ahmed

3.
4.
5.
6.
7.
fetching data from firebase not working Simulator crash "Thread 1:
EXC_BAD_ACCESS (code=2, address=0x16e607fe0)"
Ask Question

Asked today

Modified today

Viewed 4 times

my Swift code does not fetch the data from firebase loggin user. in the LoginForiOSApp file he gives
the error "Thread 1: EXC_BAD_ACCESS (code=2, address=0x16e607fe0)" the code from the
LoginForiOSApp file is
"wugfdbhsjcknamnjedwbfuvybdhaklmwdneiubfwywidjnqoxkamXWNODEFUBIWQDNJOKMxnoe
fwuibnjqoksmlnoewfjbiunjokasmnojcwefubicdjosakmcnojvbeirugdjnwcsknojwcksmnovjdsckmlnojb
eiruywdcnjoiwburycdjnoibuwrwudjnosacibuvwdcjnsaocibvuwdcjnsobiwuvdcjnso" <- is niks

import SwiftUI
import Firebase

@mainyour text
struct LoginForiOS: App {
init(){
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
} `

the login fetch code is


`
import SwiftUI
import Firebase
import FirebaseFirestore
import FirebaseStorage

struct LoginView: View {


//MARK: User Details
@State var emailID: String = ""
@State var password: String = ""
//MARK: View Properties
@State var createAccount: Bool = false
@State var showError: Bool = false
@State var errorMessage: String = ""
@State var isLoading: Bool = false
//MARK: User Defaulds
@AppStorage("user_profile_url") var profileURL: URL?
@AppStorage("user_name") var userNameStored: String = ""
@AppStorage("user_UID") var userUID: String = ""
@AppStorage("Log_status") var logStatus: Bool = false
var body: some View {
VStack(spacing: 10){
Text("Lets Sign you in")
.font(.largeTitle.bold())
.hAlign(.leading)

Text("Welcome Back,\nYou have been missed")


.font(.title3)
.hAlign(.leading)

VStack(spacing: 12){
TextField("Email", text: $emailID)
.textContentType(.emailAddress)
.border(1, .gray.opacity(0.5))
.padding(.top,5)

SecureField("Password", text: $password)


.textContentType(.password)
.border(1, .gray.opacity(0.5))

Button("Reset password", action: resetPassword)


.font(.callout)
.fontWeight(.medium)
.tint(.black)
.hAlign(.trailing)

Button (action: loginUser) {


//MARK: Login Button
Text("Sign in")
.foregroundColor(.white)
.hAlign(.center)
.fillView(.black)
}
.padding(.top,10)
.preferredColorScheme(.light)
}

//MARK: Register Button


HStack{
Text("Don't have an account?")
.foregroundColor(.gray)

Button("Register Now"){
createAccount.toggle()
}
.fontWeight(.bold)
.foregroundColor(.black)
}
.font(.callout)
.vhAlign(.bottom)
}
.vhAlign(.top)
.padding(15)
.overlay(content: {
LoadingView(show: $isLoading)
})
//MARK: Register View VIA Sheets
.fullScreenCover(isPresented: $createAccount) {
RegisterView()
}
//MARK: Displaying Alert
.alert(errorMessage, isPresented: $showError, actions: {})
}

func loginUser(){
isLoading = true
closeKeyboard()
Task{
do{
// With the help of Swift Concurrency Auth can be done with Single Line
try await Auth.auth().signIn(withEmail: emailID, password: password)
print("User Found")
try await fetchUser()
}
}
}

//MARK: If User if Found then Fetching User Data From Firestore


func fetchUser()async throws{
guard let userID = Auth.auth().currentUser?.uid else{return}
let user = try await Firestore.firestore().collection("Users").document(userID).getDocument(as: User.self)
//MARK: UI Updating Must Be Run On Main Thread
await MainActor.run(body: {
// Setting UserDefaults data and Changing App's Auth Status
userUID = userID
userNameStored = user.username
profileURL = user.userProfileURL
logStatus = true
})
}

func resetPassword(){
Task{
do{
// With the help of Swift Concurrency Auth can be done with Single Line
try await Auth.auth().sendPasswordReset(withEmail: emailID)
print("Link Sent")
}catch{
}
}
}

//MARK: Displaying Errors VIA Alert


func setError(_ error: Error)async{
//MARK: UI Must be Updated on Main Thread
await MainActor.run(body: {
errorMessage = error.localizedDescription
showError.toggle()
isLoading = false
})
}

struct LoginView_Previews: PreviewProvider {


static var previews: some View {
LoginView()
}
}
}
`

I builded the app and i just have to wait and then he gives the error "Thread 1: EXC_BAD_ACCESS (code=2,
address=0x16e607fe0)"
 ios

 swift

 iphone

 xcode
Share

Edit

Follow

asked 3 mins ago


ZIYAXSERVERS

111 bronze badge

 New contributor

Add a comment

Report this ad

Know someone who can answer? Share a link to this question via email, Twitter,


or Facebook.
Your Answer



















 Links
 

 Images
 

 Styling/Headers
 

 Lists
 

 Blockquotes
 

 Code
 

 HTML
 

 Tables
 Advanced help
 ZIYAXSERVERS is a new contributor. Be nice, and check out our Code of Conduct.

Post Your Answer

Browse other questions tagged 

 ios

 swift

 iphone

 xcode
 or ask your own question.
 The Overflow Blog
 CEO update: Eliminating obstacles to productivity, efficiency, and learning
 Announcing more ways to learn and grow your skills
 Featured on Meta
 Accessibility Update: Colors
 2022: a year in moderation
 Collectives: The next iteration
 Temporary policy: ChatGPT is banned
 We’re bringing advertisements for technology courses to Stack Overflow
Related

Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x30000008) issue generated

11

Thread 1 : EXC_BAD_ACCESS (Code = 1, address = 0x30000008)

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7fff59d8dff8)

Swift xcode error: Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ff54b59ff8)

Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffeeaa26f48)


0

Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)

12

React Native App Crash (Thread 1: EXC_BAD_ACCESS (code=1, address=0x54))

Thread 1: EXC_BAD_ACCESS (code=2, address=0x1134ca968)

Xcode 12.2 Crash. Thread 1: EXC_BAD_ACCESS (code=1, address=0x7e4)

Hot Network Questions


 Is a t-test suitable to compare the difference between the mean z-scores of two groups
 Why is the Bitcoin Core HWI written in Python? If it was rewritten in Rust should the Python HWI still be maintained?
 Did Shimano change the design of SPD cleats?
 Attempt to locate buried sewer line with melted snow?
 Can I get a travel insurance policy which is valid for NON-MEDICAL claims, despite undeclared medical conditions?
 Planetary simulation in python
 Elementary operations on list of points
more hot questions

 Question feed

STACK OVERFLOW
 Questions
 Help
PRODUCTS
 Teams
 Advertising
 Collectives
 Talent
COMPANY
 About
 Press
 Work Here
 Legal
 Privacy Policy
 Terms of Service
 Contact Us
 Cookie Settings
 Cookie Policy
STACK EXCHANGE NETWORK
 Technology
 Culture & recreation
 Life & arts
 Science
 Professional
 Business
 API
 Data
 Blog
 Facebook
 Twitter
 LinkedIn
 Instagram
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. rev 2023.1.31.43211
Your privacy

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance
with our Cookie Policy.

You might also like