Author: Chris Lattner
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
UIView *parentView, *childView; | |
[childView setFrame:({ | |
CGRect frame = childView.frame; | |
frame.origin.x = (parentView.frame.size.width - frame.size.width) / 2.0; | |
frame.origin.y = (parentView.frame.size.height - frame.size.height) / 2.0; | |
CGRectIntegral(frame); | |
})]; |
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
// | |
// Device.swift | |
// imHome | |
// | |
// Created by Kevin Xu on 2/9/15. Updated on 6/20/15. | |
// Copyright (c) 2015 Alpha Labs, Inc. All rights reserved. | |
// | |
import Foundation |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
var str = "Hello, playground" | |
import Foundation | |
func test(timeout: Double) { | |
let queue = DispatchQueue(label: "test", attributes: .concurrent) |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import PlaygroundSupport | |
let testList = ["a", "b", "c", "d"] | |
let tokenStr = testList.joined(separator: ", ") | |
tokenStr | |
let multiLanguageAddressList = |
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
extension String { | |
func remove(stringList: [String]) -> String { | |
return stringList.reduce(self) { | |
return $0.replacingOccurrences(of: $1, with: "") | |
} | |
} | |
} | |
let testEmStr = "<em>#<\\/em>swift" | |
let trimStr = testEmStr.remove(stringList:["<em>", "<\\/em>"]) |
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
//: Playground - noun: a place where people can play | |
import Foundation | |
extension String { | |
var hasNumeric: Bool { | |
return self.rangeOfCharacter(from: .decimalDigits) != nil | |
} | |
var isNumeric : Bool { |
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 mapStr = ["test"].reduce("", +) | |
mapStr | |
let mapStr2 = ["test"].joined() | |
mapStr2 | |
let mapStr3 = ["test"].joined(separator: "") | |
mapStr3 | |
extension String { | |
func removeDayzSearchCountSuffix() -> String { | |
if self.trimmingCharacters(in: .whitespacesAndNewlines).components(separatedBy: " (").count > 1 { |
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 | |
import PlaygroundSupport | |
func += <K, V> (left: inout [K:V], right: [K:V]) { | |
for (k, v) in right { | |
left[k] = v | |
} | |
} | |
func + <K,V>(left: Dictionary<K,V>, right: Dictionary<K,V>) |
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
//: Playground - noun: a place where people can play | |
import UIKit | |
import PlaygroundSupport | |
var freeV = 0 | |
func recur(input: Int, completion: @escaping (Int) -> Void) -> Int { | |
DispatchQueue.global().async { | |
print("FOR: is main thread? : ", Thread.isMainThread) | |
for i in (input * 10)...(input * 100) { |
OlderNewer