Skip to content

Instantly share code, notes, and snippets.

View karthikAdaptavant's full-sized avatar
🎯
Focusing

Karthik samy karthikAdaptavant

🎯
Focusing
  • 16:50 (UTC +05:30)
View GitHub Profile
struct ContentView: View {
var body: some View {
NavigationStack {
List(1..<100) { row in
Text("Row \(row)")
}
.refreshable {
print("Do your refresh work here")
}
}
@karthikAdaptavant
karthikAdaptavant / DocC.swift
Last active July 1, 2023 12:18
Documentation with DocC
/// This is an example function using DocC
/// - Parameters:
/// - firstParam: Description of the first parameter
/// - secondParam: Description of the second parameter
/// - Returns: Description of what this function returns
func exampleFunction(firstParam: Int, secondParam: String) -> Bool {
// Function implementation here
return true
}
@karthikAdaptavant
karthikAdaptavant / FetchedResultsTableViewController.swift
Last active May 18, 2023 11:53
FetchedResultsTableViewController
public class FetchedResultsTableViewController<Entity: NSFetchRequestResult, Content: View>: UITableViewController {
private let reuseIdentifier = "FetchedResultsCell"
private let fetchedResultsController: NSFetchedResultsController<Entity>
private var selectionType: SelectionType = .single
private var cellSelectionStyle: UITableViewCell.SelectionStyle = .default
private let baseQuery: Query<Entity>
private var cellContent: (Entity, _ isSelected: Bool) -> Content
private var didSelectRow: ((Entity) -> Void)?
@karthikAdaptavant
karthikAdaptavant / FetchedResultsTableViewControllerWrapper.swift
Last active May 19, 2023 08:59
FetchedResultsTableViewControllerWrapper
public struct FetchedResultsTableViewControllerWrapper<Entity: NSFetchRequestResult, Content: View>: UIViewControllerRepresentable {
public typealias UIViewControllerType = FetchedResultsTableViewController<Entity, Content>
/// SwiftUI
@Binding var searchText: String?
let cellContent: (Entity, _ isSelected: Bool) -> Content
public init(
searchText: Binding<String?>,
@karthikAdaptavant
karthikAdaptavant / README.md
Last active April 20, 2022 10:50 — forked from brennanMKE/README.md
Create SSH Key on Mac for Xcode

Create SSH Key on Mac for Xcode

The docs for GitHub show a command to create a key with the ed25519 encryption method which is not allowed by Xcode. Even if you are not using the Source Control features in Xcode you will often need to use an account with GitHub when you are consuming Swift packages which are pulled from GitHub.

For SSH keys there are 4 algorithms.

  • 🚨 DSA: This is an older algorithm which is no longer supported and is superceded with more modern algorithms.
  • ⚠️ RSA: This algorithm was an improvement but it is now outdated and a more modern method should be used.
  • 👀 ECDSA: Another improvement which is dependent on your computer's ability to generate random numbers.
  • ✅: Ed25519: The most recommended public-key algorithm today which you should use with GitHub.
class InstrumentsViewController: UIViewController {
@IBOutlet weak var instrumentsTableView: UITableView! {
didSet {
instrumentsTableView.delegate = self
instrumentsTableView.dataSource = self
instrumentsTableView.tableFooterView = .init()
let cellNib = UINib(nibName: "InstrumentCell", bundle: .main)
instrumentsTableView.register(cellNib, forCellReuseIdentifier: "InstrumentCell")
}
class InstrumentCell: UITableViewCell {
@IBOutlet weak var title: UILabel!
@IBOutlet weak var subtitle: UILabel!
var instrument: Instrument!
override func awakeFromNib() {
super.awakeFromNib()
}
import UIKit
// According to article by John Sundell
// https://www.swiftbysundell.com/articles/caching-in-swift/
final class Cache<Key: Hashable, Value> {
private let wrapped = NSCache<WrappedKey, Entry>()
private let dateProvider: () -> Date
private let entryLifetime: TimeInterval
private let keyTracker = KeyTracker()
@karthikAdaptavant
karthikAdaptavant / singleton.dart
Created April 7, 2020 14:34 — forked from theburningmonk/singleton.dart
Using Dart's factory constructor feature to implement the singleton pattern
class MyClass {
static final MyClass _singleton = new MyClass._internal();
factory MyClass() {
return _singleton;
}
MyClass._internal() {
... // initialization logic here
}
import UIKit
// MARK: Cache Service
struct FlagService {
let key: String
let bufferTime: Double
var canProcess: Bool {
let buffer: Double = bufferTime * 60 * 60