From 0f7c916b1a0e2ef3a7bbc7c92e4a1431115fe0b6 Mon Sep 17 00:00:00 2001 From: Philip Dukhov Date: Sat, 23 Oct 2021 17:42:25 +0700 Subject: [PATCH] added Swift usage example --- ios/Napier.xcodeproj/project.pbxproj | 6 +++- ios/Napier/Napier.swift | 54 ++++++++++++++++++++++++++++ ios/Napier/ViewController.swift | 2 ++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 ios/Napier/Napier.swift diff --git a/ios/Napier.xcodeproj/project.pbxproj b/ios/Napier.xcodeproj/project.pbxproj index 8449eae..a40ab74 100644 --- a/ios/Napier.xcodeproj/project.pbxproj +++ b/ios/Napier.xcodeproj/project.pbxproj @@ -3,11 +3,12 @@ archiveVersion = 1; classes = { }; - objectVersion = 50; + objectVersion = 51; objects = { /* Begin PBXBuildFile section */ 3B3988B1264ADA500055407D /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3988B0264ADA500055407D /* GoogleService-Info.plist */; }; + 4AC2641627241E48002BE68B /* Napier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4AC2641527241E48002BE68B /* Napier.swift */; }; 625D2A51333F356CAFD0D528 /* Pods_Napier.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 236CB35798B6FF37795E2A6A /* Pods_Napier.framework */; }; 7CFB659A22013CF600BD05FC /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CFB659922013CF600BD05FC /* AppDelegate.swift */; }; 7CFB659C22013CF600BD05FC /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7CFB659B22013CF600BD05FC /* ViewController.swift */; }; @@ -20,6 +21,7 @@ 14D73DDEDA418BBBD3C23B9B /* Pods-Napier.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Napier.release.xcconfig"; path = "Target Support Files/Pods-Napier/Pods-Napier.release.xcconfig"; sourceTree = ""; }; 236CB35798B6FF37795E2A6A /* Pods_Napier.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Napier.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 3B3988B0264ADA500055407D /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 4AC2641527241E48002BE68B /* Napier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Napier.swift; sourceTree = ""; }; 6F88F8388EB37A3B9C7069DF /* Pods-Napier.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Napier.debug.xcconfig"; path = "Target Support Files/Pods-Napier/Pods-Napier.debug.xcconfig"; sourceTree = ""; }; 7CFB659622013CF500BD05FC /* Napier.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Napier.app; sourceTree = BUILT_PRODUCTS_DIR; }; 7CFB659922013CF600BD05FC /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -83,6 +85,7 @@ 3B3988B0264ADA500055407D /* GoogleService-Info.plist */, 7CFB659922013CF600BD05FC /* AppDelegate.swift */, 7CFB659B22013CF600BD05FC /* ViewController.swift */, + 4AC2641527241E48002BE68B /* Napier.swift */, 7CFB659D22013CF600BD05FC /* Main.storyboard */, 7CFB65A022013CF900BD05FC /* Assets.xcassets */, 7CFB65A222013CF900BD05FC /* LaunchScreen.storyboard */, @@ -247,6 +250,7 @@ buildActionMask = 2147483647; files = ( 7CFB659C22013CF600BD05FC /* ViewController.swift in Sources */, + 4AC2641627241E48002BE68B /* Napier.swift in Sources */, 7CFB659A22013CF600BD05FC /* AppDelegate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/ios/Napier/Napier.swift b/ios/Napier/Napier.swift new file mode 100644 index 0000000..026113a --- /dev/null +++ b/ios/Napier/Napier.swift @@ -0,0 +1,54 @@ +// +// Napier.swift +// Napier +// +// Created by Phil on 23.10.2021. +// Copyright © 2021 AAkira. All rights reserved. +// + +import mpp_sample + +extension Napier { + static func v(tag: String? = nil, _ items: Any..., separator: String = " ", file: String = #file, function: String = #function) { + log(logLevel: .verbose, tag: tag, items, separator: separator, file: file, function: function) + } + + static func d(tag: String? = nil, _ items: Any..., separator: String = " ", file: String = #file, function: String = #function) { + log(logLevel: .debug, tag: tag, items, separator: separator, file: file, function: function) + } + + static func i(tag: String? = nil, _ items: Any..., separator: String = " ", file: String = #file, function: String = #function) { + log(logLevel: .info, tag: tag, items, separator: separator, file: file, function: function) + } + + static func w(tag: String? = nil, _ items: Any..., separator: String = " ", file: String = #file, function: String = #function) { + log(logLevel: .warning, tag: tag, items, separator: separator, file: file, function: function) + } + + static func e(tag: String? = nil, _ items: Any..., separator: String = " ", file: String = #file, function: String = #function) { + log(logLevel: .error, tag: tag, items, separator: separator, file: file, function: function) + } + + static func a(tag: String? = nil, _ items: Any..., separator: String = " ", file: String = #file, function: String = #function) { + log(logLevel: .assert, tag: tag, items, separator: separator, file: file, function: function) + } + + static private func log(logLevel: LogLevel, tag: String?, _ items: [Any], separator: String, file: String, function: String) { + let message = items.map { "\($0)" }.joined(separator: separator) + shared.log( + priority: logLevel, + tag: tag ?? { + let fileName = URL(fileURLWithPath: file).lastPathComponent + let functionName: String + if let firstBraceIndex = function.firstIndex(of: "(") { + functionName = String(function[..