Skip to content

Instantly share code, notes, and snippets.

View rollr76518's full-sized avatar

Hanyu Chen rollr76518

View GitHub Profile
@rollr76518
rollr76518 / NSLayoutManagerViewController.swift
Created August 7, 2024 04:47
NSLayoutManagerPractice for line numbers
import UIKit
class NSLayoutManagerViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// 超長的文字
let longText = """
余憶童稚時,能張目對日,明察秋毫。見藐小微物,必細察其紋理,故時有物外之趣。
@rollr76518
rollr76518 / CoreTextViewController.swift
Created August 7, 2024 04:45
CoreTextPractice for line numbers
import UIKit
import CoreText
class CoreTextViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
// 超長的文字
@rollr76518
rollr76518 / MapView change center.swift
Created October 29, 2021 13:33
MapView change center.swift
func mapView(_ mapView: MKMapView, didChange mode: MKUserTrackingMode, animated: Bool) {
let userCoordinate = mapView.userLocation.coordinate
let rect = MKMapRect(
origin: .init(userCoordinate),
size: .init(
width: 12000.001100748777 / 2,
height: 21504.00197261572 / 4 * 3
)
)
let edgePadding = UIEdgeInsets(
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-122299963-1">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-122299963-1');
</script>
//Case 1
//Only 1 file, file name is String+extension.swift
extension String {
func doA() {}
func doB() {}
}
//Case 2
import WebKit
extension WKWebView {
func setAllCookies(completion: @escaping () -> Void) {
let queue = OperationQueue()
queue.maxConcurrentOperationCount = OperationQueue.defaultMaxConcurrentOperationCount
queue.name = "setAllCookies"
//
// PropertyWrapper+DidSet.swift
//
//
// Created by Hanyu on 2020/6/2.
//
import Foundation
@propertyWrapper
extension String {
static var htmlString: String {
let content = NSLocalizedString("了解更多關於 <a href='/'>隱私權</a> 及 <a href='/'>使用條款</a>", comment: "")
return #"""
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<style type="text/css">
import Foundation
//Orignal code
class APIClient {
class let shared = APIClient()
func doA() {
//Do A
}
import XCTest
import Moya
extension XCTestCase {
func expectation(description: String, timeout seconds: TimeInterval, handler: (@escaping () -> Void) -> Void) {
let expectation = XCTestExpectation(description: description)
handler({
expectation.fulfill()
})