Skip to content

Instantly share code, notes, and snippets.

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])
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
class AlphabetComponent: NSObject {
var labelName = ""
var orderIdentifier = 0
}
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)
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" }
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
guard let results = request?.results, results.count > 0 else {
busyPerformingVisionRequest = false
return
}
...
/// ↓ Make the array of CGRects here ↓
var rectangles = [CGRect]()
...
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)
}
...
/// We need to call placeHighlights on the main queue because it involves changing the UI
/// ↓ Add this ↓
DispatchQueue.main.async {
self.placeHighlights(atTheseLocations: rectangles)
}
...
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: {
//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