This file contains hidden or 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
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ | |
//.. do other setup | |
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; | |
// Transition neatly from splash screen | |
// Very odd, on iPhone 5 you need to position the splash screen differently.. |
This file contains hidden or 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
Converting your screencast/screen recording to Gif is not a big deal. All you need: | |
1. QuickTime Player to record your screen OR video file if you already have the video that you wanna convert | |
2. ffmpeg installed in mac | |
First of all, install HomeBrew using the following command | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
Then install ffmpeg using the following commmand: |
This file contains hidden or 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
extension String { | |
var ascii: Int { | |
guard let u = UnicodeScalar(self) else { return -1 } | |
return Int(u.value) | |
} | |
} | |
"a".ascii // 97 | |
"A".ascii // 65 |
This file contains hidden or 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
extension Decimal { | |
var intValue: Int { | |
return NSDecimalNumber(decimal: self).intValue | |
} | |
} | |
extension Int { | |
func digitAt(i: Int) -> Int { | |
let div = pow(10, i).intValue | |
let x = self / div |
This file contains hidden or 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
var dic = [String: Int]() | |
dic["hello", default: 0] += 1 | |
dic // ["hello": 1] | |
func parse(_ string: String) -> String { | |
switch Int(string) { | |
case .some(7): return "SEVEN" | |
case 5?: return "FIVE" | |
case let x? where x < 10: return "1-9" | |
default: return "Not valid INT" |
This file contains hidden or 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
/** | |
Returns index of item if found. Otherwise returns -1 * position where the item should be insertd to | |
*/ | |
func binarySearch(arr: [Int], start: Int, end: Int, k: Int) -> Int { | |
var start = start | |
var end = end | |
var mid = 0 | |
while start <= end { | |
mid = start + (end - start) / 2 | |
if arr[mid] == k { |
This file contains hidden or 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
var arr = [1, 2, 5, 5, 6, 7, 10] | |
let pivot = arr.partition { $0 % 2 == 0 } | |
arr // [1, 7, 5, 5, 6, 2, 10] | |
let part1 = arr[..<pivot] // odd numbers | |
let part2 = arr[pivot...] // even numbers |
This file contains hidden or 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
private func swizzle(method: String, of class: String, to newMethod: String) { | |
let original: Method | |
let swizzled: Method | |
guard let aClass = objc_getClass(`class`) as? AnyClass else { return } | |
original = class_getInstanceMethod(aClass, Selector((method)))! | |
swizzled = class_getInstanceMethod(aClass, Selector((newMethod)))! | |
method_exchangeImplementations(original, swizzled) | |
} | |
This file contains hidden or 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
override func viewDidLayoutSubviews() { | |
super.viewDidLayoutSubviews() | |
updateTableViewHeaderHeight() | |
} | |
private func updateTableViewHeaderHeight() { | |
guard let headerView = tableView.tableHeaderView else { return } | |
/// Get the size that should meet the constraints | |
let size = headerView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize) | |
guard size.height != headerView.frame.height else { return } |
This file contains hidden or 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 Player { | |
let name: String | |
var score: Int = 0 | |
} | |
let p1 = Player(name: "John") | |
let p2 = Player(name: "Sam", score: 100) |
OlderNewer