Skip to content

Instantly share code, notes, and snippets.

View milanpanchal's full-sized avatar
🏠
Working from home

Milan Panchal milanpanchal

🏠
Working from home
View GitHub Profile
@milanpanchal
milanpanchal / .swiftlint.yml
Created June 11, 2016 00:31
SwiftLint's configuration rules example
# Find all the available rules by running:
# swiftlint rules
disabled_rules: # rule identifiers to exclude from running
# - colon
# - comma
- control_statement
# - trailing_whitespace
opt_in_rules: # some rules are only opt-in
- empty_count
@milanpanchal
milanpanchal / swift.swift
Created February 9, 2017 07:27 — forked from pedrogimenez/swift.swift
swift.swift
func calculateAverage(total: Int, countOfNumbers: Int) -> Int {
return total / countOfNumbers
}
func average(algorithm: (Int, Int) -> Int, numbers: Int...) -> Int {
var countOfNumbers = 0
var total = 0
for number in numbers {
total += number
@milanpanchal
milanpanchal / CSwift.swift
Created February 9, 2017 08:39 — forked from ankitspd/CSwift.swift
Swift ++ operator
prefix func ++(inout x: Int) -> Int {
x = x + 1
return x
}
postfix func ++(inout x: Int) -> Int {
let oldX = x
x = x + 1
return oldX
}
@milanpanchal
milanpanchal / DeviceConst.swift
Created February 9, 2017 14:37 — forked from bright23/DeviceConst.swift
DeviceConst.swift
//
// AppConst.swift
// AdBlockSample
//
// Created by bright on 2016/11/26.
// Copyright © 2016年 bright. All rights reserved.
//
import Foundation
import UIKit
import Foundation
import CoreTelephony
class OperatorInfo {
func id() -> String {
let networkInfo = CTTelephonyNetworkInfo()
let carrier = networkInfo.subscriberCellularProvider
let mcc = carrier!.mobileCountryCode
let mnc = carrier!.mobileNetworkCode
@milanpanchal
milanpanchal / getCurrentViewController
Last active November 8, 2017 10:55
To retrieve the view controller that is currently displayed in Swift
func currentViewController(_ viewController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
guard let viewController = viewController else { return nil }
if let viewController = viewController as? UINavigationController {
if let viewController = viewController.visibleViewController {
return currentViewController(viewController)
} else {
return currentViewController(viewController.topViewController)
}
} else if let viewController = viewController as? UITabBarController {
@milanpanchal
milanpanchal / Close All Notifications On Mac OS X
Last active November 17, 2020 21:07
Clearing All Notifications in Mac OS X through Apples Automator App by writing JavaScript Code
// https://medium.com/@milanpanchal24/clearing-all-notifications-in-mac-os-x-3be0a16eb2a3
function run(input, parameters) {
var app = Application('System Events');
app.includeStandardAdditions = true;
app.processes.byName('NotificationCenter').windows.buttons[0].click();
return input;
}
@milanpanchal
milanpanchal / PlaceholderTextView.swift
Created January 13, 2020 09:25 — forked from albertbori/PlaceholderTextView.swift
UITextView support for Placeholder text
import UIKit
import Foundation
@IBDesignable class PlaceholderTextView: UITextView, UITextViewDelegate
{
private let _placeholderColor: UIColor = UIColor(white: 0.78, alpha: 1)
private var _placeholderLabel: UILabel!
@IBInspectable var placeholder: String = "" {
didSet {
@milanpanchal
milanpanchal / GroupingArrayUsingDictionary.swift
Last active April 5, 2021 15:56
To group an array according to some criteria in Swift
// https://medium.com/@milanpanchal24/how-to-group-array-using-dictionary-in-swift-6d185c8c79c
let fruits = ["Apple", "Apricot", "Avocado",
"Banana", "Boysenberry", "Blueberry", "Bing Cherry",
"Clementine", "Cucumber",
"Dates", "Dewberries", "Dragon Fruit"]
let groupedByAlphabet = Dictionary(grouping: fruits) { $0.first! }
@milanpanchal
milanpanchal / GroupingArrayUsingDictionaryInSwift-example2.swift
Last active April 5, 2021 15:56
To group an array by countryName in swift
// https://medium.com/@milanpanchal24/how-to-group-array-using-dictionary-in-swift-6d185c8c79c
let employee = [["countryName":"India", "name":"Milan", "age":"30"],
["countryName":"India", "name":"Emma", "age":"25"],
["countryName":"NZ", "name":"Olivia", "age":"40"],
["countryName":"NZ", "name":"Sophia", "age":"22"],
["countryName":"Canada", "name":"David", "age":"33"],
["countryName":"Canada", "name":"Wyatt", "age":"21"],
["countryName":"Portugal", "name":"Joseph", "age":"28"]]