Skip to content

Instantly share code, notes, and snippets.

@hborders
Last active September 24, 2016 00:41
Show Gist options
  • Save hborders/8aa94a3f2b69b0f0890aecd96cc2f1f1 to your computer and use it in GitHub Desktop.
Save hborders/8aa94a3f2b69b0f0890aecd96cc2f1f1 to your computer and use it in GitHub Desktop.
Shows that CFMutableSetRef doesn't transfer CFSetCallBacks to NSSet returned from setByAddingObject:
#define HJBAssertNotSame(expression1, expression2, ...) \
XCTAssert((expression1) != (expression2), \
__VA_ARGS__)
- (void)testCFMutableSetWithOpaquePointersCopiedToNSSetByAddingDoesNotKeepOpaquePointerBehavior
{
NSString * _Nonnull string1 = [@"ab" stringByAppendingString:@"cd"];
NSString * _Nonnull string2 = [@"a" stringByAppendingString:@"bcd"];
TWAssertNotSame(string1,
string2);
NSMutableSet<NSString *> * _Nonnull stringsMutableSet = (NSMutableSet * _Nonnull) CFBridgingRelease(CFSetCreateMutable(NULL,
0,
NULL));
[stringsMutableSet addObject:string1];
[stringsMutableSet addObject:string2];
XCTAssertEqual(stringsMutableSet.count,
(NSUInteger) 2);
NSString * _Nonnull string3 = [@"abc" stringByAppendingString:@"d"];
HJBAssertNotSame(string1,
string3);
HJBAssertNotSame(string2,
string3);
NSSet<NSString *> * _Nonnull stringsSetCopiedFromStringsMutableSet = [stringsMutableSet setByAddingObject:string3];
XCTAssertEqual(stringsSetCopiedFromStringsMutableSet.count,
(NSUInteger) 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment