From cd4d5005700f3256bd0404d5caa2997d22c1113a Mon Sep 17 00:00:00 2001 From: tobias <thinkdifferent055@gmail.com> Date: Wed, 24 Mar 2021 13:41:44 +0100 Subject: [PATCH] Add some utils methods --- AppleLibs.xcodeproj/project.pbxproj | 20 ++++++++++++++++++++ AppleLibs/Numbers/Double+Rounded.swift | 17 +++++++++++++++++ AppleLibs/String+Extended.swift | 26 ++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 AppleLibs/Numbers/Double+Rounded.swift create mode 100644 AppleLibs/String+Extended.swift diff --git a/AppleLibs.xcodeproj/project.pbxproj b/AppleLibs.xcodeproj/project.pbxproj index 413f4a9..23ff45a 100644 --- a/AppleLibs.xcodeproj/project.pbxproj +++ b/AppleLibs.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ F6A251A0260B670000132DEC /* AppleLibs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F6A25196260B66FF00132DEC /* AppleLibs.framework */; }; F6A251A5260B670000132DEC /* AppleLibsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6A251A4260B670000132DEC /* AppleLibsTests.swift */; }; F6A251A7260B670000132DEC /* AppleLibs.h in Headers */ = {isa = PBXBuildFile; fileRef = F6A25199260B66FF00132DEC /* AppleLibs.h */; settings = {ATTRIBUTES = (Public, ); }; }; + F6A251BA260B697300132DEC /* Double+Rounded.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6A251B9260B697300132DEC /* Double+Rounded.swift */; }; + F6A251BE260B699100132DEC /* String+Extended.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6A251BD260B699100132DEC /* String+Extended.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -30,6 +32,8 @@ F6A251A4260B670000132DEC /* AppleLibsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleLibsTests.swift; sourceTree = "<group>"; }; F6A251A6260B670000132DEC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; F6A251B2260B680F00132DEC /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; }; + F6A251B9260B697300132DEC /* Double+Rounded.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Double+Rounded.swift"; sourceTree = "<group>"; }; + F6A251BD260B699100132DEC /* String+Extended.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extended.swift"; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -73,6 +77,8 @@ F6A25198260B66FF00132DEC /* AppleLibs */ = { isa = PBXGroup; children = ( + F6A251B8260B696200132DEC /* Numbers */, + F6A251BD260B699100132DEC /* String+Extended.swift */, F6A25199260B66FF00132DEC /* AppleLibs.h */, F6A2519A260B66FF00132DEC /* Info.plist */, ); @@ -88,6 +94,14 @@ path = AppleLibsTests; sourceTree = "<group>"; }; + F6A251B8260B696200132DEC /* Numbers */ = { + isa = PBXGroup; + children = ( + F6A251B9260B697300132DEC /* Double+Rounded.swift */, + ); + path = Numbers; + sourceTree = "<group>"; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -197,6 +211,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + F6A251BA260B697300132DEC /* Double+Rounded.swift in Sources */, + F6A251BE260B699100132DEC /* String+Extended.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -353,6 +369,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = AppleLibs/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -379,6 +396,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = AppleLibs/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -395,6 +413,7 @@ F6A251AE260B670000132DEC /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = GSS77QYM85; INFOPLIST_FILE = AppleLibsTests/Info.plist; @@ -413,6 +432,7 @@ F6A251AF260B670000132DEC /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = GSS77QYM85; INFOPLIST_FILE = AppleLibsTests/Info.plist; diff --git a/AppleLibs/Numbers/Double+Rounded.swift b/AppleLibs/Numbers/Double+Rounded.swift new file mode 100644 index 0000000..0f9e1c6 --- /dev/null +++ b/AppleLibs/Numbers/Double+Rounded.swift @@ -0,0 +1,17 @@ +// +// Double+Rounded.swift +// AppleLibs +// +// Created by Tobias on 24.03.21. +// + +import Foundation + +public extension Double { + func rounded(rule: NSDecimalNumber.RoundingMode, scale: Int) -> Double { + var result: Decimal = 0 + var decimalSelf = NSNumber(value: self).decimalValue + NSDecimalRound(&result, &decimalSelf, scale, rule) + return (result as NSNumber).doubleValue + } +} diff --git a/AppleLibs/String+Extended.swift b/AppleLibs/String+Extended.swift new file mode 100644 index 0000000..f867d30 --- /dev/null +++ b/AppleLibs/String+Extended.swift @@ -0,0 +1,26 @@ +// +// String+Extended.swift +// AppleLibs +// +// Created by Tobias on 24.03.21. +// + +import UIKit + +public extension String { + var htmlToAttributedString: NSMutableAttributedString? { + guard let data = data(using: .utf8) else { return nil } + do { + let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [ + .documentType: NSAttributedString.DocumentType.html, + .characterEncoding: String.Encoding.utf8.rawValue + ] + return try NSMutableAttributedString(data: data, options: options, documentAttributes: nil) + } catch { + return nil + } + } + var htmlToString: String { + return htmlToAttributedString?.string ?? "" + } +} -- GitLab