This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Refs: | |
| - https://blog.devgenius.io/async-image-loading-its-combine-way-be203eae12f7 | |
| - https://www.fivestars.blog/articles/design-system-composing-views | |
| - https://sarunw.com/posts/how-to-initialize-stateobject-with-parameters-in-swiftui | |
| - https://www.simpleswiftguide.com/how-to-use-sf-symbols-in-swiftui | |
| */ | |
| //--- VIEW MODEL | |
| import Combine |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Debouncer { | |
| private var task: DispatchWorkItem? | |
| func perform(after interval: TimeInterval = 0.5, handler: @escaping ()->Void) { | |
| cancel() | |
| let task = DispatchWorkItem(block: handler) | |
| DispatchQueue.global().asyncAfter(deadline: .now() + interval, execute: task) | |
| self.task = task |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| static func randomLetters(ranged range: ClosedRange<Int>) -> String { | |
| var randomCharacter: Character { | |
| let range: ClosedRange<UInt16> = (97...122) | |
| let unicode: Unicode.Scalar = .init(range.randomElement()!)! | |
| let character = Character(unicode) | |
| return character | |
| } | |
| let upperBound = range.randomElement()! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var url: URL? { | |
| let input = "Lorem ipsum dolor https://www.google.com" | |
| let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) | |
| let matches = detector.matches(in: input, | |
| options: [], | |
| range: NSRange(location: 0, length: input.utf16.count)) | |
| var urlString = "" | |
| for match in matches { | |
| guard let range = Range(match.range, in: input) else { continue } | |
| urlString = String(input[range]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //--------------------- | |
| //SORTER IMPLEMENTATION: | |
| protocol Sorter { | |
| typealias OrderingHandler<Element> = (Element, Element) throws -> Bool | |
| func sort<Element>(_ array: inout [Element], by areInIncreasingOrder: OrderingHandler<Element>) rethrows | |
| } | |
| extension Array { | |
| mutating func sort(using sorter: Sorter, by areInIncreasingOrder: (Element, Element) throws -> Bool) rethrows { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Ref: https://www.youtube.com/watch?v=o4bAoo_gFBU | |
| var array = [16,14,5,6,8] | |
| for i in 0..<array.count - 1 { | |
| var didSwap = false | |
| for j in 0..<array.count - 1 - i { | |
| let (firstIndex, secondIndex) = (j, j + 1) | |
| if array[firstIndex] > array[secondIndex] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ssh-keygen -t ed25519 -C "<YOUR_EMAIL_ADDRESS>" | |
| git clone <SSH_LINK> | |
| //if above did not work then check which ssh filename is being used with github: | |
| ssh -vT git@github.com | |
| ssh-add -K <PATH OF SSH PRIVATE KEY> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Ref: https://medium.com/@cboynton/todo-make-your-notes-on-xcode-stand-out-5f5124ec064c | |
| TAGS="TODO:|FIXME:" | |
| ERRORTAG="ERROR:" | |
| find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Ref: | |
| - https://developer.apple.com/documentation/uikit/view_controllers/creating_a_custom_container_view_controller | |
| - https://www.swiftbysundell.com/basics/child-view-controllers | |
| */ | |
| extension UIViewController { | |
| func embed(child: UIViewController, in container: UIView) { | |
| guard container.subviews.contains(child.view) == false else { return } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| xcrun simctl list | |
| xcrun simctl erase <device UDID> | |
| xcrun simctl erase all | |
| sudo rm -rf /Library/Developer/CommandLineTools | |
| sudo xcode-select --install |