如何在Swift中声明和使用C联合类型?
我试过了:
var value: union {
var output: CLongLong
var input: [CInt]
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用......
更新:我想使用union将a分割8 bytes number为2 x 4 bytes number.
我在运行时尝试使用NSDictionary的objectForKey:交换实现,但没有任何改变!
#import "NSDictionary+Utils.h"
#import <objc/runtime.h>
@implementation NSDictionary (Utils)
+ (void)load
{
method_exchangeImplementations(class_getInstanceMethod(self, @selector(objectForKey:)),
class_getInstanceMethod(self, @selector(_objectForKey:)));
}
- (id)_objectForKey:(id)aKey
{
NSLog(@"ok");
id obj = [self _objectForKey:aKey];
if ([obj isEqual:[NSNull null]]) {
return nil;
}
return obj;
}
@end
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么?
谢谢你读了我可怜的英语.