Skip to content

Instantly share code, notes, and snippets.

View KaneCheshire's full-sized avatar

Kane Cheshire KaneCheshire

View GitHub Profile
import UIKit
protocol AccessibilityModel {
/// Whether the view should be an accessibility element
var isAccessibilityElement: Bool { get }
/// An optional accessibility label. This is read out by VoiceOver as
/// soon as the VoiceOver cursor focuses on the accessibility element.
///
struct CellViewModel: AccessibilityModel {
// Standard view model properties
// that we use to populate a cell
let titleString: String
let subtitleString: String
let actionString: String
// AccessibilityModel properties
extension UIView {
func updateAccessibility(with accessibilityModel: AccessibilityModel) {
self.isAccessibilityElement = accessibilityModel.isAccessibilityElement
self.accessibilityLabel = accessibilityModel.accessibilityLabel
self.accessibilityHint = accessibilityModel.accessibilityHint
self.accessibilityIdentifier = accessibilityModel.accessibilityIdentifier
self.accessibilityTraits = accessibilityModel.accessibilityTraits
}
final class Cell: UICollectionViewCell {
@IBOutlet private var titleLabel: UILabel!
@IBOutlet private var subtitleLabel: UILabel!
@IBOutlet private var actionLabel: UILabel!
func configure(with viewModel: CellViewModel) {
// Populate labels with the view model like always
self.titleLabel.text = viewModel.titleString
class CustomCell: UICollectionViewCell {
@IBOutlet private var contentView: UIView! // Subview of `self`
@IBOutlet private var titleLabel: UIView! // Subview of `contentView`
@IBOutlet private var subtitleLabel: UIView! // Subview of `contentView`
@IBOutlet private var actionLabel: UIView! // Subview of `contentView`
}
class CustomCell: UICollectionViewCell {
@IBOutlet private var contentView: UIView! // Subview of `self`
@IBOutlet private var titleLabel: UIView! // Subview of `contentView`
@IBOutlet private var subtitleLabel: UIView! // Subview of `contentView`
@IBOutlet private var actionLabel: UIView! // Subview of `contentView`
private func setupAccessibility() {
contentView.isAccessibilityElement = true
class CustomCell: UICollectionViewCell {
@IBOutlet private var contentView: UIView! // Subview of `self`
@IBOutlet private var titleLabel: UIView! // Subview of `contentView`
@IBOutlet private var subtitleLabel: UIView! // Subview of `contentView`
@IBOutlet private var actionLabel: UIView! // Subview of `contentView`
private func setupAccessibility() {
contentView.isAccessibilityElement = true
let manager = CLLocationManager()
manager.requestWhenInUseAuthorization()
manager.requestAlwaysAuthorization()
// - Significant change monitoring:
manager.startMonitoringSignificantLocationChanges()
// - Visit monitoring:
manager.startMonitoringVisits()
// - Region monitoring:
manager.startMonitoring(for: CLCircularRegion())
manager.allowsBackgroundLocationUpdates = true