Skip to content

Instantly share code, notes, and snippets.

func asynchronouslyLoadURLAssets(_ newAsset: AVURLAsset) {
DispatchQueue.main.async {
newAsset.loadValuesAsynchronously(forKeys: self.assetKeysRequiredToPlay) {
for key in self.assetKeysRequiredToPlay {
var error: NSError?
if newAsset.statusOfValue(forKey: key, error: &error) == .failed {
self.delegate?.playerDidFailToPlay(message: "Can't use this AVAsset because one of it's keys failed to load")
return
}
}
func cleanExpiredVideos() {
let currentTimeStamp = Date().timeIntervalSince1970
var expiredKeys: [String] = []
for videoData in videosDict where currentTimeStamp - videoData.value.timeStamp >= expiryTime {
// video is expired. delete
if let _ = popupVideosDict[videoData.key] {
expiredKeys.append(videoData.key)
}
}
for key in expiredKeys {
func isStorageAvailable() -> Bool {
let fileURL = URL(fileURLWithPath: NSHomeDirectory() as String)
do {
let values = try fileURL.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey, .volumeTotalCapacityKey])
guard let totalSpace = values.volumeTotalCapacity,
let freeSpace = values.volumeAvailableCapacityForImportantUsage else {
return false
}
if freeSpace > minimumSpaceRequired {
return true
@Composable
fun ApplyButton(
text: String,
modifier: Modifier = Modifier,
applicable: Boolean = false,
spanStyle: SpanStyle,
paragraphStyle: ParagraphStyle,
style: TextStyle,
onClick: () -> Unit
) {
@agammahajan1
agammahajan1 / item_cell.swift
Created September 30, 2021 13:05
Change item cell UI
if UIAccessibility.isVoiceOverRunning {
// add cart button in item cell
}
@agammahajan1
agammahajan1 / cutom-actions.swift
Last active August 29, 2021 21:51
Custom Actions handling in Food item
let addItemAction = UIAccessibilityCustomAction(name: "Add one quantity of this item.") { [weak self] _ in
// add 1 quantity of the item selected
UIAccessibility.post(notification: .announcement, argument: "Item added, total number of items in cart now is \(noOfItems) with a subtotal of \(cartTotal) rupees")
}
let removeItemAction = UIAccessibilityCustomAction(name: "Remove one quantity of this item.") { [weak self] _ in
if itemsInCart {
//remove 1 quantity of the item selected
if noOfItems == 0 {
UIAccessibility.post(notification: .announcement, argument: "Item removed, no items in cart now")
UIAccessibility.post(notification: .announcement,
argument: "Location has changed to JP Nagar")
@agammahajan1
agammahajan1 / images.swift
Created August 29, 2021 21:10
Add alt text to the image view
imageView.isAccessibilityElement = true
imageView.accessibilityLabel = dataSource.accessibility.altText
@agammahajan1
agammahajan1 / grouping.swift
Created August 29, 2021 19:17
Grouping of view
cell.isAccessibilityElement = true
cell.accessibilityLabel = restaurantName + rating + offer
extension URL {
var attributes: [FileAttributeKey : Any]? {
do {
return try FileManager.default.attributesOfItem(atPath: path)
} catch let error as NSError {
print("FileAttribute error: \(error)")
}
return nil
}