Skip to content

Commit

Permalink
added Swift usage example
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilipDukhov committed Oct 23, 2021
1 parent 7bfba62 commit 0f7c916
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ios/Napier.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand All @@ -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 = "<group>"; };
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 = "<group>"; };
4AC2641527241E48002BE68B /* Napier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Napier.swift; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -247,6 +250,7 @@
buildActionMask = 2147483647;
files = (
7CFB659C22013CF600BD05FC /* ViewController.swift in Sources */,
4AC2641627241E48002BE68B /* Napier.swift in Sources */,
7CFB659A22013CF600BD05FC /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
54 changes: 54 additions & 0 deletions ios/Napier/Napier.swift
Original file line number Diff line number Diff line change
@@ -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[..<firstBraceIndex])
} else {
functionName = function
}
return "\(fileName):\(functionName)"
}(),
throwable: nil,
message_: message
)
}
}
2 changes: 2 additions & 0 deletions ios/Napier/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ private extension ViewController {
sample.suspendHelloKt()

sample.handleError()

Napier.d("Hello from Napier", 123)
}
}

0 comments on commit 0f7c916

Please sign in to comment.