문제

What is the best way to validate whether a NSString is a propertyList or not? If I call NSString's -propertyList method it will throw an exception if it cannot parse the string.

도움이 되었습니까?

해결책

Use +propertyListWithData:options:format:error: on NSPropertyListSerialization to attempt to parse the data, it can pass you back an NSError object with some diagnostics if it can't. For example:

NSString *plist = ...;
NSError *e = nil;
NSPropertyListFormat format;
id obj = [NSPropertyListSerialization 
    propertyListWithData:[plist dataUsingEncoding:NSUnicodeStringEncoding]
                 options:NSPropertyListImmutable
                  format:&format
                   error:&e];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top