Skip to content

Instantly share code, notes, and snippets.

Avatar

Jayesh Kawli jayesh15111988

View GitHub Profile
@jayesh15111988
jayesh15111988 / Regex.swift
Created Jul 18, 2022
The Gist to summarize how to use Regular expression on iOS platform using Swift
View Regex.swift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
findMatches()
findMatchingElements()
replaceMatchingElements()
}
func findMatches() {
@jayesh15111988
jayesh15111988 / custom_alignments.swift
Created May 9, 2022
A code to add custom alignments to SwiftUI views
View custom_alignments.swift
import SwiftUI
extension VerticalAlignment {
// A custom vertical alignment to custom align views vertically
private struct TopSectionTitlesAlignment: AlignmentID {
static func defaultValue(in context: ViewDimensions) -> CGFloat {
// Default to center alignment if no guides are set
context[HorizontalAlignment.center]
}
@jayesh15111988
jayesh15111988 / ShadowContainerView.swift
Last active May 6, 2022
A SwiftUI code to demonstrate how to create a shadow view in SwiftUI
View ShadowContainerView.swift
import SwiftUI
struct ShadowComponent: View {
enum Direction {
case upward
case downward
@jayesh15111988
jayesh15111988 / shadow_view_swiftUI.swift
Created May 6, 2022
Adding Shadow View in SwiftUI
View shadow_view_swiftUI.swift
import SwiftUI
struct ShadowView: View {
let xOffset: CGFloat
let yOffset: CGFloat
var body: some View {
Text("SwiftUI is Awesome").padding().background(
Rectangle()
@jayesh15111988
jayesh15111988 / PersistentStorageCodable.swift
Last active May 6, 2022
Storing custom objects into UserDefaults persistent storage
View PersistentStorageCodable.swift
struct Employee: Codable {
let name: String
let ssn: String
}
private let employeeDataKey = "employee"
func encodeObject() {
do {
let employeeData = try JSONEncoder().encode(Employee(name: "abc def", ssn: "123456789"))
View virusOriginator.swift
let graphNodes = [(1, 2), (2, 3), (2, 4), (4, 5), (4, 6), (5, 4)]
var nodeToIncomingEdgesCountMapping: [Int: Int] = [:]
for node in graphNodes {
if nodeToIncomingEdgesCountMapping[node.0] == nil {
nodeToIncomingEdgesCountMapping[node.0] = 0
}
if nodeToIncomingEdgesCountMapping[node.1] == nil {
@jayesh15111988
jayesh15111988 / TransactionOperation.swift
Last active Oct 25, 2020
This is the Swift implementation to perform basic database operations
View TransactionOperation.swift
//
// TransactionOperation.swift
// NotificationCenterImplementation
//
// Created by Jayesh Kawli on 10/18/20.
// Copyright © 2020 Jayesh Kawli. All rights reserved.
//
import Foundation
View MyNotificationCenter.swift
//
// MyNotificationCenter.swift
// MyNotificationCenterImplementation
//
// Created by Jayesh Kawli on 10/12/19.
// Copyright © 2019 Jayesh Kawli. All rights reserved.
//
import Foundation
enum NotificationCenterError: Error {
View MovieCell.swift
//
// MovieCell.swift
//
import UIKit
final class MovieCell: UITableViewCell {
let posterImageView = UIImageView(frame: .zero)
@jayesh15111988
jayesh15111988 / ImageDownloader.swift
Created Apr 26, 2020
A gist for image downloader and caching library written in Swift for iOS applications
View ImageDownloader.swift
import UIKit
// Image downloader utility class. We are going to use the singleton instance to be able to download required images and store them into in-memory cache.
final class ImageDownloader {
static let shared = ImageDownloader()
private var cachedImages: [String: UIImage]
private var imagesDownloadTasks: [String: URLSessionDataTask]