Skip to content

Instantly share code, notes, and snippets.

View stevencurtis's full-sized avatar

Steven Curtis stevencurtis

View GitHub Profile
import SwiftUI
public extension Text {
init(_ attributedString: NSAttributedString) {
if #available(iOS 15.0, *) {
self.init(AttributedString(attributedString))
} else {
self.init("") // initial, empty Text
// scan the attributed string for distinctly attributed regions
import UIKit
import DataProvider
final class CurrentPlanDataSource: NSObject {
// MARK: - Cell -
enum Cell {
case daysLeft(daysLeft: Int, endDate: Date, newPlan: String?, currentPlanTitle: String)
case cancelDowngrade(previousPlanTitle: String)
class BasicFlowLayoutViewModel {
var sectionAdata = [UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.systemPink]
var sectionBdata = [UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green]
}
class BasicFlowLayoutViewController: UIViewController {
enum Constants {
static let reuseCell = "subclassedcell"
static let reuseHeader = "header"
}
override func loadView() {
collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
self.view = collectionView
}
extension BasicFlowLayoutViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 15, bottom: 100, right: 15)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let noOfCellsInRow = 2
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
let totalSpace = flowLayout.sectionInset.left
+ flowLayout.sectionInset.right
final class BasicUICollectionViewModel {
var data = [UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.systemPink, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.green, UIColor.red, UIColor.green, UIColor.blue, UIColor.green, UIColor.purple, UIColor.orange, UIColor.blue, UIColor.green, UIColor.blue, UIColor.systemPink]
}
final class BasicUICollectionViewController: UIViewController {
enum Constants {
static let reuseCell = "subclassedcell"
}
var collectionView: UICollectionView!
let viewModel: BasicUICollectionViewModel
override func loadView() {
collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
let dogHandler = DogHandler()
let wolfHandler = WolfHandler()
let elephantHandler = ElephantHandler()
dogHandler.next = wolfHandler
wolfHandler.next = elephantHandler
dogHandler.handle(request: Animal.cat) // handled by the dog handler
dogHandler.handle(request: Animal.elephant) // handled by the elephant handler
class DogHandler: Handler {
func handle(request: Animal) {
if request > .dog {
next?.handle(request: request)
} else {
print ("Handled by the dog handler")
}
}
var next: Handler?
protocol Handler {
var next: Handler? { get }
func handle(request: Animal)
}