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
private func renderData() { | |
let subviews = (0..<data.count).map { (index: Int) -> Someview in | |
let nib = UINib(nibName: "Someview", bundle: nil) | |
let viewArray = nib.instantiate(withOwner: nil, options: nil) | |
guard let view = viewArray.first as? Someview else { | |
return Someview() | |
} |
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
import Foundation | |
import UIKit | |
class CountdownProgressBar: UIView { | |
private var timer = Timer() | |
private var duration = 5.0 | |
private var remainingTime = 0.0 | |
private var showPulse = false |
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
import UIKit | |
private struct BlurableKey { | |
static var blurable = "blurable" | |
} | |
extension UIView { | |
func blur(blurRadius : CGFloat) { | |
if self.superview == nil { |
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
//https://www.hackingwithswift.com/quick-start/swiftui | |
//https://github.com/SimpleBoilerplates/SwiftUI-Cheat-Sheet | |
// Textfield with floating label | |
// https://medium.com/swlh/simpler-better-floating-label-textfields-in-swiftui-24f7d06da8b8 |
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 property wrapper adds a layer of separation between code | |
that manages how a property is stored and the code that defines a property | |
*/ | |
//https://docs.swift.org/swift-book/LanguageGuide/Properties.html | |
//To define a property wrapper, you make a structure, enumeration, or class that defines a wrappedValue property | |
//wrappedValue can be anything, even generic value of the struct | |
@propertyWrapper | |
struct SmallNumber { |
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 sequence is a list of values that you can step through one at a time. | |
//The most common way to iterate over the elements of a sequence is to use a for-in loop: | |
/* | |
Potentially our database could contain a large set of records, | |
and for each model we need to hit the disk to actually load its data, | |
so we don’t want to load everything at once. | |
To make this happen, we’re going to replace the array return type with our own custom sequence. | |
*/ | |
//https://www.swiftbysundell.com/articles/swift-sequences-the-art-of-being-lazy/ |
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
//https://swiftbysundell.com/articles/picking-the-right-data-structure-in-swift/ | |
/* | |
A list struct, which will keep track of the first and last nodes within our list | |
Both of those properties are read-only outside of our type, to be able to ensure data consistency | |
*/ | |
struct List<Value> { | |
private(set) var firstNode: Node? | |
private(set) var lastNode: Node? | |
} |
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
// To be able to use strings as caching keys, we have to use | |
// NSString here, since NSCache is only compatible with keys | |
// that are subclasses of NSObject: | |
let cache = NSCache<NSString, MyClass>() | |
//Problem: | |
//can only store class instances, and it’s only compatible with NSObject-based keys | |
//NSCache simple use here: | |
//https://www.hackingwithswift.com/example-code/system/how-to-cache-data-using-nscache |