خرید بک لینک

Vote count: 0

I'm using this approach to keep my string constants together. Using the same example from that post:

MONExtResult.h

struct MONExtResultStruct {
    __unsafe_unretained NSString * const AppID;
    __unsafe_unretained NSString * const ErrorCode;
    __unsafe_unretained NSString * const Progress;
};

exte const struct MONExtResultStruct MONExtResult;

MONExtResult.m

const struct MONExtResultStruct MONExtResult = {
    .AppID = @"appid",
    .ErrorCode = @"errorcode",
    .Progress = @"progress"
};

When I try to use it in Swift:

let appID: String = MONExtResult.AppID

I get the error:

Caot convert value of type 'Unmanaged<NSString>!' to expected argument type 'String'

This is because I need to grab the value from the unmanaged wrapper and then convert it to a String:

let appID: String = MONExtResult.AppID.takeUnretainedValue() as String

Is there any way to aotate the objective-C code to prevent the need for calling takeUnretainedValue like you can with CF_IMPLICIT_BRIDGING_ENABLED or CF_RETURNS_RETAINED for C functions?

asked 55 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 6 تير 1395 ساعت: 22:46

صفحه بندی