Skip to content

Instantly share code, notes, and snippets.

// Download the "video GIF"
let data = try! Data(contentsOf: URL(string: "https://thumbs.gfycat.com/ThankfulLawfulAsianelephant-mobile.mp4")!)
let fileName = String(format: "%@_%@", ProcessInfo.processInfo.globallyUniqueString, "html5gif.mp4")
let url = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName)
try! data.write(to: url, options: [.atomic])
// Do the converties
let asset = AVURLAsset(url: url)
guard let reader = try? AVAssetReader(asset: asset) else {
return
import UIKit
import AsyncDisplayKit
class CommentPreviewViewController: ASViewController<ASDisplayNode> {
let rootNode = ASDisplayNode()
let textNode = ASTextNode()
init() {
super.init(node: rootNode)
class TextAndImageActivityItemSource: NSObject, UIActivityItemSource {
let text: String
let image: UIImage
init(text: String, image: UIImage) {
self.text = text
self.image = image
}
func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
import UIKit
class RootViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let text = "Cute cat"
let image = UIImage(named: "cat.jpg")!
// Note: you can't wrap the text and image into a single "TextImage" object and selectively return both or one as UIActivityItemSource doesn't like holding arrays
@christianselig
christianselig / awards.json
Created August 3, 2020 19:37
Reddit Awards JSON listing
{
"data":{
"subredditInfoById":{
"sortedUsableAwards":[
{
"total":0,
"award":{
"awardType":"GLOBAL",
"awardSubType":"GLOBAL",
"coinPrice":500,
@christianselig
christianselig / reddit.swift
Created August 12, 2020 16:50
An attempt at parsing Reddit using Codable
class RedditManager {
static let shared = RedditManager()
private let session: URLSession
private init() {
let configuration = URLSessionConfiguration.default
session = URLSession(configuration: configuration)
}
@christianselig
christianselig / tableview-insert.swift
Created November 29, 2020 21:51
Trying to figure out how to insert a UITableViewCell above while maintaining scroll position
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView(frame: CGRect.zero, style: .plain)
var totalSubtracted = 0
override func viewDidLoad() {
super.viewDidLoad()
@christianselig
christianselig / ios-tableview-add.swift
Created November 30, 2020 01:16
I want to add a new cell to the top of the table view without causing the current position to be pushed down. Note that I'm also not removing the cell I would like to add to the top, but rather just also adding it to the top.
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView(frame: CGRect.zero, style: .plain)
var totalAdded = 0
override func viewDidLoad() {
super.viewDidLoad()
@christianselig
christianselig / table-insert.swift
Created November 30, 2020 18:29
Trying to insert a table view cell at the top, without offsetting the current scroll position and causing a jump. Insert occurs when you tap one of the star accessory views, and seems due to the two different types of cells used in the table.
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let tableView = UITableView(frame: CGRect.zero, style: .plain)
var totalAdded = 0
override func viewDidLoad() {
super.viewDidLoad()
@christianselig
christianselig / catalyst-problem.md
Created December 9, 2020 18:10
Unable to get Catalyst to work with a few Cocoapods dependencies

I have a few dependencies for a project (managed via Cocoapods) that I'm having trouble getting to compile under Catalyst, but compile fine for iOS.

Steps to Reproduce

  1. Create new Xcode project
  2. Create Podfile with two pods: "DTCoreText" (an HTML parser) and "Mantle" (helps with object modeling), so something like this:
platform :ios, '12.0'