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
CGFloat ScaleToAspectFitRectInRect(CGRect rfit, CGRect rtarget) | |
{ | |
// first try to match width | |
CGFloat s = CGRectGetWidth(rtarget) / CGRectGetWidth(rfit); | |
// if we scale the height to make the widths equal, does it still fit? | |
if (CGRectGetHeight(rfit) * s <= CGRectGetHeight(rtarget)) { | |
return s; | |
} | |
// no, match height instead | |
return CGRectGetHeight(rtarget) / CGRectGetHeight(rfit); |
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
1. Install Xcode (available in the Mac App Store) | |
2. Install [Brew](https://brew.sh) | |
3. Install [Cocoapods](https://cocoapods.org) | |
4. Install [Fastlane](https://docs.fastlane.tools) | |
5. In Xcode, make sure that under Preferences/Locations the Command Line Tools field is not empty | |
6. Add provisoning profiles and certificates | |
7. Install [Buildkite agent](https://buildkite.com/docs/agent/v3/osx) | |
* `brew tap buildkite/buildkite` | |
* `brew install --token='INSERT-YOUR-AGENT-TOKEN-HERE' buildkite-agent` | |
* Run `brew info buildkite-agent` and execute the command displayed at the end to autostart the agent |
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
// Swift's `Task` silently discards errors from throwable callsites. `SafeTask` forces you to explicitly handle errors at the callsite and helps you avoid mistakes with silently discarded errors. | |
@discardableResult func SafeTask<Success>(priority: TaskPriority? = nil, operation: @escaping () async -> Success) -> Task<Success, Never> where Success: Sendable { | |
return Task(priority: priority, operation: { | |
await operation() | |
}) | |
} |
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 | |
// Based on https://www.swiftbysundell.com/articles/caching-in-swift/ | |
final class Cache<Key: Hashable, Value> { | |
private let wrapped = NSCache<WrappedKey, Entry>() | |
func insert(_ value: Value, forKey key: Key) { | |
let entry = Entry(value: value) | |
wrapped.setObject(entry, forKey: WrappedKey(key)) |
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 | |
/** | |
Limits the rate at which a closure is executed by preventing it's execution until a specified amount of time has elapsed. | |
Example: | |
``` | |
let fetchThrottle = Throttle(interval: 60) | |
fetchThrottle { |
OlderNewer