mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
An error type can conform to one or more of these new protocols to customize its behavior and representation. From an implementation standpoint, the protocol conformances are used to fill in the user-info dictionary in NSError to interoperate with the Cocoa error-handling system. There are a few outstanding problems with this implementation, although it is fully functional: * Population of the userInfo dictionary is currently eager; we should use user info providers on platforms where they are available. * At present, the Swift dynamic casting machinery is unable to unbox a _SwiftNativeNSError when trying to cast from it to (e.g.) an existential, which makes it impossible to retrieve the RecoverableError from the NSError. Instead, just capture the original error---hey, they're supposed to be value types anyway!---and use that to implement the entry points for the informal NSErrorRecoveryAttempting protocol. This is part (1) of the proposal solution.
131 lines
3.9 KiB
Plaintext
131 lines
3.9 KiB
Plaintext
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See http://swift.org/LICENSE.txt for license information
|
|
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#include <objc/message.h>
|
|
|
|
#include "swift/Runtime/Config.h"
|
|
|
|
SWIFT_CC(swift)
|
|
extern "C" void
|
|
NS_Swift_NSUndoManager_registerUndoWithTargetHandler(
|
|
id NS_RELEASES_ARGUMENT __nonnull self_,
|
|
id NS_RELEASES_ARGUMENT __nonnull target,
|
|
void (^__nonnull handler)(id __nonnull)) {
|
|
|
|
NSUndoManager *undoManager = self_;
|
|
[undoManager registerUndoWithTarget:target handler:handler];
|
|
|
|
[self_ release];
|
|
[target release];
|
|
[handler release];
|
|
}
|
|
|
|
|
|
// -- NSCoder
|
|
SWIFT_CC(swift)
|
|
extern "C" NS_RETURNS_RETAINED __nullable id
|
|
NS_Swift_NSCoder_decodeObject(id NS_RELEASES_ARGUMENT __nonnull self_,
|
|
NSError *__nullable *__nullable error) {
|
|
NSCoder *coder = (NSCoder *)self_;
|
|
id result = nil;
|
|
if (error) {
|
|
result = [coder decodeTopLevelObjectAndReturnError:error];
|
|
} else {
|
|
result = [coder decodeObject];
|
|
}
|
|
[self_ release];
|
|
return [result retain];
|
|
}
|
|
|
|
SWIFT_CC(swift)
|
|
extern "C" NS_RETURNS_RETAINED __nullable id
|
|
NS_Swift_NSCoder_decodeObjectForKey(id NS_RELEASES_ARGUMENT __nonnull self_,
|
|
id NS_RELEASES_ARGUMENT __nonnull key,
|
|
NSError *__nullable *__nullable error) {
|
|
NSCoder *coder = (NSCoder *)self_;
|
|
id result = nil;
|
|
if (error) {
|
|
result = [coder decodeTopLevelObjectForKey:key error:error];
|
|
} else {
|
|
result = [coder decodeObjectForKey:key];
|
|
}
|
|
[self_ release];
|
|
[key release];
|
|
return [result retain];
|
|
}
|
|
|
|
SWIFT_CC(swift)
|
|
extern "C" NS_RETURNS_RETAINED __nullable id
|
|
NS_Swift_NSCoder_decodeObjectOfClassForKey(
|
|
id NS_RELEASES_ARGUMENT __nonnull self_,
|
|
id NS_RELEASES_ARGUMENT __nonnull cls,
|
|
id NS_RELEASES_ARGUMENT __nonnull key,
|
|
NSError *__nullable *__nullable error) {
|
|
NSCoder *coder = (NSCoder *)self_;
|
|
id result = nil;
|
|
if (error) {
|
|
result = [coder decodeTopLevelObjectOfClass:cls forKey:key error:error];
|
|
} else {
|
|
result = [coder decodeObjectOfClass:cls forKey:key];
|
|
}
|
|
[self_ release];
|
|
[key release];
|
|
return [result retain];
|
|
}
|
|
|
|
SWIFT_CC(swift)
|
|
extern "C" NS_RETURNS_RETAINED __nullable id
|
|
NS_Swift_NSCoder_decodeObjectOfClassesForKey(
|
|
id NS_RELEASES_ARGUMENT __nonnull self_,
|
|
NSSet *NS_RELEASES_ARGUMENT __nullable classes,
|
|
id NS_RELEASES_ARGUMENT __nonnull key,
|
|
NSError *__nullable *__nullable error) {
|
|
NSCoder *coder = (NSCoder *)self_;
|
|
id result = nil;
|
|
if (error) {
|
|
result = [coder decodeTopLevelObjectOfClasses:classes forKey:key error:error];
|
|
} else {
|
|
result = [coder decodeObjectOfClasses:classes forKey:key];
|
|
}
|
|
[self_ release];
|
|
[classes release];
|
|
[key release];
|
|
return [result retain];
|
|
}
|
|
|
|
// -- NSKeyedUnarchiver
|
|
SWIFT_CC(swift)
|
|
extern "C" NS_RETURNS_RETAINED __nullable id
|
|
NS_Swift_NSKeyedUnarchiver_unarchiveObjectWithData(
|
|
Class Self_, id NS_RELEASES_ARGUMENT __nonnull data,
|
|
NSError *__nullable *__nullable error) {
|
|
id result = nil;
|
|
if (error) {
|
|
result = [Self_ unarchiveTopLevelObjectWithData:data error:error];
|
|
} else {
|
|
result = [Self_ unarchiveObjectWithData:data];
|
|
}
|
|
[data release];
|
|
return [result retain];
|
|
}
|
|
|
|
// -- NSError
|
|
SWIFT_CC(swift)
|
|
extern "C" void
|
|
NS_Swift_performErrorRecoverySelector(_Nullable id delegate,
|
|
SEL selector,
|
|
BOOL success,
|
|
void * _Nullable contextInfo) {
|
|
objc_msgSend(delegate, selector, success, contextInfo);
|
|
}
|