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 | |
func printf<T>(msg message: T, file: String = #file, method: String = #function, line: Int = #line) { | |
let fileName = (file as NSString).lastPathComponent | |
print("\(fileName) [\(line)], \(method): \(message)") | |
} |
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
// 延遲指定時間 (可搭配 activity indicator 使用) | |
func delay(_ seconds: Double, completion: @escaping ()->()) { | |
let dispatchTime: DispatchTime = DispatchTime.now() + Double(Int64(seconds * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) | |
DispatchQueue.main.asyncAfter(deadline: dispatchTime) { | |
completion() | |
} | |
} |
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 SystemConfiguration | |
public class Reachability { | |
class func isConnectedToNetwork() -> Bool { | |
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0)) | |
zeroAddress.sin_len = UInt8(MemoryLayout.size(ofValue: zeroAddress)) | |
zeroAddress.sin_family = sa_family_t(AF_INET) | |
let defaultRouteReachability = withUnsafePointer(to: &zeroAddress) { | |
$0.withMemoryRebound(to: sockaddr.self, capacity: 1) {zeroSockAddress in | |
SCNetworkReachabilityCreateWithAddress(nil, zeroSockAddress) |
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 | |
extension UIDevice { | |
//MARK: Get String Value | |
func MBFormatter(_ bytes: Int64) -> String { | |
let formatter = ByteCountFormatter() | |
formatter.allowedUnits = ByteCountFormatter.Units.useMB | |
formatter.countStyle = ByteCountFormatter.CountStyle.decimal |
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 swift(>=5.0) | |
print("Hello, Swift 5.0") | |
#elseif swift(>=4.2) | |
print("Hello, Swift 4.2") | |
#elseif swift(>=4.1) | |
print("Hello, Swift 4.1") | |
#elseif swift(>=4.0) | |
print("Hello, Swift 4.0") | |
#elseif swift(>=3.0) | |
print("Hello, Swift 3.0") |
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
func cropToSquare(image: UIImage) -> UIImage? { | |
if let cgImg = image.cgImage { | |
let contextSize: CGSize = image.size | |
var posX: CGFloat = 0 | |
var posY: CGFloat = 0 | |
var length: CGFloat = 0 | |
if contextSize.width > contextSize.height { |
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
override func viewDidAppear(_ animated: Bool) { | |
if let img = UIImage(named: "Sonic") { | |
let considerationPaperSize = CGSize(width: 1800, height: 2400) | |
let outputImage = self.allocate(image: img, inPhotoPaper: considerationPaperSize) | |
Thread.updateUI(byType: .async) { | |
self.myImage.image = outputImage |
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
// | |
// main.c | |
// test | |
// | |
// Created by Bob Chang on 2019/3/2. | |
// Copyright © 2019 Bob Chang. All rights reserved. | |
// | |
#include <stdio.h> |
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 EventKit | |
class ViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
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
// | |
// ViewController.swift | |
// Font | |
// | |
// Created by Bob on 2019/7/9. | |
// Copyright © 2019 Hamster. All rights reserved. | |
// | |
import UIKit |
OlderNewer