Skip to content

Instantly share code, notes, and snippets.

View tayathorn's full-sized avatar

Tayathorn 'Pan' Panuwattanawong tayathorn

View GitHub Profile
@pallavtrivedi03
pallavtrivedi03 / CertificatePinning.swift
Created September 3, 2021 10:02
Implementation of SSL pinning (using certifcate)
func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {
guard let serverTrust = challenge.protectionSpace.serverTrust else {
completionHandler(.cancelAuthenticationChallenge, nil);
return
}
let certificate = SecTrustGetCertificateAtIndex(serverTrust, 0)
// SSL Policies for domain name check
let policy = NSMutableArray()
@IanKeen
IanKeen / Example.swift
Created February 7, 2021 03:09
PropertyWrapper: Ignore codable properties
struct Foo: Codable {
var name: String
@Ignore var foo: Int?
}
let model = Foo(name: "Ian", foo: 42)
let data = try! JSONEncoder().encode(model)
print(String(data: data, encoding: .utf8)!) // {"name":"Ian"}
@zntfdr
zntfdr / firebase-iOS-breakdown.swift
Last active September 24, 2024 06:29
Firebase iOS Version breakdown
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
@GoranLilja
GoranLilja / AppDelegate.swift
Last active May 12, 2024 12:24
Blur app when resigning active
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func applicationWillResignActive(_ application: UIApplication) {
addBlurViews()
}
func applicationDidBecomeActive(_ application: UIApplication) {
removeBlurViews()
}
@DineshKachhot
DineshKachhot / ForceUpdateAppVersion.swift
Last active October 29, 2023 06:33
Force Update iOS App while API has major update
import Foundation
enum VersionError: Error {
case invalidResponse, invalidBundleInfo
}
class ForceUpdateAppVersion {
class func isForceUpdateRequire(apiVersion:Int) -> Bool {
func update() {
@imaizume
imaizume / RemoteConfigManager.swift
Last active February 18, 2021 06:36
How to manage parameters for Firebase Remote Config in Swift easily.
// MARK:- definition
/// Constraint for Parameter Type Definition.
protocol ParameterProtocol {
/// Parameter name in Firebase console. e.g. "beta_test_1"
var name: String { get }
/// Default value to be set to Remote Config object.
var defaultValue: [String: NSObject] { get }
}
@SergLam
SergLam / EmojiCheck.swift
Created May 27, 2019 07:38
Swift - check if string contains emoji character
// https://stackoverflow.com/questions/30757193/find-out-if-character-in-string-is-emoji
import Foundation
extension UnicodeScalar {
var isEmoji: Bool {
switch value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x1F1E6...0x1F1FF, // Regional country flags
@endy-s
endy-s / String.swift
Last active October 21, 2022 04:03
Compare two String Versions
extension String {
func getRawVersionString() -> String? {
return self.removePrefix("v")
.split(separator: "-")
.first?.toString()
}
// Modified from the DragonCherry extension - https://github.com/DragonCherry/VersionCompare
private func compare(toVersion targetVersion: String) -> ComparisonResult {
let versionDelimiter = "."
@deepakraj27
deepakraj27 / AttachmentHandler.swift
Last active July 15, 2025 14:01
Access Camera, Photo Library, Video and File from User device using Swift 4
//
// AttachmentHandler.swift
// AttachmentHandler
//
// Created by Deepak on 25/01/18.
// Copyright © 2018 Deepak. All rights reserved.
//
import Foundation
import UIKit
@joshbuchea
joshbuchea / semantic-commit-messages.md
Last active March 19, 2026 20:51
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example