Skip to content

Instantly share code, notes, and snippets.

View anirudhamahale's full-sized avatar

Anirudha Mahale anirudhamahale

View GitHub Profile
@anirudhamahale
anirudhamahale / NetworkHelper+Extension.swift
Last active November 23, 2022 10:51
Network Helper Extensions
extension Data {
func printData(with title: String?) {
if let title = title {
print(title)
}
if let json = try? JSONSerialization.jsonObject(with: self, options: .mutableContainers),
let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) {
print(String(decoding: jsonData, as: UTF8.self))
} else {
String(decoding: self, as: UTF8.self)
@anirudhamahale
anirudhamahale / PhoneNumberManager
Last active April 22, 2021 04:54
Returns the country code and phone number from number
```swift
import Foundation
class PhoneNumberManager {
static func readJson() -> [String: Any]? {
if let fileUrl = Bundle.main.url(forResource: "DailerCodeTree", withExtension: "json") {
do {
let data = try Data(contentsOf: fileUrl)
let json = try JSONSerialization.jsonObject(with: data, options: [])
let dictionary = json as! [String: Any]
@anirudhamahale
anirudhamahale / HealthKitManager.swift
Created October 30, 2020 12:03
Wrapper for HKHealthStore written in RxSwift to return steps count, distance(walking & running) & active energy burned.
import Foundation
import HealthKit
import RxSwift
class HealthKitManager {
private let healthStore = HKHealthStore()
func requestPermission() -> Observable<Bool> {
return .create { [weak self] (observer) -> Disposable in
extension String {
func toArray() throws -> [Any] {
guard let stringData = data(using: .utf16, allowLossyConversion: false) else { return [] }
guard let array = try JSONSerialization.jsonObject(with: stringData, options: .mutableContainers) as? [Any] else {
throw JSONError.notArray
}
return array
}
@anirudhamahale
anirudhamahale / EmptyDataSet.swift
Last active March 3, 2020 14:55
EmptyDataSet
import UIKit
class EmptyDataSet: UIView {
private(set) var parentView: UIView!
private(set) var titleLabel: UILabel!
private(set) var descriptionLabel: UILabel!
private(set) var imageView: UIImageView!
private(set) var button: UIButton!
@anirudhamahale
anirudhamahale / LocalNotificationManager.Swift
Created January 15, 2020 09:59
Manager to handle local notifications.
import UIKit
import UserNotifications
class LocalNotificationManager {
var notifications = [Notification]()
func scheduledNotifications(completion: ([Notification])->()) {
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().getPendingNotificationRequests { notifications in
@anirudhamahale
anirudhamahale / ShimmerView.swift
Last active December 16, 2019 11:36
Simple ShimmerView.
/// View to give shimmering effects.
class ShimmerView: UIView {
/// Start the shimmering animation.
func start() {
let light = UIColor.white.cgColor
let alpha = UIColor(red: 206/255, green: 10/255, blue: 10/255, alpha: 0.7).cgColor
let gradient = CAGradientLayer()
gradient.frame = CGRect(x: -self.bounds.size.width, y: 0, width: 3 * self.bounds.size.width, height: self.bounds.size.height)
gradient.colors = [light, alpha, light]
@anirudhamahale
anirudhamahale / PhoneContacts.swift
Last active November 18, 2019 06:32
Fetches contacts.
import Contacts
class PhoneContacts {
struct Contact {
let givenName: String
let middleName: String
let familyName: String
let phoneNumber: [String]
let email: [String]
@anirudhamahale
anirudhamahale / LineChart.swift
Last active November 15, 2019 06:16
Create simple line graph to show Blood Pressure stats.
//
// LineChart.swift
// LineChart
//
// Created by Nguyen Vu Nhat Minh on 25/8/17.
// Copyright © 2017 Nguyen Vu Nhat Minh. All rights reserved.
//
// Modified by Anirudha Mahale on 14/11/19.
import UIKit
@anirudhamahale
anirudhamahale / PickerView.swift
Last active October 17, 2019 11:14
Swift UIPickerView
//
// PickerView.swift
// SlideUpAnimation
//
// Created by Anirudha Mahale on 17/10/19.
// Copyright © 2019 Anirudha Mahale. All rights reserved.
//
import UIKit
import RxSwift