Skip to content

Instantly share code, notes, and snippets.

View scottfister's full-sized avatar

Scotty scottfister

  • Apple
  • San Francisco
View GitHub Profile
override func configurationItems() -> [Any]! {
if let deck = SLComposeSheetConfigurationItem() {
deck.title = "Selected Deck"
deck.value = "Deck Title"
deck.tapHandler = {
let vc = ShareSelectViewController()
vc.userDecks = self.userDecks
self.pushConfigurationViewController(vc)
}
return [deck]
private var userDecks: [Deck]()
fileprivate var selectedDeck: Deck?
override func viewDidLoad() {
super.viewDidLoad()
for i in 1...3 {
let deck = Deck()
deck.title = "Deck \(i)"
userDecks.append(deck)
}
protocol ShareSelectViewControllerDelegate: class {
func selected(deck: Deck)
}
class ShareSelectViewController {
private lazy var tableView: UITableView = {
// ...
tableView.delegate = self
// ...
}()
//...
deck.tapHandler = {
let vc = ShareSelectViewController()
vc.userDecks = self.userDecks
vc.delegate = self
self.pushConfigurationViewController(vc)
}
//...
extension ShareViewController: ShareSelectViewControllerDelegate {
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionActivationRule</key>
<dict>
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
<integer>1</integer>
</dict>
<key>NSExtensionJavaScriptPreprocessingFile</key>
@scottfister
scottfister / .swift
Created July 27, 2021 19:44
Swift Modulate Function
public extension FloatingPoint {
typealias ModulationRange = (lowerBound: Self, upperBound: Self)
/// Translates the given floating point between two ranges.
/// Limit defaults to true. If limit is set to false, the value returned can be outside of the "to" range.
///
/// Using the Modulate function
/// ----------------------------------------------------------
/// Say you'd like to transform a view's scale from `1.0` to `0.45` depending on some other factor, like scroll amount.
/// The `from` could be `0...120` and the `to` would be`1.0...0.45`, which would mean at `0` content offset, the transform would be `1.0`