Skip to content

Instantly share code, notes, and snippets.

@boraseoksoon
boraseoksoon / UILabelCenter.m
Last active January 18, 2017 15:03
iOS CocoaTouch How to put the UILabel Center for x or y independently
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);
})];
@boraseoksoon
boraseoksoon / Device.swift
Created March 20, 2017 17:34 — forked from imkevinxu/Device.swift
iOS device checks for OS version and screen size in Swift
//
// 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
@boraseoksoon
boraseoksoon / .swift
Created July 29, 2018 12:52
how to sync control dispatch Async snippet
//: 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)
@boraseoksoon
boraseoksoon / .swift
Created August 7, 2018 15:44
20180808.Playground
//: 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 =
@boraseoksoon
boraseoksoon / .swift
Last active August 8, 2018 10:06
remove all match list strings to need to be removed in a given string
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>"])
@boraseoksoon
boraseoksoon / .swift
Last active August 9, 2018 18:50
get timestamp start, end boundary for Dayz
//: Playground - noun: a place where people can play
import Foundation
extension String {
var hasNumeric: Bool {
return self.rangeOfCharacter(from: .decimalDigits) != nil
}
var isNumeric : Bool {
@boraseoksoon
boraseoksoon / .swift
Last active August 13, 2018 11:39
string array to string for Dayz iOS
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 {
@boraseoksoon
boraseoksoon / .swift
Created August 13, 2018 19:03
Dayz test code : reduce triple parameter tuple, ways to append dictionary to append
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>)
@boraseoksoon
boraseoksoon / .swift
Created August 14, 2018 11:15
async + recursion + multi-thread serious simplification test code in playground
//: 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) {