Skip to content

Instantly share code, notes, and snippets.

View lamlv2305's full-sized avatar

Lam Luong Van lamlv2305

View GitHub Profile
{
"files.associations": {
".eslintrc": "javascriptreact",
"./build/**": "plaintext",
"./public/az/**": "plaintext"
},
"editor.tabSize": 2,
"editor.suggestSelection": "first",
"editor.codeActionsOnSave": {
// For ESLint
@lamlv2305
lamlv2305 / TableViewContentInset.swift
Created November 15, 2018 07:49
Update UITableView/UICollectionView content insets inside nib of UITabBarController
if #available(iOS 11, *) {
// do nothing
} else {
let tableInset: () -> UIEdgeInsets = { [weak self] in
let frame = self?.navigationController?.navigationBar.frame
let topInset = [frame?.origin.y, frame?.height].compactMap { $0 }.reduce(0, +)
let bottomInset = self?.tabBarController?.tabBar.frame.height ?? 0
return UIEdgeInsets(top: topInset, left: 0, bottom: bottomInset, right: 0)
}
1. Add symbolic breakpoint
2. Symbol: -[UIViewController dealloc]
3. Add 2 action, Log Message and Sound
4. Edit command on Log Message Action:
--- dealloc @(id)[$arg1 description]@ @(id)[$arg1 title]@
@lamlv2305
lamlv2305 / build-framework-post-action-script.sh
Created June 18, 2018 02:43
Build fat framework post action.
exec > /tmp/${PROJECT_NAME}_archive.log 2>&1
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
if [ "true" == ${ALREADYINVOKED:-false} ]
then
echo "RECURSION: Detected, stopping"
else
export ALREADYINVOKED="true"
func sizeOfString (string: String, constrainedToWidth width: Double) -> CGSize {
let attributes = [NSFontAttributeName:self,]
let attString = NSAttributedString(string: string,attributes: attributes)
let framesetter = CTFramesetterCreateWithAttributedString(attString)
return CTFramesetterSuggestFrameSizeWithConstraints(framesetter, CFRange(location: 0,length: 0), nil, CGSize(width: width, height: DBL_MAX), nil)
}
/**
* Require
* Copyright (c) John Sundell 2017
* Licensed under the MIT license. See LICENSE file.
*/
import Foundation
public extension Optional {
/**
@lamlv2305
lamlv2305 / AutoclosureExample.swift
Created January 9, 2018 10:27
[SWIFT 4.0] Autoclosure example
extension UIView {
static func animate(duration: TimeInterval, _ animations: @autoclosure @escaping () -> Void) {
UIView.animate(withDuration: duration, animations: { animations() })
}
}
UIView.animate(duration: 0.1, self.view.backgroundColor = UIColor.red)
@lamlv2305
lamlv2305 / ExtensionVariables.swift
Created January 9, 2018 08:39
[SWIFT 4.0] New variable in extension for existed class
class Testing {
}
private var key: Void?
extension Testing {
var title: String {
get {
guard let value = objc_getAssociatedObject(self, &key) as? String else {
return ""
@lamlv2305
lamlv2305 / LoadXibToStoryboard.swift
Last active January 9, 2018 05:30
Using xibview with storyboard. Do not forget to set "File's Owner -> Custom Class" in your xib file.
import UIKit
@IBDesignable
class XibView: UIView {
@IBInspectable var nibName: String?
private(set) var contentView: UIView?
override func awakeFromNib() {
super.awakeFromNib()
@lamlv2305
lamlv2305 / ForwardPipeOperator.swift
Last active January 5, 2018 05:47
[SWIFT 4.0] Forward Pipe Operator
infix operator |>: AdditionPrecedence
func |> <T, U>(value: T, function: ((T) -> U)) -> U {
return function(value)
}
func pow(_ value: Int) -> String {
return "ahihi \(value * value)"
}
let k = 3 |> pow