From 1994ca3b4decbbd4e9b02b1144352ba1cff252c1 Mon Sep 17 00:00:00 2001 From: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Date: Tue, 14 Aug 2018 09:00:03 +0200 Subject: [PATCH] Added NSFileHandle category and bridging header --- Logger.xcodeproj/project.pbxproj | 32 ++++++++++++++ Logger/Logger-Bridging-Header.h | 5 +++ .../Loggers/DiskLogger/NSFileHandle+Swift.h | 35 +++++++++++++++ .../Loggers/DiskLogger/NSFileHandle+Swift.m | 44 +++++++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 Logger/Logger-Bridging-Header.h create mode 100644 Logger/Loggers/DiskLogger/NSFileHandle+Swift.h create mode 100644 Logger/Loggers/DiskLogger/NSFileHandle+Swift.m diff --git a/Logger.xcodeproj/project.pbxproj b/Logger.xcodeproj/project.pbxproj index c3b2fad..b9e551a 100644 --- a/Logger.xcodeproj/project.pbxproj +++ b/Logger.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 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 */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -33,6 +34,9 @@ 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 = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -65,6 +69,7 @@ 2EBF4B3C2122AA34008E4117 /* Logger */ = { isa = PBXGroup; children = ( + 2EBF4B532122B2AA008E4117 /* Logger-Bridging-Header.h */, 2EBF4B442122ACD6008E4117 /* LogStringConvertible.swift */, 2EBF4B3D2122AA34008E4117 /* Logger.swift */, 2EBF4B462122AF53008E4117 /* Loggers */, @@ -78,10 +83,20 @@ 2EBF4B472122AF53008E4117 /* AgregateLogger.swift */, 2EBF4B482122AF53008E4117 /* ConsoleLogger.swift */, 2EBF4B492122AF53008E4117 /* NullLogger.swift */, + 2EBF4B4D2122B034008E4117 /* DiskLogger */, ); path = Loggers; sourceTree = ""; }; + 2EBF4B4D2122B034008E4117 /* DiskLogger */ = { + isa = PBXGroup; + children = ( + 2EBF4B4F2122B06E008E4117 /* NSFileHandle+Swift.h */, + 2EBF4B502122B06E008E4117 /* NSFileHandle+Swift.m */, + ); + path = DiskLogger; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -114,6 +129,7 @@ TargetAttributes = { 2EBF4B392122AA34008E4117 = { CreatedOnToolsVersion = 10.0; + LastSwiftMigration = 1000; }; }; }; @@ -141,6 +157,7 @@ files = ( 2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */, 2EBF4B3E2122AA34008E4117 /* Logger.swift in Sources */, + 2EBF4B512122B06E008E4117 /* NSFileHandle+Swift.m in Sources */, 2EBF4B4B2122AF53008E4117 /* ConsoleLogger.swift in Sources */, 2EBF4B4A2122AF53008E4117 /* AgregateLogger.swift in Sources */, 2EBF4B452122ACD6008E4117 /* LogStringConvertible.swift in Sources */, @@ -269,10 +286,18 @@ 2EBF4B422122AA34008E4117 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); 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 = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -281,10 +306,17 @@ 2EBF4B432122AA34008E4117 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CLANG_ENABLE_MODULES = YES; CODE_SIGN_STYLE = Automatic; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_OBJC_BRIDGING_HEADER = "Logger/Logger-Bridging-Header.h"; SWIFT_VERSION = 4.2; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/Logger/Logger-Bridging-Header.h b/Logger/Logger-Bridging-Header.h new file mode 100644 index 0000000..886bed2 --- /dev/null +++ b/Logger/Logger-Bridging-Header.h @@ -0,0 +1,5 @@ +// +// Use this file to import your target's public headers that you would like to expose to Swift. +// + +#import "NSFileHandle+Swift.h" diff --git a/Logger/Loggers/DiskLogger/NSFileHandle+Swift.h b/Logger/Loggers/DiskLogger/NSFileHandle+Swift.h new file mode 100644 index 0000000..23f3d4e --- /dev/null +++ b/Logger/Loggers/DiskLogger/NSFileHandle+Swift.h @@ -0,0 +1,35 @@ +// +// 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 new file mode 100644 index 0000000..994e667 --- /dev/null +++ b/Logger/Loggers/DiskLogger/NSFileHandle+Swift.m @@ -0,0 +1,44 @@ +// +// 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