Skip to content

Instantly share code, notes, and snippets.

View benjaminmayo's full-sized avatar

Benjamin Mayo benjaminmayo

View GitHub Profile
@benjaminmayo
benjaminmayo / ZipSparsePairs.swift
Last active March 1, 2020 19:43
This is an example implementation of the zip sparse pairs algorithm in Swift. The sequence iterates through two sorted sequences of elements, which are then paired according to some supplied `predicate`. The sequence returns a stream of `PossiblePair` instances.
struct ZipSparsePairsSequence<A: Sequence, B: Sequence> : Sequence {
private var primary: A
private var subset: B
private let predicate: PairingPredicate
fileprivate init(primary: A, subset: B, pairingWith predicate: @escaping PairingPredicate) {
self.primary = primary
self.subset = subset
self.predicate = predicate
}
@benjaminmayo
benjaminmayo / ViewController.swift
Last active June 6, 2021 08:58
Working example of UIActivityItemProvider customising a shared URL depending on the activity type. http://benjaminmayo.co.uk/twitter-app-sharing-link-garbage
import UIKit
class ViewController : UIViewController {
// Monotonous view setup hidden. Imagine there's a button on screen that gets tapped and fires the action below.
@IBAction func shareLinkButtonPressed(_ sender: Any) {
let urlToShare = URL(string: "http://twitter.com/bzamayo")! // the base URL, in a real app this would be provided dynamically based on the current context
let sharingActivityItemProvider = LinkSharingActivityItemProvider(url: urlToShare) // make an activity item provider, defined below
let activityViewController = UIActivityViewController(activityItems: [sharingActivityItemProvider], applicationActivities: nil)