Skip to content

Instantly share code, notes, and snippets.

View glennposadas's full-sized avatar
🏠
Working from home

Glenn Posadas glennposadas

🏠
Working from home
View GitHub Profile
@ricardo0100
ricardo0100 / PhotoView.swift
Created August 15, 2020 15:20
Photo View with zoom and edges control in SwiftUI
import SwiftUI
struct PhotoView: View {
@State var scale: CGFloat = 1
@State var scaleAnchor: UnitPoint = .center
@State var lastScale: CGFloat = 1
@State var offset: CGSize = .zero
@State var lastOffset: CGSize = .zero
@State var debug = ""
import Combine
import UIKit
public protocol CombineCompatible {}
// MARK: - UIControl
public extension UIControl {
final class Subscription<SubscriberType: Subscriber, Control: UIControl>: Combine.Subscription where SubscriberType.Input == Control {
private var subscriber: SubscriberType?
private let input: Control
@SergLam
SergLam / CustomNavigationController.swift
Last active February 6, 2024 09:23
Custom screen transition with pan gesture from the center of screen
import UIKit
// Fade animation: https://medium.com/@ludvigeriksson/custom-interactive-uinavigationcontroller-transition-animations-in-swift-4-a4b5e0cefb1e
// Slide animation: https://medium.com/swift2go/simple-custom-uinavigationcontroller-transitions-fdb56a217dd8
class CustomNavigationController: UINavigationController {
private var interactionController: UIPercentDrivenInteractiveTransition?
private var edgeSwipeGestureRecognizer: UIScreenEdgePanGestureRecognizer?
private var panGesturerecognizer: PanDirectionGestureRecognizer?
@zntfdr
zntfdr / firebase-iOS-breakdown.swift
Last active May 28, 2024 12:49
Firebase iOS Version breakdown
// How to:
// 1. Open the Firebase Analytics Dashboard
// 2. Scroll to bottom, where you see the "Users by Device model" widget
// 3. Click "View device models" in that widget (this opens the "Tech details" Firebase Analytics page)
// 4. Above the table shown in the new page, click on the “Device model” drop down menu and select “OS with Version”
// 5. Make sure to select “OS with version” and not “OS Version”
// 6. On the top right corner of the page, click on the “Share this report” icon (next to the date)
// 7. Click “Download file” on the new side bar, then “Download CSV"
// 8. Open the file and select the iOS/Android breakdown raw data
// 9. Replace the sample data in this script with your data
@dubemike
dubemike / Genrics+CellReuse.swift
Created June 21, 2018 10:12
An easier way to dequeue cells in iOS
import Foundation
import UIKit
public protocol ReusableView: class {
static var defaultReuseIdentifier: String { get }
}
extension ReusableView where Self: UIView {
public static var defaultReuseIdentifier: String {
return String(describing: self)
}
@simme
simme / UITabBarController+ToggleTabBar.swift
Created January 25, 2018 15:36
Extension on UITabBarController for hiding/showing the tab bar.
extension UITabBarController {
/**
Show or hide the tab bar.
- Parameter hidden: `true` if the bar should be hidden.
- Parameter animated: `true` if the action should be animated.
- Parameter transitionCoordinator: An optional `UIViewControllerTransitionCoordinator` to perform the animation
along side with. For example during a push on a `UINavigationController`.
*/
@agrcrobles
agrcrobles / android_instructions_29.md
Last active June 2, 2024 05:54 — forked from patrickhammond/android_instructions.md
Setup Android SDK on OSX with and without the android studio

Hi, I am a fork from https://gist.github.com/patrickhammond/4ddbe49a67e5eb1b9c03.

A high level overview for what I need to do to get most of an Android environment setup and maintained on OSX higher Catalina and Big Sur with and without Android Studio been installed.

Considering the SDK is installed under /Users/<your_user>/Library/Android/sdk folder which is the Android Studio preferred SDK location, but it works fine under /usr/local/share/android-sdk as well, which is a location pretty much used on CI mostly.

Prerequisites:

https://github.com/shyiko/jabba instead ?

@pffan91
pffan91 / NetworkLayerWithMoya_fullExample.swift
Last active February 7, 2019 12:46
NetworkLayerWithMoya_fullExample
#1 Moya Target
import Foundation
import Moya
enum MyAPI {
// MARK: - User
case createUser(model: User)
case changePassword(currentPassword: String, newPassword: String)
@lattner
lattner / async_swift_proposal.md
Last active April 21, 2024 09:43 — forked from oleganza/async_swift_proposal.md
Concrete proposal for async semantics in Swift

Async/Await for Swift

Introduction

Modern Cocoa development involves a lot of asynchronous programming using closures and completion handlers, but these APIs are hard to use. This gets particularly problematic when many asynchronous operations are used, error handling is required, or control flow between asynchronous calls gets complicated. This proposal describes a language extension to make this a lot more natural and less error prone.

This paper introduces a first class Coroutine model to Swift. Functions can opt into to being async, allowing the programmer to compose complex logic involving asynchronous operations, leaving the compiler in charge of producing the necessary closures and state machines to implement that logic.

extension Sequence {
/**
Returns a filtered "view" of `self` where only one for all elements that return the same value for `taggingHandler` is kept. In other words: every element in the returned array was the first to return its value from `taggingHandler` when traversing the sequence in order.
```swift
[1, 1, 1, 2, 3, 3, 4, 5, 5, 5].unique { $0 }
// = [1, 2, 3, 4, 5]
[0, 1, -1, -2, 2, -3, -3].unique { abs($0) }