Skip to content

Instantly share code, notes, and snippets.

View mzeeshanid's full-sized avatar

Muhammad Zeeshan mzeeshanid

View GitHub Profile
@mzeeshanid
mzeeshanid / OneDelarationPerFileRule.swift
Last active December 8, 2023 18:01
Implementation of One Declaration Per File Rule
import SwiftSyntax
@SwiftSyntaxRule
struct OneDelarationPerFileRule: OptInRule {
var configuration = SeverityConfiguration<Self>(.warning)
static let description = RuleDescription(
identifier: "one_declaration_per_file",
name: "One Declaration Per File",
description: "Only a single declaration is allowed in a file",
@mzeeshanid
mzeeshanid / Triggering.swift
Created December 5, 2023 06:16
swiftlint custom rule triggering example for 1 declaration per file rule
class Car {
var make: String
var model: String
init(make: String, model: String) {
self.make = make
self.model = model
}
}
@mzeeshanid
mzeeshanid / NonTriggering.swift
Last active December 5, 2023 06:11
swiftlint custom rule non triggering example for 1 declaration per file
class Car {
var make: String
var model: String
init(make: String, model: String) {
self.make = make
self.model = model
}
}
@mzeeshanid
mzeeshanid / ReverseGeoCodingViewModel.swift
Created February 24, 2022 11:33
GMSGeocoder entertain last request only
class ReverseGeoCodingViewModel {
var requestIdentifier: Int = 0
func reverseGeoCodeLocation(_ coordinate: CLLocationCoordinate2D,
completion: @escaping GMSReverseGeocodeCallback) {
self.requestIdentifier += 1
let currentRequestIdentifier = self.requestIdentifier
let geocoder = GMSGeocoder()
@mzeeshanid
mzeeshanid / ReverseGeocdingViewModel.swift
Created February 24, 2022 11:25
GMSGeocoder example
class ReverseGeoCodingViewModel {
func reverseGeoCodeLocation(_ coordinate: CLLocationCoordinate2D,
completion: @escaping GMSReverseGeocodeCallback) {
let geocoder = GMSGeocoder()
geocoder.reverseGeocodeCoordinate(coordinate) { response, error in
completion(response, error)
}
}
}
@mzeeshanid
mzeeshanid / ProductExt.swift
Created December 30, 2020 10:45
Product extension
extension Product {
func startingPrice() -> Double {
return self.variants.min(by: {$0.price < $1.price})?.price ?? 0.0
}
}
@mzeeshanid
mzeeshanid / Models.swift
Last active December 30, 2020 10:41
class declaration for models
class Product {
var id: Int
var name: String
var image: String
var variants: [Variant]
}
class Variant {
var id: Int
@mzeeshanid
mzeeshanid / stringsearch.swift
Created April 7, 2020 18:54
Search for string with before and after limit
let limit = 13
let queryString = "text"
let targettedString = "Lorem Ipsum is simply dummy text of the printing and typesetting"
let queryRange = targettedString.range(of: queryString)
let distanceToStart = max(self.distance(from: queryRange.lowerBound, to: self.startIndex), -limit)
let distanceToEnd = min(self.distance(from: queryRange.upperBound, to: self.endIndex), limit)
let start = self.index(queryRange.lowerBound, offsetBy: distanceToStart)
@mzeeshanid
mzeeshanid / ViewController.swift
Created April 5, 2020 11:19
Synchronised splash animation
//
// ViewController.swift
// splashanimation
//
// Created by Muhammad Zeeshan on 05/04/2020.
// Copyright © 2020 mzeeshanid. All rights reserved.
//
import UIKit
@mzeeshanid
mzeeshanid / properties.swift
Last active April 5, 2020 10:30
Properties for Splash Animation
var images: [UIImage] = []
var currentIndex: Int = 0
var isScreenVisible: Bool = false