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 / 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 / .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 / 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 / User.swift
Created March 20, 2020 10:08
MVVM Design Pattern - User Model
//
// User.swift
// MVVM
//
// Created by Milan Panchal on 19/03/20.
// Copyright © 2020 Jeenal Infotech. All rights reserved.
//
import UIKit
struct UserList: Codable {
// 20200320153014
// https://randomuser.me/api/?results=20
{
"results": [
{
"gender": "male",
"name": {
"title": "Mr",
"first": "Victor",
@milanpanchal
milanpanchal / UserViewModel.swift
Created March 20, 2020 10:28
MVVM Design Pattern - UserViewModel
//
// UserViewModel.swift
// MVVM
//
// Created by Milan Panchal on 19/03/20.
// Copyright © 2020 Jeenal Infotech. All rights reserved.
//
import UIKit