Skip to content

Commit

Permalink
Merge pull request #88 from PhilipDukhov/sampleUsageFromSwift
Browse files Browse the repository at this point in the history
Sample usage from swift
  • Loading branch information
AAkira authored Oct 26, 2021
2 parents bfe5784 + 0f7c916 commit 76fa7a3
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 17 deletions.
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)
}
}
76 changes: 60 additions & 16 deletions mpp-sample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import dependencies.Dep
import dependencies.Versions
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.Framework

plugins {
kotlin("multiplatform")
Expand All @@ -17,25 +19,42 @@ kotlin {
jvm()

// darwin
if (isAppleSilicon) {
if (ideaActive.not()) {
// intel
macosX64()
ios()
watchos()

// apple silicon
macosArm64()
iosSimulatorArm64()
watchosSimulatorArm64()
} else {
// intel
macosX64()
iosX64()
watchosX64()
if (isAppleSilicon) {
// apple silicon
macosArm64()
iosSimulatorArm64()
watchosSimulatorArm64()
} else {
// intel
macosX64()
iosX64()
watchosX64()
}
}
targets.withType<KotlinNativeTarget> {
binaries.withType<Framework> {
export(project(":napier"))
}
}

sourceSets {
val commonMain by getting {
dependencies {
implementation(Dep.Kotlin.common)
implementation(Dep.Coroutines.core)

implementation(project(":napier"))
api(project(":napier"))
}
}
val androidMain by getting {
Expand All @@ -58,28 +77,53 @@ kotlin {
val darwinMain by creating {
dependsOn(commonMain)
}
if (isAppleSilicon) {
// apple silicon
val macosArm64Main by getting {
// darwin
if (ideaActive.not()) {
// intel
val macosX64Main by getting {
dependsOn(darwinMain)
}
val iosSimulatorArm64Main by getting {
val iosMain by getting {
dependsOn(darwinMain)
}
val watchosSimulatorArm64Main by getting {
val watchosMain by getting {
dependsOn(darwinMain)
}
} else {
// intel
val macosX64Main by getting {

// apple silicon
val macosArm64Main by getting {
dependsOn(darwinMain)
}
val iosX64Main by getting {
val iosSimulatorArm64Main by getting {
dependsOn(darwinMain)
}
val watchosX64Main by getting {
val watchosSimulatorArm64Main by getting {
dependsOn(darwinMain)
}
} else {
if (isAppleSilicon) {
// apple silicon
val macosArm64Main by getting {
dependsOn(darwinMain)
}
val iosSimulatorArm64Main by getting {
dependsOn(darwinMain)
}
val watchosSimulatorArm64Main by getting {
dependsOn(darwinMain)
}
} else {
// intel
val macosX64Main by getting {
dependsOn(darwinMain)
}
val iosX64Main by getting {
dependsOn(darwinMain)
}
val watchosX64Main by getting {
dependsOn(darwinMain)
}
}
}
}

Expand Down

0 comments on commit 76fa7a3

Please sign in to comment.