Skip to content

Instantly share code, notes, and snippets.

View 29satnam's full-sized avatar
🎯
Focusing

Satnam 29satnam

🎯
Focusing
View GitHub Profile
@29satnam
29satnam / UIButtonDeviceClass.swift
Created November 12, 2019 07:55
Dynamic Font Size UIButton Label
import Foundation
import UIKit
class UIButtonDeviceClass : UIButton {
@IBInspectable var iPhoneFontSize:CGFloat = 0 {
didSet {
overrideFontSize(fontSize: iPhoneFontSize)
}
@29satnam
29satnam / RealmExample.swift
Last active February 7, 2022 04:27
Realm CRUD Swift 5
import UIKit
import RealmSwift
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let realm = try! Realm()
@29satnam
29satnam / CRUDVapor.swift
Created February 15, 2019 12:42
Basic CRUD with Vapor - Swift
import Vapor
/// Register your application's routes here.
public func routes(_ router: Router) throws {
// Saving models
router.post("api", "acronyms") { req -> Future<Acronym> in
return try req.content.decode(Acronym.self)
.flatMap(to: Acronym.self) { acronym in
return acronym.save(on: req)
@29satnam
29satnam / routes.swift
Created February 5, 2019 17:09
Vapor very basic route handeling
import Vapor
/// Register your application's routes here.
public func routes(_ router: Router) throws {
/* // Example of configuring a controller
let todoController = TodoController()
router.get("todos", use: todoController.index)
router.post("todos", use: todoController.create)
router.delete("todos", Todo.parameter, use: todoController.delete) */
private var previousController: UINavigationController? = nil;
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
let canScrollToTop = navigationController == previousController
@29satnam
29satnam / SSLPinningSwift3.swift
Created September 9, 2017 10:18
SSL Pinning Swift 3
// Step 1: class ViewController: ..... URLSessionDelegate, URLSessionTaskDelegate
// Step 2: Usage
if let url = NSURL(string: "https://example.com") {
let session = URLSession(
configuration: URLSessionConfiguration.ephemeral,
delegate: NSURLSessionPinningDelegate(),
delegateQueue: nil)
@29satnam
29satnam / mailcore2-ios.swift
Created July 25, 2017 10:18
Swift 3 mailcore2-ios Implementation.
var smtpSession = MCOSMTPSession()
smtpSession.hostname = ""
smtpSession.username = ""
smtpSession.password = ""
smtpSession.timeout = 5
smtpSession.port = UInt32(port!)!
smtpSession.authType = MCOAuthType.saslPlain
smtpSession.connectionType = MCOConnectionType.startTLS
smtpSession.connectionLogger = {(connectionID, type, data) in
if data != nil {
@29satnam
29satnam / BottomBorderTextField.swift
Created July 19, 2017 09:40
This is how you can set only Bottom Border to UITextField using Swift 3
class BottomBorderTF: UITextField {
var bottomBorder = UIView()
override func awakeFromNib() {
//MARK: Setup Bottom-Border
self.translatesAutoresizingMaskIntoConstraints = false
bottomBorder = UIView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
bottomBorder.backgroundColor = UIColor.orange
bottomBorder.translatesAutoresizingMaskIntoConstraints = false
//
// UILabelDeviceClass.swift
//
// Created by MyCandy on 01/01/19.
// Copyright © 2019 Silver Seahog. All rights reserved.
//
import Foundation
import UIKit
let prefs:NSUserDefaults = NSUserDefaults.standardUserDefaults() //make this global
// Mark: This is how you save.
prefs.setObject("\(someVariable)", forKey: "PORT")
prefs.synchronize()
//Mark: This is how you retrieve saved content.
let retrieve = prefs.valueForKey("PORT") as? String
print(retrieve)