diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index f793aa5..5560cfb 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -84,6 +84,7 @@ EAD062A52A3B5CDF0015965D /* Slider.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD062A42A3B5CDF0015965D /* Slider.swift */; }; EAD062AD2A3B86950015965D /* BadgeIndicatorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD062AC2A3B86950015965D /* BadgeIndicatorViewController.swift */; }; EAD068902A55FC11002E3A2D /* LoaderViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD0688F2A55FC11002E3A2D /* LoaderViewController.swift */; }; + EAEEEC942B1F824500531FC2 /* Bundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAEEEC932B1F824500531FC2 /* Bundle.swift */; }; EAF7F07D2899698800B287F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAF7F07B2899698800B287F5 /* Assets.xcassets */; }; EAF7F09C2899B92400B287F5 /* CheckboxItemViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F09B2899B92400B287F5 /* CheckboxItemViewController.swift */; }; EAF7F0CA289DA24F00B287F5 /* ArtifactoryItems.txt in Resources */ = {isa = PBXBuildFile; fileRef = EAF7F0C5289DA24F00B287F5 /* ArtifactoryItems.txt */; }; @@ -179,6 +180,7 @@ EAD062A42A3B5CDF0015965D /* Slider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Slider.swift; sourceTree = ""; }; EAD062AC2A3B86950015965D /* BadgeIndicatorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BadgeIndicatorViewController.swift; sourceTree = ""; }; EAD0688F2A55FC11002E3A2D /* LoaderViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoaderViewController.swift; sourceTree = ""; }; + EAEEEC932B1F824500531FC2 /* Bundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bundle.swift; sourceTree = ""; }; EAF7F07B2899698800B287F5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; EAF7F09B2899B92400B287F5 /* CheckboxItemViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxItemViewController.swift; sourceTree = ""; }; EAF7F0C5289DA24F00B287F5 /* ArtifactoryItems.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ArtifactoryItems.txt; sourceTree = ""; }; @@ -276,6 +278,7 @@ isa = PBXGroup; children = ( EA985C1F296DECF600F2FF2E /* IconName.swift */, + EAEEEC932B1F824500531FC2 /* Bundle.swift */, ); path = Extensions; sourceTree = ""; @@ -496,6 +499,7 @@ EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */, EA5E3050294D11540082B959 /* TileContainerViewController.swift in Sources */, 445BA07A29C088470036A7C5 /* NotificationViewController.swift in Sources */, + EAEEEC942B1F824500531FC2 /* Bundle.swift in Sources */, EAF7F11A28A14A0E00B287F5 /* RadioButtonGroupViewController.swift in Sources */, EA89204628B66CE2006B9984 /* ScrollViewController.swift in Sources */, EA471F402A97BEAA00CE9E58 /* CustomRotorable.swift in Sources */, diff --git a/VDSSample/Extensions/Bundle.swift b/VDSSample/Extensions/Bundle.swift new file mode 100644 index 0000000..d73f7d7 --- /dev/null +++ b/VDSSample/Extensions/Bundle.swift @@ -0,0 +1,51 @@ +// +// Bundle.swift +// VDSSample +// +// Created by Matt Bruce on 12/5/23. +// + +import Foundation +import VDS + +extension Bundle { + var versionNumber: String? { + infoDictionary?["CFBundleShortVersionString"] as? String + } + var buildNumber: String? { + infoDictionary?["CFBundleVersion"] as? String + } + + var build: String? { + guard let versionNumber, let buildNumber else { return nil } + return "\(versionNumber).\(buildNumber)" + } + + func contents(_ fileName: String, fileExtension: String = "txt" ) -> String? { + guard let fileURL = url(forResource: fileName, withExtension: fileExtension) else { return nil } + do { + return try String(contentsOf: fileURL) + } catch { + print("error reading releaseNotes") + return "none" + } + } +} + +struct VDSHelper { + static var bundle: Bundle { + VDS.Bundle(for: VDS.Badge.self) + } + + static var version: String { + bundle.versionNumber ?? "" + } + + static func releaseNotes() -> String { + return bundle.contents("ReleaseNotes") ?? "" + } + + static func changeLog(for component: ViewProtocol.Type) -> String? { + return bundle.contents("\(component.self)ChangeLog") + } +} diff --git a/VDSSample/ViewControllers/BaseViewController.swift b/VDSSample/ViewControllers/BaseViewController.swift index dbe9d2f..3fd5137 100644 --- a/VDSSample/ViewControllers/BaseViewController.swift +++ b/VDSSample/ViewControllers/BaseViewController.swift @@ -172,6 +172,14 @@ public class BaseViewController: UIViewController, Initable , open override func viewDidLoad() { super.viewDidLoad() + + if let component = component as? ViewProtocol, let content = VDSHelper.changeLog(for: type(of: component)) { + let tooltip = VDS.Tooltip() + tooltip.title = "ChangeLog" + tooltip.content = content + navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip) + } + view.backgroundColor = .white // Add the top and bottom views to the stack view stackView.addArrangedSubview(contentTopView.makeWrapper(edgeSpacing: 16, isTrailing: false)) diff --git a/VDSSample/ViewControllers/MenuViewController.swift b/VDSSample/ViewControllers/MenuViewController.swift index 05e0909..753b294 100644 --- a/VDSSample/ViewControllers/MenuViewController.swift +++ b/VDSSample/ViewControllers/MenuViewController.swift @@ -106,10 +106,9 @@ class MenuViewController: UITableViewController, TooltipLaunchable { override func viewDidLoad() { title = "VDS Sample: Build \(Bundle.main.build ?? "none")" let tooltip = VDS.Tooltip() - let bundle = VDS.Bundle(for: VDS.Badge.self) - tooltip.title = "Release Notes: \(bundle.build ?? "")" - tooltip.content = bundle.contents("ReleaseNotes") - navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip) // UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(buildInfoTapped)) + tooltip.title = "Release Notes: \(VDSHelper.version)" + tooltip.content = VDSHelper.releaseNotes() + navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip) super.viewDidLoad() overrideUserInterfaceStyle = .light tableView.register(MenuCell.self, forCellReuseIdentifier: "cell") @@ -167,27 +166,3 @@ class MenuViewController: UITableViewController, TooltipLaunchable { } } } - -extension Bundle { - var versionNumber: String? { - infoDictionary?["CFBundleShortVersionString"] as? String - } - var buildNumber: String? { - infoDictionary?["CFBundleVersion"] as? String - } - - var build: String? { - guard let versionNumber, let buildNumber else { return nil } - return "\(versionNumber).\(buildNumber)" - } - - func contents(_ fileName: String, fileExtension: String = "txt" ) -> String { - guard let fileURL = url(forResource: fileName, withExtension: fileExtension) else { return "none" } - do { - return try String(contentsOf: fileURL) - } catch { - print("error reading releaseNotes") - return "none" - } - } -}