Skip to content

Instantly share code, notes, and snippets.

View maxtran88's full-sized avatar

Max Tran maxtran88

  • Mobile Health
View GitHub Profile
@maxtran88
maxtran88 / ChatCollectionViewFlowLayout.swift
Created April 3, 2020 16:42 — forked from jochenschoellig/ChatCollectionViewFlowLayout.swift
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?
@maxtran88
maxtran88 / prettyPrint.swift
Created February 20, 2019 11:33 — forked from Edudjr/prettyPrint.swift
Swift 3 JSON pretty printing
//Function to pretty-print Json Object in Swift 3
func prettyPrint(with json: [String:Any]) -> String{
let data = try! JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
let string = NSString(data: data, encoding: String.Encoding.utf8.rawValue)
return string as! String
}