투케이2K

234. (TWOK/ERROR) [Ios] async call in a function that does not support concurrency 본문

투케이2K 에러관리

234. (TWOK/ERROR) [Ios] async call in a function that does not support concurrency

투케이2K 2024. 4. 19. 10:06
반응형

[환경 설정 및 설명]

프로그램 : Xcode

설 명 : [Ios] async call in a function that does not support concurrency

 

[에러 원인]

1. 비동기 콘텐츠가 아닌 곳에서 await 함수를 호출해서 발생하는 이슈

 

[해결 방법]

1. Task 블럭 내에서 await 함수를 호출 하도록 변경

2. 예시 :

 

    func testMain() {
        
        
        // [로직 처리 실시]
        Task {
            
            do {
                // [HTTP 요청 주소 정의]
                let url = "https://jsonplaceholder.typicode.com/posts?userId=1&id=1"
                
                
                // [OkHttpClient 생성]
                let client = OkHttpClient()
                
                
                // [URL 및 Request 정의]
                let urls = URL(string: url)
                let requests = URLRequest(url: urls!)
                
                
                // [HTTP 요청 수행 및 리턴 확인]
                let result: [jsonStruct] = try await client.execute(request: requests)
            }
            catch {
                S_Log._D_(description: S_FinalMsg.LOG_BUG_STATE, data: [
                    "catch :: \(error.localizedDescription)"
                ])
            }

        }

    }

 

반응형
Comments