your programing

Xcode 7.3은 수동 참조 계산을 사용하여 파일에 __weak 참조를 만들 수 없습니다.

lovepro 2020. 10. 6. 18:54
반응형

Xcode 7.3은 수동 참조 계산을 사용하여 파일에 __weak 참조를 만들 수 없습니다.


Xcode 7.3으로 업데이트 한 후 Cannot create __weak reference in file using manual reference counting포드 파일에 오류가 발생 합니다. 누구든지이 문제를 해결 했습니까?


로 설정 Build Settings -> Apple LLVM 7.1 - Language - Objective C -> Weak References in Manual Retain Release합니다 YES.

시각적 예

에서 촬영 애플 개발자 포럼 - 엑스 코드 7.3b4, 비 아크, __weak 참조를 만들 수 없습니다 .


이것은 링크에서 Apple의 공식 답변입니다.

이 문제는 다음에 따라 의도 한대로 작동합니다. 모든 Objective-C 언어 모드에서 약한 참조를 구현하는 중입니다. “__weak”은 역사적으로 비 ARC (및 비 GC) 언어 모드에서 무시되었으므로이 오류를 추가하여 향후 의미 체계가 변경 될 위치를 지적했습니다. 버그 보고서를 업데이트하여 이것이 여전히 문제인지 알려주십시오.

따라서 기본적으로 타사 라이브러리에 Pod를 사용하는 경우 비 ARC에서 __weak을 삭제하거나 업데이트를 기다려야합니다.

업데이트 @ 3/23

이런 종류의 것들을 우회하기 위해 컴파일러에게 전달할 수있는 플래그에 대해 더 많이 조사해야했습니다. 그러나 근본적으로 __weak예기치 않은 충돌을 피하기 위해 지금부터 비 ARC 모드에서 사용해서는 안됩니다 . cocoapods 사용자의 경우 __weak업데이트 를 삭제 하거나 기다릴 필요가 없지만 Weak References in Manual Retain ReleaseLean이 말한 것처럼 빌드 설정의 플래그를 YES로 설정하십시오. 이 도움을 바랍니다.


이 문제를 해결하는 가장 좋은 방법 은 모든 포드 대상에서 플래그를 post_install설정 하는 스크립트를 Podfile 에 추가하는 것 입니다. 그렇게하려면 .Weak References in Manual Retain ReleaseyesPodfile

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['CLANG_ENABLE_OBJC_WEAK'] ||= 'YES'
        end
    end
end

때때로 그렇게하면 오류가 발생 -fobjc-weak is not supported on the current deployment target합니다. 다른 구성 옵션을 추가하여 모든 포드가 원하는 버전을 대상으로하도록 강제하여 해결할 수 있습니다 ( 이 답변을 기반으로 ).

post_install do |installer_representation|
    installer_representation.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            config.build_settings['CLANG_ENABLE_OBJC_WEAK'] ||= 'YES'
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.3'
        end
    end
end

FBSettings.m에서 Facebook 약한 참조에 대한 해결 방법

Podfile에는 pod 설치 / 업데이트 후 실행할 스크립트를 작성할 수 있으며, 거기에 다음을 설명합니다.

 
post_install do | installer |
     classy_pods_target = installer.pods_project.targets.find {| target | target.name == 'Facebook-iOS-SDK'}
     classy_pods_target.build_configurations.each do | config |
         config.build_settings['CLANG_ENABLE_OBJC_WEAK'] ||= 'YES'
     end
 end

CLANG_ENABLE_OBJC_WEAK 마법의 단어를 찾는 방법. 유효한 XHTML.


나는 이것을 발견했다.

__weak 삭제를 의미하는 것 같아요

https://forums.developer.apple.com/thread/38934

음, MRR [수동 유지 해제]에서 약한 변수 참조와 같은 것이 있었습니까? "__weak"은 다음 두 가지 중 하나 또는 둘 다를 의미합니다.

  1. 소유되지 않은 참조 (즉, 보유 횟수를 나타내지 않음).

  2. A zeroing reference (i.e. that the runtime zeroes when the referenced object is deallocated).

#1 doesn't apply to MRR, because you just don't retain the variable anyway.

#2 doesn't apply to MRR either, because the runtime support is in GC and ARC [automatic reference counting], which you're not using.

It sounds like the compiler is now just complaining that it can't do what it could never do. (And in the case of an app delegate, you wouldn't be able to tell the difference at run-time, since the app delegate generally is never deallocated.)


Just goto your target in "Build Phases" tab look for the pod files in "Compile Sources", click those files and add compiler flag "-fobjc-arc"


또는로 변경 __weak하십시오 __unsafeunretained. 이것은 전통의 문제를 해결할 것입니다. MRC (xCode 4 이전-) 이후 __weak은 iOS에 없었습니다.

참고 URL : https://stackoverflow.com/questions/36147625/xcode-7-3-cannot-create-weak-reference-in-file-using-manual-reference-counting

반응형