extension of utility

This commit is contained in:
Christiano, Kevin 2021-08-03 17:38:30 +00:00 committed by Pfeil, Scott Robert
parent 50d30b08e5
commit 54651b0a65
2 changed files with 65 additions and 0 deletions

View File

@ -121,6 +121,7 @@
0AE98BB323FF0934004C5109 /* ExternalLinkModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB223FF0934004C5109 /* ExternalLinkModel.swift */; };
0AE98BB523FF18D2004C5109 /* Arrow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB423FF18D2004C5109 /* Arrow.swift */; };
0AE98BB723FF18E9004C5109 /* ArrowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AE98BB623FF18E9004C5109 /* ArrowModel.swift */; };
0AF60F0926B3316E00AC3DB4 /* MVMCoreUIUtility+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0AF60F0826B3316E00AC3DB4 /* MVMCoreUIUtility+Extension.swift */; };
1D6D258826899B0C00DEBB08 /* ImageButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6D258626899B0B00DEBB08 /* ImageButtonModel.swift */; };
1D6D258926899B0C00DEBB08 /* ImageButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D6D258726899B0B00DEBB08 /* ImageButton.swift */; };
279B1569242BBC2F00921D6C /* ActionModelAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */; };
@ -689,6 +690,7 @@
0AE98BB223FF0934004C5109 /* ExternalLinkModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalLinkModel.swift; sourceTree = "<group>"; };
0AE98BB423FF18D2004C5109 /* Arrow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arrow.swift; sourceTree = "<group>"; };
0AE98BB623FF18E9004C5109 /* ArrowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArrowModel.swift; sourceTree = "<group>"; };
0AF60F0826B3316E00AC3DB4 /* MVMCoreUIUtility+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIUtility+Extension.swift"; sourceTree = "<group>"; };
1D6D258626899B0B00DEBB08 /* ImageButtonModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageButtonModel.swift; path = MVMCoreUI/Atomic/Atoms/Buttons/ImageButtonModel.swift; sourceTree = SOURCE_ROOT; };
1D6D258726899B0B00DEBB08 /* ImageButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageButton.swift; path = MVMCoreUI/Atomic/Atoms/Buttons/ImageButton.swift; sourceTree = SOURCE_ROOT; };
279B1568242BBC2F00921D6C /* ActionModelAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModelAdapter.swift; sourceTree = "<group>"; };
@ -2073,6 +2075,7 @@
D29DF2A721E7B2F9003B2FB9 /* MVMCoreUIConstants.h */,
D29DF2A821E7B2F9003B2FB9 /* MVMCoreUIConstants.m */,
0A41BA6D2344FCD400D4C0BC /* CATransaction+Extension.swift */,
0AF60F0826B3316E00AC3DB4 /* MVMCoreUIUtility+Extension.swift */,
);
path = Utility;
sourceTree = "<group>";
@ -2536,6 +2539,7 @@
5248BFED23F12E350059236A /* ListThreeColumnPlanDataDividerModel.swift in Sources */,
AA0A257824766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift in Sources */,
0A5D59C223AD2F5700EFD9E9 /* AppleGuidelinesProtocol.swift in Sources */,
0AF60F0926B3316E00AC3DB4 /* MVMCoreUIUtility+Extension.swift in Sources */,
8D070BB0241B56530099AC56 /* ListRightVariableTotalDataModel.swift in Sources */,
943784F5236B77BB006A1E82 /* Wheel.swift in Sources */,
D23A90682614B0B4007E14CE /* CoreUIModelMapping.swift in Sources */,

View File

@ -0,0 +1,61 @@
//
// CoureUIUtility.swift
// MVMCoreUI
//
// Created by Kevin Christiano on 7/29/21.
// Copyright © 2021 Verizon Wireless. All rights reserved.
//
import UIKit
public extension MVMCoreUIUtility {
/// Finds a view by a given type.
/// - Parameters:
/// - type: The type you are looking for.
/// - views: The starting array of subviews.
/// - Returns: If found, the first view matching the type will be casted to it and returned; otherwise nil will be returned.
static func findView<T>(by type: T.Type, views: [UIView]) -> T? {
guard !views.isEmpty else { return nil }
var queue = [UIView]()
// Reversed the array to first check views at the front.
for view in views {
if view is T {
return view as? T
}
queue.append(contentsOf: view.subviews)
}
return findView(by: type, views: queue)
}
/// Finds an array of views assocaited with a given type.
/// - Parameters:
/// - type: The type you are looking for.
/// - views: The starting array of subviews.
/// - Returns: Will return an array of any view associated with the given type. Will return an empty array of none were found.
static func findViews<T>(by type: T.Type, views: [UIView]) -> [T] {
guard !views.isEmpty else { return [] }
var queue = [UIView]()
var matching = [T]()
// Reversed the array to first check views at the front.
for view in views {
if view is T {
matching.append(view as! T)
}
queue.append(contentsOf: view.subviews)
}
return findViews(by: type, views: queue) + matching
}
}