Skip to content

Instantly share code, notes, and snippets.

View imnaveensharma's full-sized avatar

Naveen Sharma imnaveensharma

  • TechAhead Software Pvt. Ltd.
  • Noida, India
View GitHub Profile
@imnaveensharma
imnaveensharma / zshrc
Created June 20, 2022 10:51
Git Branch Colors and Formatting on Terminal on Mac
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF='%f'
COLOR_USR='%F{0}'
COLOR_DIR='%F{197}'
COLOR_GIT='%F{39}'
NEWLINE=$'\n'
@imnaveensharma
imnaveensharma / UIKit_TableView+ScrollHeader.swift
Created November 8, 2020 07:24
Scroll table view header with table scroll
// MARK: - Extension :: UIScrollViewDelegate ::
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//--- Scroll Table Header with Table Scroll ---//
if let tableView = scrollView as? UITableView {
if let visible = tableView.indexPathsForVisibleRows {
if let first = visible.first {
@imnaveensharma
imnaveensharma / UIKit_ScrollView+IndicatorColor.swift
Last active July 10, 2024 01:45
To change scroll view indicator color
// MARK: - Extension :: UIScrollViewDelegate ::
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//--- Change Scroll View Indicator Color ---//
if #available(iOS 13, *) {
let verticalIndicatorView = (scrollView.subviews[(scrollView.subviews.count - 1)].subviews[0])
let horizontalIndicatorView = (scrollView.subviews[(scrollView.subviews.count - 2)].subviews[0])
@imnaveensharma
imnaveensharma / RealmConfiguration.swift
Created September 21, 2020 05:19
Update/Change default realm database location and prevent database file from sharing iTunes(files app) and iCloud
func setupRealmConfiguration() {
var realmConfig = Realm.Configuration.defaultConfiguration
let paths = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory,
.userDomainMask,
true)
let applicationSupportDirectoryPath = paths.first
if let applicationSupportDirectoryPath = applicationSupportDirectoryPath {
let realmPath = applicationSupportDirectoryPath.appending("/default.realm")
realmConfig.fileURL = URL(fileURLWithPath: realmPath)
Realm.Configuration.defaultConfiguration = realmConfig
@imnaveensharma
imnaveensharma / RealmManager.swift
Last active September 19, 2020 09:09
Store Data in Realm Database
import Realm
import RealmSwift
/*
https://realm.io/docs/swift/latest/
https://github.com/realm/realm-cocoa
https://www.raywenderlich.com/9220-realm-tutorial-getting-started
https://medium.com/flawless-app-stories/crud-operation-using-realmswift-part-1-17a99de83cc1
https://medium.com/@aliakhtar_16369/realm-notifications-realmswift-part-2-60c66ab99ea9
https://medium.com/@aliakhtar_16369/realm-custom-configuration-and-encryption-realmswift-part-3-f991f090ae22
@imnaveensharma
imnaveensharma / GooglePlacePicker.swift
Last active October 28, 2020 08:07
Implementation of Google's native GMSAutocompleteViewController
import UIKit
import GooglePlaces
//https://developers.google.com/places/ios-sdk/autocomplete
class GooglePlacePicker: NSObject {
private var getPlaceInfo:((_ place: String?, _ coordinate: CLLocationCoordinate2D?, _ isSuccess: Bool) -> Void)?
internal static let shared: GooglePlacePicker = {
@imnaveensharma
imnaveensharma / UIKit_TableView+LongPressGesture.swift
Created August 7, 2020 07:17
Add Long Press Gesture Recognizer on Table Cell For Multiple Selection
private func setupLongPressGesture() {
let longPressGesture:UILongPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress))
longPressGesture.minimumPressDuration = 1.0 // 1 second press
//longPressGesture.delegate = self
self.tblView.addGestureRecognizer(longPressGesture)
}
@objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) {
if gestureRecognizer.state == .began {
let touchPoint = gestureRecognizer.location(in: self.tblView)
@IBOutlet private weak var collectionView: UICollectionView!
private func registerNibs() {
self.collectionView.register(UINib(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "CollectionViewCell")
}
// MARK: - Extension :: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout ::
extension MyProfileViewC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet private weak var tblView: UITableView!
private func registerNibs() {
self.tblView.register(UINib(nibName: "TableHeaderView", bundle: nil), forHeaderFooterViewReuseIdentifier: "TableHeaderView")
self.tblView.register(UINib(nibName: "TableFooterView", bundle: nil), forHeaderFooterViewReuseIdentifier: "TableFooterView")
self.tblView.register(UINib(nibName: "TableViewCell", bundle: nil), forCellReuseIdentifier: "TableViewCell")
}
// MARK: - Extension :: UITableViewDelegate, UITableViewDataSource ::
extension ViewController: UITableViewDelegate, UITableViewDataSource {
@imnaveensharma
imnaveensharma / UIKit_UIRefreshControl.swift
Created July 27, 2020 10:04
Add "Pull to Refresh" and "Load More" on UITableView and UICollectionView
//Step 2: Install below given Pod
pod 'CCBottomRefreshControl'
//Step 2: Add below given line in bridging header file
#import <CCBottomRefreshControl/UIScrollView+BottomRefreshControl.h>
//Step 3: