Skip to content

Instantly share code, notes, and snippets.

View lanserxt's full-sized avatar
🖥️
Developing a dream

Anton Gubarenko lanserxt

🖥️
Developing a dream
View GitHub Profile
@lanserxt
lanserxt / DeinitIsolation.swift
Created March 16, 2025 07:10
UIKit deinit isolation implementation
import UIKit
class ParentViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let childVC = ChildViewController()
displayContentController(content: childVC)
}
@lanserxt
lanserxt / gist:50c54a459f0962dfaf6bf89c392875d5
Created November 13, 2024 12:19
Remove token from plist
# Define the relative path to the file containing the access token
TOKEN_FILE_PATH="${SRCROOT}/Config/access_token.txt"
# Check if the file exists
if [ -f "$TOKEN_FILE_PATH" ]; then
# Read the access token from the file
ACCESS_TOKEN=$(cat "$TOKEN_FILE_PATH")
else
echo "Access token file not found at $TOKEN_FILE_PATH"
exit 1
@lanserxt
lanserxt / AuthDataManager.swift
Created October 31, 2024 09:31
Secured Credentials Manager to load API keys, login credentials and other from local secured file
import Foundation
import CryptoKit
struct AuthDataManager {
//MARK: - Encrypt/Decrypt Logic
/// Generate a symmetric key from a password
/// - Parameter password: password to use
/// - Returns: key
@lanserxt
lanserxt / UTMCampaignLoader.swift
Created October 17, 2024 14:38
AdService AAAttribution payload async fetching
//This class demostates how to extract and store payload info if it's available. Compaign ID was valuable for me so that's why only it is stored.
import AdServices
actor UTMCampaignLoader {
// Optional campaignID property
var campaignID: Int?
// Method to load UTM campaign asynchronously
func loadUTMCampaign() async -> Int? {
@lanserxt
lanserxt / WKWebViewScriptHandler.swift
Last active October 3, 2024 05:13
WKWebView script for full content loading
//Setting the script
extension WebViewCoordinator: WKNavigationDelegate {
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
let script = """
function isContentFullyRendered() {
var imgElements = document.images;
var imgComplete = true;
for (var i = 0; i < imgElements.length; i++) {
if (!imgElements[i].complete) {
imgComplete = false;
@lanserxt
lanserxt / Task.swift
Created May 17, 2023 12:15
UICollection model extension to support extra model
//We have a UICollectionView with Grid layout that shows a collection card.
//Model for a card looks like this:
struct CollectionViewCellModel: Codable {
let id: Int
let image: String
let imageUrl: String
let name: String
let description: String
let stocksAmount: Int
@lanserxt
lanserxt / LoggableButton.swift
Created April 24, 2023 07:05
SwiftUI Button with events logging
import SwiftUI
struct LoggableButton<Label> : View where Label : View {
let eventName: String
let action: () -> Void
let label: () -> Label
var body: some View {
Button {
//Handel event log
@lanserxt
lanserxt / ColorSliderView.swift
Created January 24, 2023 21:23
GradientColorPicker+SwiftUI
struct ColorSliderView: View {
//Picked Color
@State
private var location: CGPoint = CGPoint(x: 0, y: 0) {
didSet {
//Need https://gist.githubusercontent.com/marchinram/3675efc96bf1cc2c02a5/raw/ec95113fa3cf1a6e97361426dc7574d9e14a09c0/UIImage+PixelColor.swift
currentColor = trackImage[Int(location.x), 0] ?? .white
@lanserxt
lanserxt / Firebase+Tools.swift
Created July 6, 2020 13:29
Firebase document decoding to Swift Object
func resolveFirebaseObject<T: Codable>(_ snapshot: DocumentSnapshot) -> T? {
guard snapshot.exists else {return nil}
if let data = try? JSONSerialization.data(withJSONObject: snapshot.data(), options: []) {
do {
return try self.decoder.decode(T.self, from: data)
} catch {
print("Decoding error: \(error)")
}
}
return nil
@lanserxt
lanserxt / FMBlurable.swift
Created January 22, 2020 11:43
FMBlurable (Swift 5 update)
//
// FMBlurable.swift
// FMBlurable
//
// Created by SIMON_NON_ADMIN on 18/09/2015.
// Copyright © 2015 Simon Gladman. All rights reserved.
//
// Thanks to romainmenke (https://twitter.com/romainmenke) for hint on a larger sample...
import UIKit