Skip to content

Instantly share code, notes, and snippets.

import PlaygroundSupport
import Foundation
import Combine
// MARK: - Network Controller
protocol NetworkControllerProtocol: class {
typealias Headers = [String: Any]
func get<T>(type: T.Type,
url: URL,
@cupnoodle
cupnoodle / IAPHelper.swift
Created July 21, 2020 09:51
In app purchase helper class
// Created by Soulchild on 21/07/2020.
// Copyright © 2020 fluffy. All rights reserved.
//
import Foundation
import StoreKit
// Need to install the TPInAppReceipt library first
import TPInAppReceipt
@abhi21git
abhi21git / ExtensionURLRequest.swift
Last active February 19, 2024 12:23
Swift cURL Printer
//
// ExtensionURLRequest.swift
//
// Created by Abhishek Maurya on 16/07/20.
// Copyright © 2020. All rights reserved.
//
import Foundation
extension URLRequest {
@fmo91
fmo91 / FunctionalNetworkingLayer.swift
Last active July 19, 2020 00:24
Toy Networking Layer with functional operators
import Foundation
import PlaygroundSupport
enum NetworkError: Error {
case generic
}
precedencegroup PipeAssociativity {
associativity: left
}
@cprovatas
cprovatas / Data+PrettyPrint.swift
Created May 23, 2018 15:52
Pretty print JSON string from Data in Swift 4.1 (especially useful printing to Xcode console)
import Foundation
extension Data {
var prettyPrintedJSONString: NSString? { /// NSString gives us a nice sanitized debugDescription
guard let object = try? JSONSerialization.jsonObject(with: self, options: []),
let data = try? JSONSerialization.data(withJSONObject: object, options: [.prettyPrinted]),
let prettyPrintedString = NSString(data: data, encoding: String.Encoding.utf8.rawValue) else { return nil }
return prettyPrintedString
}
@Pulimet
Pulimet / AdbCommands
Last active March 28, 2024 15:08
Adb useful commands list
adb help // List all comands
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
@TheCodedSelf
TheCodedSelf / RxSwiftBindToButton.swift
Created May 13, 2017 17:16
RxSwift: Bind to button taps
import UIKit
import RxSwift
import RxCocoa
let button = UIButton()
button.rx.tap.bind {
print("button tapped")
}
@fmo91
fmo91 / ReusableViewEnum.swift
Last active August 16, 2017 20:39
Protocol extension to help using UITableView protocols in a better way.
protocol ReusableViewEnum {}
extension ReusableViewEnum where Self: RawRepresentable, Self.RawValue == Int {
static var all: [Self] {
var index = 0
var allItems = [Self]()
while let item = Self(rawValue: index) {
allItems.append(item)
index += 1
}
@shaps80
shaps80 / cURL+Request.swift
Last active December 23, 2023 17:43
Generates a cURL command representation of a URLRequest in Swift.
import Foundation
extension URLRequest {
/**
Returns a cURL command representation of this URL request.
*/
public var curlString: String {
guard let url = url else { return "" }
var baseCommand = #"curl "\#(url.absoluteString)""#
@fmo91
fmo91 / LoadingButton.swift
Created October 4, 2016 17:08
Simple UIButton subclass that can show a customizable loading message
//
// LoadingButton.swift
// LoadingButton
//
// Created by Fernando Ortiz on 4/10/16.
// Copyright © 2016 Fernando Martín Ortiz. All rights reserved.
//
import UIKit