Skip to content

Instantly share code, notes, and snippets.

git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
git config --global --unset http.proxy
git config --global --unset https.proxy
npm config delete proxy
@williamhqs
williamhqs / Test.playground
Last active May 13, 2020 10:21
ProperyWrapper decode
import UIKit
let jsonString =
"""
{
"name": "Tim",
"age": "28"
}
"""
/* 3.1 */
// 1. Write Pseudo code find a given element in an array
func linearSearch<T: Equatable>(target: T, in array: [T]) {
for (index, element) in array.enumerated() {
if element == target {
print("Found \(element) at \(index)")
break
} else if (index == array.count) {
print("The target \(target) not found")
//
// GSSimpleImageView.swift
// GSSimpleImage
//
// Created by 胡秋实 on 16/1/2016.
// Copyright © 2016 CocoaPods. All rights reserved.
//
import UIKit
@williamhqs
williamhqs / GradientLine.swift
Last active December 12, 2019 22:08
CoreGraphics draw a line with gradient and lineCap
class GradientLineView: UIView {
override func draw(_ rect: CGRect) {
if let context = UIGraphicsGetCurrentContext() {
let startPoint1 = CGPoint(x: 20, y: rect.height/2)
let endPoint1 = CGPoint(x: rect.width-120, y: rect.height/2)
context.setLineWidth(15)
context.move(to: startPoint1)
context.addLine(to: endPoint1)
context.setLineCap(.round)
extension Date {
func yearsCount(from date: Date) -> Int {
return Calendar.current.dateComponents([.year], from: date, to: self).year ?? 0
}
func monthsCount(from date: Date) -> Int {
return Calendar.current.dateComponents([.month], from: date, to: self).month ?? 0
}
set -e
REVEAL_ARCHIVE_IN_FINDER=true
FRAMEWORK_NAME="${PROJECT_NAME}"
SIMULATOR_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${FRAMEWORK_NAME}.framework"
DEVICE_LIBRARY_PATH="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${FRAMEWORK_NAME}.framework"
UNIVERSAL_LIBRARY_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneuniversal"
@williamhqs
williamhqs / universal-framework.sh
Created October 23, 2018 07:12 — forked from Tokuriku/universal-framework.sh
Script to put in an Aggregate Target of a Framework in Xcode 6 to create a Universal Framework
#!/bin/sh
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# make sure the output directory exists
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# Step 1. Build Device and Simulator versions
xcodebuild -target "${PROJECT_NAME}" ONLY_ACTIVE_ARCH=NO -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
xcodebuild -target "${PROJECT_NAME}" -configuration ${CONFIGURATION} -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
https://rink.hockeyapp.net/apps/aab3358c393742e2b1223c144755743a/app_versions/2166

View Layer Architecture

In a viewController usually there are many methods. In order make this part organized well. Here are the rules:

// MARK: - Life cycle