Post

Replies

Boosts

Views

Activity

Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT) whenever I try to make a network request
I have been getting a weird crash whenever I run my app and use my request utilities. Here is the code: Firstly, I have a button that submits the data when clicked Button(action: { Task { await viewModel.submitData() } } ) {      Text("Log In") } This is the submitData function func submitData() async -> Void {     state = .loading           do {       let result = try await AuthenticationAPI.login(user: user)               self.state = .success       self.authenticator.authenticate(token: result.value.token)     } catch let error as APIError {       self.handleAPIError(error)     } catch {       // TODO: Log Error       self.handleAPIError(.unexpectedError)     }   } This is the AuthenticationAPI.login function    static func login(user: LoginUser) async throws -> APIService.Response<AuthenticatedUser> {     let endpoint = Endpoint.login           let data = try? encode(user.toDictionary())           return try await apiService.post(type: AuthenticatedUser.self,                 url: endpoint.url, body: data)   } Lastly this is the network call   func executeRequest<T: Decodable>(_ request: URLRequest) async throws -> Response<T> {     guard let (data, response) = try? await URLSession.shared.data(for: request) else {         throw APIError.networkError     }           if let response = response as? HTTPURLResponse {       if (200...299).contains(response.statusCode) {         guard let data = try? decoder.decode(T.self, from: data) else {           throw APIError.decodingError         }                   return Response(value: data, response: response)       } else if (400...499).contains(response.statusCode) {         throw APIError.httpError(data, response)       } else if response.statusCode == 500 {         throw APIError.serverError       }     }           throw APIError.unexpectedError   }   func post<T: Decodable>(     type: T.Type,     url: URL,     headers: Headers = [:],     body: Data?   ) async throws -> Response<T> {     var request = URLRequest(url: url)           request.httpMethod = "POST"     request.httpBody = body           constructHeaders(request: &request, headers: headers)           return try await executeRequest(request) // This is where the compiler tells me the error occurs       } The executeRequest function is never called because it never makes the request (I checked my local server). These are the thread logs: Thread 1 Queue : com.apple.main-thread (serial) #0 0x00007fff30bb03f4 in swift::TargetMetadata<swift::InProcess>::isCanonicalStaticallySpecializedGenericMetadata() const () #1 0x00007fff30bbc7b1 in swift_checkMetadataState () #2 0x00007fff30b713d5 in type metadata completion function for ClosedRange<>.Index () #3 0x00007fff30bbf75d in swift::MetadataCacheEntryBase<(anonymous namespace)::GenericCacheEntry, void const*>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) () #4 0x00007fff30bb1941 in _swift_getGenericMetadata(swift::MetadataRequest, void const* const*, swift::TargetTypeContextDescriptor<swift::InProcess> const*) () #5 0x00007fff30b8b440 in __swift_instantiateCanonicalPrespecializedGenericMetadata () #6 0x00000001017f9e00 in APIService.post<τ_0_0>(type:url:headers:body:) at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/Services/APIService.swift:124 #7 0x00000001017a0dd0 in static AuthenticationAPI.login(user:) at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/Networking/Authentication/AuthenticationAPI.swift:21 #8 0x000000010170b3c0 in LoginViewModel.submitData() at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/App/Login/ViewModels/LoginViewModel.swift:42 #9 0x00000001016317d0 in closure #1 in closure #1 in closure #2 in closure #1 in closure #1 in LoginView.body.getter at /Users/jayaikendu/Documents/projects/Xcode - Swift/squizelstudents/Shared/App/Login/Views/LoginView.swift:26 #10 0x0000000101637960 in partial apply for closure #1 in closure #1 in closure #2 in closure #1 in closure #1 in LoginView.body.getter () #11 0x0000000101631ae0 in thunk for @escaping @callee_guaranteed @Sendable @async () -> () () #12 0x0000000101637ac0 in partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> () () #13 0x00000001016353f0 in thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out τ_0_0) () #14 0x0000000101637d70 in partial apply for thunk for @escaping @callee_guaranteed @Sendable @async () -> (@out τ_0_0) () This is on XCode Beta 13.5 I should mention that I am using the Thread Sanitizer too. This error only appears with the Thread Sanitizer turned on.
5
0
3k
Sep ’21
SwiftUI Date Picker is Problematic
I am using the swiftUI DatePicker like so: swift DatePicker("Start Date", selection: $profile.goalDate, in: dateRange, displayedComponents: [.date]) Basically, following the tutorial on the apple website. However, the DatePicker echoes out this error in the console: [DatePicker] UIDatePicker 0x7fe42bc36e90 is being laid out below its minimum width of 280. This may not look like expected, especially with larger than normal font sizes. And when I select certain dates, the picker format changes abruptly. So, the start date might be "Mar 2, 2021". Then, when I use the picker to select let's say 31st March, the portion showing the selected date moves to the right, and the format changes to "31/3/21". This is not how it is supposed to behave Initial Behavior (Expected) imgur.com/GI38I7A Behavior after selecting a date (Unexpected) imgur.com/vuZjhaj
4
1
7.0k
Sep ’21