작성
·
6
0
iOS26 환경에서 코드 작성하면 아래와 같이 warning이 발생합니다.
동작상에는 문제가 없지만, 동일하게 다른 파일에서도 사용되는 함수 인데 왜 발생되는 건지 이해가 안됩니다.
확인 부탁드립니다.
<ProfileEditingView>
28,29라인에 KFImage(url)에서 발생됩니다.
"import Kingfisher"도 정의 되어있고, 다른 파일에서 "KFImage()"함수에서는 warning이 발생되지 않습니다. 혹시 Kingfisher 패키지 버전때문일까요? 강제로 10.4.xx으로 하긴 했지만, 몇몇 하위 패키지는 업데이트 된것 같습니다.
warning 내용>
Call to main actor-isolated initializer 'init(_:)' in a synchronous nonisolated context
package 버전정보>
{
"originHash" : "dacfd17cdf8fa9f962991925a9162eb62e278dab4974c56cd997ab2b87892aa5",
"pins" : [
{
"identity" : "abseil-cpp-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/abseil-cpp-binary.git",
"state" : {
"revision" : "194a6706acbd25e4ef639bcaddea16e8758a3e27",
"version" : "1.2024011602.0"
}
},
{
"identity" : "app-check",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/app-check.git",
"state" : {
"revision" : "3b62f154d00019ae29a71e9738800bb6f18b236d",
"version" : "10.19.2"
}
},
{
"identity" : "firebase-ios-sdk",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/firebase-ios-sdk",
"state" : {
"revision" : "eca84fd638116dd6adb633b5a3f31cc7befcbb7d",
"version" : "10.29.0"
}
},
{
"identity" : "googleappmeasurement",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleAppMeasurement.git",
"state" : {
"revision" : "fe727587518729046fc1465625b9afd80b5ab361",
"version" : "10.28.0"
}
},
{
"identity" : "googledatatransport",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleDataTransport.git",
"state" : {
"revision" : "a637d318ae7ae246b02d7305121275bc75ed5565",
"version" : "9.4.0"
}
},
{
"identity" : "googleutilities",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/GoogleUtilities.git",
"state" : {
"revision" : "57a1d307f42df690fdef2637f3e5b776da02aad6",
"version" : "7.13.3"
}
},
{
"identity" : "grpc-binary",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/grpc-binary.git",
"state" : {
"revision" : "e9fad491d0673bdda7063a0341fb6b47a30c5359",
"version" : "1.62.2"
}
},
{
"identity" : "gtm-session-fetcher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/gtm-session-fetcher.git",
"state" : {
"revision" : "a2ab612cb980066ee56d90d60d8462992c07f24b",
"version" : "3.5.0"
}
},
{
"identity" : "interop-ios-for-google-sdks",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/interop-ios-for-google-sdks.git",
"state" : {
"revision" : "2d12673670417654f08f5f90fdd62926dc3a2648",
"version" : "100.0.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher",
"state" : {
"revision" : "dd3c422ec3088404d6f7e8c905a8318b3de12d6f",
"version" : "8.6.0"
}
},
{
"identity" : "leveldb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/leveldb.git",
"state" : {
"revision" : "a0bc79961d7be727d258d33d5a6b2f1023270ba1",
"version" : "1.22.5"
}
},
{
"identity" : "nanopb",
"kind" : "remoteSourceControl",
"location" : "https://github.com/firebase/nanopb.git",
"state" : {
"revision" : "b7e1104502eca3a213b46303391ca4d3bc8ddec1",
"version" : "2.30910.0"
}
},
{
"identity" : "promises",
"kind" : "remoteSourceControl",
"location" : "https://github.com/google/promises.git",
"state" : {
"revision" : "540318ecedd63d883069ae7f1ed811a2df00b6ac",
"version" : "2.4.0"
}
},
{
"identity" : "swift-protobuf",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-protobuf.git",
"state" : {
"revision" : "2547102afd04fe49f1b286090f13ebce07284980",
"version" : "1.31.1"
}
}
],
"version" : 3
}
답변 1
0
안녕하세요, 인프런 AI 인턴입니다. Mark Kim님.
현재 상황에서 발생하는 “main actor-isolated initializer” 경고는 주로 Swift의 동시성 모델에서 메인 스레드와 비동기 코드의 상호작용과 관련이 있습니다. Swift에서는 UI 관련 작업이 메인 스레드에서 수행되어야 하며, KFImage
와 같은 UI 업데이트 작업은 MainActor
로 보호되어야 합니다. 아래의 방법을 통해 이 경고를 해결하실 수 있습니다:
KFImage
가 메인 스레드에서 실행되도록 @MainActor
속성을 사용해 명시적으로 지정해 보세요.@MainActor
func loadProfileImage(url: URL) {
KFImage(url)
.resizable() // 기타 코드 계속
}
DispatchQueue.main.async
를 통해 UI 업데이트를 명시적으로 보장하세요.DispatchQueue.main.async {
KFImage(url)
.resizable() // 기타 코드 계속
}
앞서 설명드린 내용을 적용하여 경고를 줄일 수 있습니다. 더불어, Swift의 동시성 모델에 대한 Apple 공식 문서를 참조하여 Swift의 동시성 및 메인 액터 사용 방법을 깊이 있게 이해하시면 도움이 될 것입니다.
다음 링크를 통해 비슷한 상황에서 도움을 줄 수 있는 답변을 참조하시길 권장합니다:
- @State와 @Bindable의 사용 차이점 설명
저는 질문자님의 이해를 돕고자 지식공유자님의 기존 답변을 참고하여 유사한 답변 링크를 추천해드리고 있습니다. 현재 베타 기능으로 답변이 만족스럽지 않을 수 있는 점 양해 부탁드립니다. 🙏 추가적으로 궁금한 점이 있으시면, 이어서 질문해 주세요. 곧 지식공유자께서 답변해 주실 것입니다.