1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//===--- ArrayBridge.m - Array bridge/cast tests - the ObjC side ----------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
//
//
//===----------------------------------------------------------------------===//
#include "ArrayBridge.h"
#include <stdio.h>
@interface Thunks : NSObject
- (id)createSubclass:(NSInteger)value;
- (id)acceptSubclassArray:(NSArray *)bridged expecting:(NSArray*)unbridged;
- (NSArray *)produceSubclassArray:(NSMutableArray *)expectations;
- (void)checkProducedSubclassArray:(NSArray *)produced expecting:(NSArray *)expected;
- (void)checkProducedBridgeableValueArray:(NSArray *)produced;
- (void)acceptBridgeableValueArray:(NSArray *)x;
- (NSArray *)produceBridgeableValueArray;
@end
id arrayAsID(NSArray* a) {
return a;
}
NSArray* idAsArray(id a) {
return a;
}
// Call back into thunks, passing arrays in both directions
void testSubclass(id thunks) {
// Retrieve an array from Swift.
NSMutableArray* expectations = [[NSMutableArray alloc] init];
NSArray *fromObjCArr = [thunks produceSubclassArray:expectations];
[thunks checkProducedSubclassArray:fromObjCArr expecting:expectations];
// Send an array to swift.
NSMutableArray *toObjCArr = [[NSMutableArray alloc] init];
[toObjCArr addObject: [thunks createSubclass:10]];
[toObjCArr addObject: [thunks createSubclass:11]];
[toObjCArr addObject: [thunks createSubclass:12]];
[toObjCArr addObject: [thunks createSubclass:13]];
[toObjCArr addObject: [thunks createSubclass:14]];
[thunks acceptSubclassArray: toObjCArr expecting: toObjCArr];
}
void testBridgeableValue(id thunks) {
// Retrieve an array from Swift.
NSArray *fromSwiftArr = [thunks produceBridgeableValueArray];
[thunks checkProducedBridgeableValueArray: fromSwiftArr];
// Send an array to swift.
NSMutableArray *toSwiftArr = [[NSMutableArray alloc] init];
[toSwiftArr addObject: [thunks createSubclass:10]];
[toSwiftArr addObject: [thunks createSubclass:11]];
[toSwiftArr addObject: [thunks createSubclass:12]];
[toSwiftArr addObject: [thunks createSubclass:13]];
[toSwiftArr addObject: [thunks createSubclass:14]];
[thunks acceptBridgeableValueArray: toSwiftArr];
}
static id filter(id<NSFastEnumeration, NSObject> container, BOOL (^predicate)(id)) {
id result = [[[container class] new] mutableCopy];
for (id object in container) {
if (predicate(object)) {
[result addObject:object];
}
}
return result;
}
id testHKTFilter(id array) {
return filter(array, ^(id obj) {
return [obj isEqual:@"hello"];
});
}
@implementation RDar27905230
+ (NSDictionary<NSString *, NSArray<id> *> *)mutableDictionaryOfMutableLists {
NSMutableArray *arr = [NSMutableArray array];
[arr addObject:[NSNull null]];
[arr addObject:@""];
[arr addObject:@1];
[arr addObject:@YES];
[arr addObject:[NSValue valueWithRange:NSMakeRange(0, 1)]];
[arr addObject:[NSDate dateWithTimeIntervalSince1970: 0]];
return [NSMutableDictionary dictionaryWithObject:arr forKey:@"list"];
}
@end
|