Skip to content

Instantly share code, notes, and snippets.

View vialyx's full-sized avatar
🎯
Focusing

Maxim Vialyx vialyx

🎯
Focusing
View GitHub Profile
struct Segue {
var identifier: String
}
extension UIViewController {
func perform(segue: Segue, sender: Any? = nil) {
performSegue(withIdentifier: segue.identifier, sender: sender)
}
if segue.identifier == "signup",
let vc = segue.destination as? OBSignupViewController {
vc.email = emailTF.text
}
class ViewController: UIViewController {
var model: Model = Model()
override func loadView() {
super.loadView()
let button = UIButton(frame: CGRect(x: 60, y: 100, width: 200, height: 100))
button.setTitle("Start Fitbit Auth", for: UIControl.State())
button.backgroundColor = .red
@vialyx
vialyx / Model.swift
Last active September 9, 2020 20:04
class Model: AuthHandlerType {
var session: NSObject? = nil
var contextProvider: AuthContextProvider?
func auth(_ completion: @escaping ((String?, Error?) -> Void)) {
guard let authUrl = Constants.authUrl else {
completion(nil, nil)
return
struct Constants {
static let authUrl = URL(string: "https://www.fitbit.com/oauth2/authorize")
static let responseType = "code"
static let clientId = "{YOUR_CLIENT_ID}"
static let redirectScheme = "vialyx://" // YOU MUST DEFINE THAT SCHEME IN PROJECT SETTIGNS
static let redirectUrl = "\(redirectScheme)fitbit/auth"
static let scope = ["activity", "heartrate", "location", "nutrition", "profile", "settings", "sleep", "social", "weight"]
static let expires = "604800"
import SafariServices
import AuthenticationServices
typealias AuthHandlerCompletion = (URL?, Error?) -> Void
class AuthContextProvider: NSObject {
private weak var anchor: ASPresentationAnchor!
init(_ anchor: ASPresentationAnchor) {
//
// ViewController.swift
// ActivityViewController
//
// Created by Maksim Vialykh on 2019-02-21.
// Copyright © 2019 Vialyx. All rights reserved.
//
import UIKit
import UIKit
class AnimatedTabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
delegate = self
}
}
import UIKit
class AnimatableTableViewCell: UITableViewCell, HighlightAnimatable {
var settings: HighlightAnimatableSettings {
var settings = HighlightAnimatableSettings()
settings.transform = .init(scaleX: 0.70, y: 0.70)
settings.duration = 0.3
return settings
}
import UIKit
class AnimatableButton: UIButton, HighlightAnimatable {
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
highlight(true)
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {