this approach을 사용하여 문자열 상수를 함께 유지합니다.Objective-C 구조체를 사용할 때 takeRetainedValue 또는 takeUnretainedValue를 방지합니다.
MONExtResult.h 이것과 같이 오브젝티브 C에 사용할 수
const struct MONExtResultStruct MONExtResult = {
.AppID = @"appid",
.ErrorCode = @"errorcode",
.Progress = @"progress"
};
struct MONExtResultStruct {
__unsafe_unretained NSString * const AppID;
__unsafe_unretained NSString * const ErrorCode;
__unsafe_unretained NSString * const Progress;
};
extern const struct MONExtResultStruct MONExtResult;
MONExtResult.m :
해당 게시물에서 동일한 예를 사용NSString *str = MONExtResult.AppID;
나는 그러나, 스위프트에서 사용하려고 할 때 : 나는 그것을 변환 후 unmanaged wrapper에서 값을 잡고해야하기 때문에
Cannot convert value of type 'Unmanaged<NSString>!' to expected argument type 'String'
이것은 :
let appID: String = MONExtResult.AppID
... 나는 오류 String으로 :
let appID: String = MONExtResult.AppID.takeUnretainedValue() as String
는 CF_IMPLICIT_BRIDGING_ENABLED
또는때와 수처럼 takeUnretainedValue
를 호출의 필요성을 방지하기 위해 목표 - C 코드에 주석을 달 수있는 방법이 있나요 C 함수에 대한? 업데이트 : 상수는 Objective-C와 Swift 모두에서 액세스 할 수 있어야합니다. 그렇지 않으면 String
원시 값을 가진 신속한 enum을 사용합니다.
요구 사항 중 하나는 Objective-C와 Swift 모두에서 사용해야하기 때문에 Objective-C 구조체로 남아 있어야한다는 것입니다. Swift에서 열거 형을 만들면 원시 값 때문에 Objective-C 코드에서 액세스 할 수 없습니다. – Senseful
사용 방법에 대한 예를 들어주십시오. Objective-C – Feldur
안전하지 않은 모든 보존되지 않은 주석을 단순히 제거하면 어떻게됩니까? – Feldur