This file contains 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
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | |
if collectionView == baseCollectionView { | |
let alphabetLetter = newBaseCollectionViewArray[indexPath.item] | |
secondCollectionViewArray.append(alphabetLetter) | |
let newIndexPath = IndexPath(item: secondCollectionViewArray.count - 1, section: 0) | |
secondCollectionView.insertItems(at: [newIndexPath]) | |
newBaseCollectionViewArray.remove(at: indexPath.item) | |
baseCollectionView.deleteItems(at: [indexPath]) |
This file contains 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
//: A UIKit based Playground for presenting user interface | |
import UIKit | |
import PlaygroundSupport | |
class AlphabetComponent: NSObject { | |
var labelName = "" | |
var orderIdentifier = 0 | |
} |
This file contains 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
func convertDateToReadableString(dateToConvert: Date) -> String { | |
/// Make a date formatter object. This will take care converting Date objects to String objects and vice versa. | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = "MMddyy" /// This is a pretty good format that will yield something like "January 1, 2020" | |
let todaysDate = Date() /// When you initialize a Date object like this, the Date will be the current date. | |
let todaysDateAsString = dateFormatter.string(from: todaysDate) | |
let yesterday = todaysDate.subtract(days: 1) | |
let yesterdaysDateAsString = dateFormatter.string(from: yesterday!) | |
let oneWeekAgo = todaysDate.subtract(days: 7) |
This file contains 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 Date { | |
func convertDateToReadableString() -> String { | |
let todayString = "Today" | |
let yesterdayString = "Yesterday" | |
/// Initializing a Date object will always return the current date (including time) | |
let todaysDate = Date() | |
guard let yesterday = todaysDate.subtract(days: 1) else { return "2023" } | |
guard let oneWeekAgo = todaysDate.subtract(days: 7) else { return "2023" } |
This file contains 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
func placeHighlights(atTheseLocations rectangles: [CGRect]) { | |
/// First, we'll remove all the existing highlights in the drawingView | |
for highlight in drawingView.subviews { | |
/// Fading it out | |
UIView.animate(withDuration: 0.3, animations: { | |
highlight.alpha = 0 | |
}) { _ in |
This file contains 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
guard let results = request?.results, results.count > 0 else { | |
busyPerformingVisionRequest = false | |
return | |
} | |
... | |
/// ↓ Make the array of CGRects here ↓ | |
var rectangles = [CGRect]() | |
... |
This file contains 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
for index in indicies { | |
... | |
/// ↓ Delete this ↓ | |
/// print("\"\(originalFoundText)\" | Position: x: \(finalX), y: \(finalY), width: \(finalWidth), height: \(finalHeight)") | |
/// Todo: Step 2... place the rectangle "in real life" | |
/// ↓ Add this ↓ | |
let rect = CGRect(x: finalX, y: finalY, width: finalWidth, height: finalHeight) | |
rectangles.append(rect) |
This file contains 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
} | |
... | |
/// We need to call placeHighlights on the main queue because it involves changing the UI | |
/// ↓ Add this ↓ | |
DispatchQueue.main.async { | |
self.placeHighlights(atTheseLocations: rectangles) | |
} | |
... |
This file contains 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
func placeHighlights(atTheseLocations rectangles: [CGRect]) { | |
/// ↓ We're going to do more than just simple fade transitions, so remove or comment out the following ↓ | |
// ----------------------------------------------------------------- | |
/// First, we'll remove all the existing highlights in the drawingView | |
// for highlight in drawingView.subviews { | |
// | |
// /// Fading it out | |
// UIView.animate(withDuration: 0.3, animations: { |
This file contains 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
//MARK: Motion (Accelerometer and Gyroscope) | |
/// motionManager will be what we'll use to get device motion | |
var motionManager = CMMotionManager() | |
/// this will be the "device’s true orientation in space" (Source: https://nshipster.com/cmdevicemotion/) | |
var initialAttitude: CMAttitude? | |
/// we'll later read these values to update the highlight's position | |
var motionX = Double(0) /// aka Roll |