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
if let userDict = User.convertToDict() { | |
// Do something you want with dict | |
} |
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
struct User: Convertable { | |
let name: String | |
let phone: String | |
} |
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 Foundation | |
protocol Convertable: Codable { | |
} | |
// Convert struct to dictionary | |
extension Convertable { | |
func convertToDict() -> Dictionary<String, Any>? { | |
var dict: Dictionary<String, Any>? = nil |
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
// I dont want my table jumping/animation when appending new rows | |
// for an infinite scroll feel | |
// | |
// Some of this might not be needed but it works | |
// | |
// TODO: Possibly garbage | |
extension UITableView { | |
func reloadDataSmoothly() { | |
UIView.setAnimationsEnabled(false) |
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
enum Type: String { | |
// 直接指定 API 回傳的 String | |
case regular = "regular" | |
case system = "system" | |
case advertise = "advertise" | |
var image: UIImage? { | |
// 一行搞定 | |
return UIImage(named: self.rawValue) | |
} |
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
let json = ["type": 1] | |
if let typeNumber = json["type"] { | |
imageView.image = Type(rawValue: typeNumber)?.image | |
} |
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
enum Type: Int { | |
case regular = 0 | |
case system | |
case advertise | |
var image: UIImage? { | |
switch self { | |
case .regular: | |
return UIImage(named: "regular") | |
case .system: |
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
enum Type { | |
case regular | |
case system | |
case advertise | |
var image: UIImage? { | |
switch self { | |
case .regular: | |
return UIImage(named: "regular") | |
case .system: |
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
enum Type { | |
case regular | |
case system | |
case advertise | |
} |
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
# Stole from: | |
# http://stackoverflow.com/questions/32122784/alias-script-to-delete-all-local-and-remote-git-branches-with-a-specific-prefix | |
git branch -D $(printf "%s\n" $(git branch) | grep 'feature/') | |
# Or this will work too to remove all remote branches: | |
# https://coderwall.com/p/eis0ba/remove-a-thousand-stale-remote-branches-on-git | |
git branch -r | awk -F/ '/\/feature/{print $2}' | xargs -I {} git push origin :{} | |
# Prune all origin branches | |
git remote prune origin |