문제

I set the following value: [self.networkStream setProperty:(id)kCFBooleanTrue forKey:(id)kCFStreamPropertyFTPUsePassiveMode]; but before i do so i would like to check what value it currently has. But I am not able to find out how I can read its value.

I have a boolean variable, called "usepassive". What i need to do is compare the value above with usepassive.

I tried this:

BOOL status = [self.networkStream valueForKey:(id)kCFStreamPropertyFTPUsePassiveMode];
if (status != usepassive)
        {

The result is an error: [<__NSCFOutputStream 0x107d25d90> valueForUndefinedKey:]: this class is not key value coding-compliant for the key kCFStreamPropertyFTPUsePassiveMode.

How can I fix this?

도움이 되었습니까?

해결책

  • The counterpart to [networkStream setProperty:... forKey:...] is [networkStream propertyForKey:...].

  • propertyForKey returns an id (a pointer to an an Objective-C object), which can be converted to a BOOL with boolValue.

So the following should work:

BOOL usePassive = [[self.networkStream propertyForKey:(id)kCFStreamPropertyFTPUsePassiveMode] boolValue];
if (usePassive) {
    // passive mode enabled
} else {
    // passive mode disabled
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top