Instantly share code, notes, and snippets.
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
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` |
scottfister
/ share-extension-info.plist
Last active
April 26, 2017 18:39
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
<key>NSExtension</key> | |
<dict> | |
<key>NSExtensionAttributes</key> | |
<dict> | |
<key>NSExtensionActivationRule</key> | |
<dict> | |
<key>NSExtensionActivationSupportsWebURLWithMaxCount</key> | |
<integer>1</integer> | |
</dict> | |
<key>NSExtensionJavaScriptPreprocessingFile</key> |
scottfister
/ share-extension-12.swift
Last active
April 25, 2017 15:56
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
//... | |
deck.tapHandler = { | |
let vc = ShareSelectViewController() | |
vc.userDecks = self.userDecks | |
vc.delegate = self | |
self.pushConfigurationViewController(vc) | |
} | |
//... | |
extension ShareViewController: ShareSelectViewControllerDelegate { |
scottfister
/ share-extension-11.swift
Last active
April 25, 2017 15:54
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
protocol ShareSelectViewControllerDelegate: class { | |
func selected(deck: Deck) | |
} | |
class ShareSelectViewController { | |
private lazy var tableView: UITableView = { | |
// ... | |
tableView.delegate = self | |
// ... | |
}() |
scottfister
/ share-extension-10.swift
Last active
April 25, 2017 04:22
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 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) | |
} |
scottfister
/ share-extension-9.swift
Last active
April 25, 2017 04:14
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
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] |
scottfister
/ share-extension-8.swift
Last active
April 25, 2017 04:22
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 var userDecks = [Deck]() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
for i in 1...3 { | |
let deck = Deck() | |
deck.title = "Deck \(i)" | |
userDecks.append(deck) | |
} | |
// ... |
scottfister
/ share-extension-7.swift
Created
April 17, 2017 17:25
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
extension ShareSelectViewController: UITableViewDataSource { | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return userDecks.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: Identifiers.DeckCell, for: indexPath) | |
cell.textLabel?.text = userDecks[indexPath.row].title | |
cell.backgroundColor = .clear | |
return cell | |
} |
scottfister
/ share-extension-6.swift
Last active
November 24, 2017 02:46
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
lazy var tableView: UITableView = { | |
let tableView = UITableView(frame: self.view.frame) | |
tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight] | |
tableView.dataSource = self | |
tableView.backgroundColor = .clear | |
tableView.register(UITableViewCell.self, forCellReuseIdentifier: Identifiers.DeckCell) | |
return tableView | |
}() | |
override func viewDidLoad() { |
scottfister
/ share-extension-5.swift
Created
April 17, 2017 17:17
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
final class Deck { | |
var id: String? | |
var title: String? | |
} |
NewerOlder