Forked from cellularmitosis/EmojiPointersDemo.swift
Created
September 19, 2018 17:13
-
-
Save streeter/44454fec7c017e8b3c65cfa191d4adb6 to your computer and use it in GitHub Desktop.
Representing pointer values as emoji can be useful for "visually" debugging certain issues, like cell reuse, etc.
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
DEBUG: populating cell 0x00007fa2ec02e800 π’ | |
DEBUG: populating cell 0x00007fa2ec018a00 π₯ | |
DEBUG: populating cell 0x00007fa2eb005000 π | |
DEBUG: populating cell 0x00007fa2ec018a00 π₯ | |
DEBUG: populating cell 0x00007fa2ec02e800 π’ | |
DEBUG: populating cell 0x00007fa2ec032c00 π© | |
DEBUG: populating cell 0x00007fa2ec030600 π | |
DEBUG: populating cell 0x00007fa2ec033200 π | |
DEBUG: populating cell 0x00007fa2e98b2000 π | |
DEBUG: populating cell 0x00007fa2e9815600 π’ | |
DEBUG: populating cell 0x00007fa2e98b3000 π | |
DEBUG: populating cell 0x00007fa2e98b3600 π΅ | |
DEBUG: populating cell 0x00007fa2e9883000 π | |
DEBUG: populating cell 0x00007fa2e9883600 π₯ | |
DEBUG: populating cell 0x00007fa2e9881000 π | |
DEBUG: populating cell 0x00007fa2e9883600 π₯ | |
DEBUG: populating cell 0x00007fa2e9883000 π | |
DEBUG: populating cell 0x00007fa2e98b3600 π΅ | |
DEBUG: populating cell 0x00007fa2e9815600 π’ | |
DEBUG: populating cell 0x00007fa2e98b3000 π | |
DEBUG: populating cell 0x00007fa2e98b2000 π | |
DEBUG: populating cell 0x00007fa2ec033200 π | |
DEBUG: populating cell 0x00007fa2ec030600 π | |
DEBUG: populating cell 0x00007fa2ec032c00 π© | |
DEBUG: populating cell 0x00007fa2ec02e800 π’ | |
DEBUG: populating cell 0x00007fa2ec018a00 π₯ |
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 UIKit | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
let window = UIWindow(frame: UIScreen.main.bounds) | |
window.makeKeyAndVisible() | |
window.rootViewController = ViewController() | |
self.window = window | |
return true | |
} | |
} | |
class ViewController: UITableViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "\(UITableViewCell.self)") | |
} | |
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(withIdentifier: "\(UITableViewCell.self)", for: indexPath) | |
print("DEBUG: populating cell \(cell.asPointer) \(cell.asPointer.asEmoji)") | |
cell.textLabel?.text = "\(indexPath) \(cell.asPointer.asEmoji)" | |
return cell | |
} | |
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 100 | |
} | |
} | |
extension NSObject { | |
public var asPointer: UnsafeMutableRawPointer { | |
return Unmanaged.passUnretained(self).toOpaque() | |
} | |
} | |
extension UnsafeMutableRawPointer { | |
public var asEmoji: String { | |
// Adapted from https://gist.github.com/iandundas/59303ab6fd443b5eec39 | |
// Tweak the range to your liking. | |
//let range = 0x1F600...0x1F64F | |
let range = 0x1F300...0x1F3F0 | |
let index = (self.hashValue % range.count) | |
let ord = range.lowerBound + index | |
guard let scalar = UnicodeScalar(ord) else { | |
return "β" | |
} | |
return String(scalar) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment