From da03316ce6a44bc0c99738e9eb72e767455a7938 Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Wed, 30 Oct 2019 18:55:31 +0100 Subject: [PATCH] Remove NSFileHandle+Swift and replace it by calling __write(_:error:) --- Logger.xcodeproj/project.pbxproj | 10 ----- Logger/Logger-Bridging-Header.h | 5 --- Logger/Loggers/DiskLogger/DiskLogger.swift | 3 ++ .../Loggers/DiskLogger/NSFileHandle+Swift.h | 35 --------------- .../Loggers/DiskLogger/NSFileHandle+Swift.m | 44 ------------------- 5 files changed, 3 insertions(+), 94 deletions(-) delete mode 100644 Logger/Logger-Bridging-Header.h delete mode 100644 Logger/Loggers/DiskLogger/NSFileHandle+Swift.h delete mode 100644 Logger/Loggers/DiskLogger/NSFileHandle+Swift.m diff --git a/Logger.xcodeproj/project.pbxproj b/Logger.xcodeproj/project.pbxproj index bcdfc0c..46251ca 100644 --- a/Logger.xcodeproj/project.pbxproj +++ b/Logger.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ 2EBF4B4A2122AF53008E4117 /* AgregateLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B472122AF53008E4117 /* AgregateLogger.swift */; }; 2EBF4B4B2122AF53008E4117 /* ConsoleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B482122AF53008E4117 /* ConsoleLogger.swift */; }; 2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B492122AF53008E4117 /* NullLogger.swift */; }; - 2EBF4B512122B06E008E4117 /* NSFileHandle+Swift.m in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B502122B06E008E4117 /* NSFileHandle+Swift.m */; }; 2EBF4B572122B598008E4117 /* DiskLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B542122B598008E4117 /* DiskLogger.swift */; }; 2EBF4B582122B598008E4117 /* FileWriter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B552122B598008E4117 /* FileWriter.swift */; }; 2EBF4B592122B598008E4117 /* FileRotate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B562122B598008E4117 /* FileRotate.swift */; }; @@ -58,9 +57,6 @@ 2EBF4B472122AF53008E4117 /* AgregateLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgregateLogger.swift; sourceTree = ""; }; 2EBF4B482122AF53008E4117 /* ConsoleLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleLogger.swift; sourceTree = ""; }; 2EBF4B492122AF53008E4117 /* NullLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NullLogger.swift; sourceTree = ""; }; - 2EBF4B4F2122B06E008E4117 /* NSFileHandle+Swift.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSFileHandle+Swift.h"; sourceTree = ""; }; - 2EBF4B502122B06E008E4117 /* NSFileHandle+Swift.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSFileHandle+Swift.m"; sourceTree = ""; }; - 2EBF4B532122B2AA008E4117 /* Logger-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Logger-Bridging-Header.h"; sourceTree = ""; }; 2EBF4B542122B598008E4117 /* DiskLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiskLogger.swift; sourceTree = ""; }; 2EBF4B552122B598008E4117 /* FileWriter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileWriter.swift; sourceTree = ""; }; 2EBF4B562122B598008E4117 /* FileRotate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileRotate.swift; sourceTree = ""; }; @@ -128,7 +124,6 @@ 2EBF4B3C2122AA34008E4117 /* Logger */ = { isa = PBXGroup; children = ( - 2EBF4B532122B2AA008E4117 /* Logger-Bridging-Header.h */, 2EBF4B442122ACD6008E4117 /* LogStringConvertible.swift */, 2EBF4B3D2122AA34008E4117 /* Logger.swift */, 2EBF4B462122AF53008E4117 /* Loggers */, @@ -153,8 +148,6 @@ 2EBF4B542122B598008E4117 /* DiskLogger.swift */, 2EBF4B552122B598008E4117 /* FileWriter.swift */, 2EBF4B562122B598008E4117 /* FileRotate.swift */, - 2EBF4B4F2122B06E008E4117 /* NSFileHandle+Swift.h */, - 2EBF4B502122B06E008E4117 /* NSFileHandle+Swift.m */, 2ED077DA2132B0320058EEFC /* FileSystem.swift */, ); path = DiskLogger; @@ -269,7 +262,6 @@ 2EBF4B572122B598008E4117 /* DiskLogger.swift in Sources */, 2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */, 2EBF4B3E2122AA34008E4117 /* Logger.swift in Sources */, - 2EBF4B512122B06E008E4117 /* NSFileHandle+Swift.m in Sources */, 2EBF4B4B2122AF53008E4117 /* ConsoleLogger.swift in Sources */, 2ED077DB2132B0320058EEFC /* FileSystem.swift in Sources */, 2EBF4B4A2122AF53008E4117 /* AgregateLogger.swift in Sources */, @@ -452,7 +444,6 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_OBJC_BRIDGING_HEADER = "Logger/Logger-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; @@ -472,7 +463,6 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_OBJC_BRIDGING_HEADER = "Logger/Logger-Bridging-Header.h"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/Logger/Logger-Bridging-Header.h b/Logger/Logger-Bridging-Header.h deleted file mode 100644 index 6a5bec0..0000000 --- a/Logger/Logger-Bridging-Header.h +++ /dev/null @@ -1,5 +0,0 @@ -// -// Use this file to import your target's public headers that you would like to expose to Swift. -// - -#import "Loggers/DiskLogger/NSFileHandle+Swift.h" diff --git a/Logger/Loggers/DiskLogger/DiskLogger.swift b/Logger/Loggers/DiskLogger/DiskLogger.swift index c2a44d0..340fa48 100644 --- a/Logger/Loggers/DiskLogger/DiskLogger.swift +++ b/Logger/Loggers/DiskLogger/DiskLogger.swift @@ -186,4 +186,7 @@ private class FileHandleFactory: FileFactory { extension FileHandle: File { + func swift_write(_ data: Data) throws { + try __write(data, error: ()) + } } diff --git a/Logger/Loggers/DiskLogger/NSFileHandle+Swift.h b/Logger/Loggers/DiskLogger/NSFileHandle+Swift.h deleted file mode 100644 index 23f3d4e..0000000 --- a/Logger/Loggers/DiskLogger/NSFileHandle+Swift.h +++ /dev/null @@ -1,35 +0,0 @@ -// -// MIT License -// -// Copyright (c) 2018 Wojciech Nagrodzki -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface NSFileHandle (Swift) - -- (BOOL)swift_writeData:(NSData *)data error:(NSError **)error; - -@end - -NS_ASSUME_NONNULL_END diff --git a/Logger/Loggers/DiskLogger/NSFileHandle+Swift.m b/Logger/Loggers/DiskLogger/NSFileHandle+Swift.m deleted file mode 100644 index 994e667..0000000 --- a/Logger/Loggers/DiskLogger/NSFileHandle+Swift.m +++ /dev/null @@ -1,44 +0,0 @@ -// -// MIT License -// -// Copyright (c) 2018 Wojciech Nagrodzki -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. -// - -#import "NSFileHandle+Swift.h" - -@implementation NSFileHandle (Swift) - -- (BOOL)swift_writeData:(NSData *)data error:(NSError **)error { - @try { - [self writeData:data]; - return YES; - } - @catch (NSException *exception) { - if (error == nil) { - return NO; - } - NSDictionary * userInfo = @{NSLocalizedFailureReasonErrorKey: exception.reason}; - *error = [NSError errorWithDomain:@"NSFileHandleException" code:1 userInfo:userInfo]; - return NO; - } -} - -@end