Skip to content

Instantly share code, notes, and snippets.

View strzempa's full-sized avatar

Patryk Strzemiecki strzempa

View GitHub Profile
@Kievkao
Kievkao / SwiftUI-ScrollView-offset.swift
Created September 9, 2020 07:09
How to get ScrollView offset in SwiftUI
struct ContentView: View {
var body: some View {
ScrollViewOffset(onOffsetChange: { (offset) in
print("New ScrollView offset: \(offset)")
}) {
VStack {
ForEach(0..<100) { index in
Text("\(index)")
}
}
@ethanhuang13
ethanhuang13 / FacebookAuth.swift
Last active March 28, 2024 08:24
FacebookAuth is for iOS app developers who need to support Facebook login but don't want to use the official SDK
//
// FacebookAuth.swift
// GitHub: ethanhuang13
// Twitter: @ethanhuang13
import AuthenticationServices
import SafariServices
/*
Updated:
@KaQuMiQ
KaQuMiQ / TextView.swift
Created March 19, 2020 18:56
Autoresizing text view
import UIKit
public final class TextView: UITextView {
public override init(frame: CGRect, textContainer: NSTextContainer?) {
super.init(frame: frame, textContainer: textContainer)
layoutManager.delegate = self
isScrollEnabled = false
}
@KaQuMiQ
KaQuMiQ / UITextView+Lines.swift
Created March 19, 2020 18:46
Number of text lines in UITextView
extension NSLayoutManager {
var numberOfLines: Int {
var linesCount: Int = 0
var idx: Int = 0
let lineRange: NSRangePointer = .allocate(capacity: 1)
while idx < numberOfGlyphs {
lineFragmentRect(forGlyphAt: idx, effectiveRange: lineRange)
idx = NSMaxRange(lineRange.pointee)
linesCount += 1
}
@KaQuMiQ
KaQuMiQ / Command
Created March 17, 2020 09:58
Swift LLDB pretty print json data
e print(String(data: JSONSerialization.data(withJSONObject: JSONSerialization.jsonObject(with: data, options: []), options: .prettyPrinted), encoding: .utf8)!)
@KaQuMiQ
KaQuMiQ / Cryptor.swift
Last active March 7, 2023 08:24
EasyAES
import Foundation
import CommonCrypto
internal enum CryptoError: Error {
case emptyData
case invalidData
case invalidKey
case fail(status: CCStatus)
}
import UIKit
public protocol UITableViewHeaderFooterViewIdentifiable: UITableViewHeaderFooterView {
static var identifier: String { get }
}
public extension UITableViewHeaderFooterViewIdentifiable where Self: UITableViewHeaderFooterView {
static var identifier: String {
return String(describing: self)
}
import Foundation
public extension UIApplication {
class func tryURL(_ urls: [String]) {
let application = UIApplication.shared
urls.forEach { urlString in
guard let url = URL(string: urlString) else {
Logger.error?.message("Cannot make url from: \(urlString)")
return
}
@strzempa
strzempa / ProgressObservableWebViewController.swift
Last active October 11, 2019 05:22
WKWebViewController with secure progress observation, progressView and activityIndicatorView
import UIKit
import WebKit
open class ProgressObservableWebViewController: UIViewController, WKWebViewProgressObservable {
@IBOutlet weak public var webView: WKWebView!
public var webViewProgressObservation: Any?
private let progressView: UIProgressView = {
let view = UIProgressView(progressViewStyle: .default)
@freak4pc
freak4pc / Combine+WithLatestFrom.swift
Last active February 19, 2024 15:35
withLatestFrom for Apple's Combine
//
// Combine+WithLatestFrom.swift
//
// Created by Shai Mishali on 29/08/2019.
// Copyright © 2019 Shai Mishali. All rights reserved.
//
import Combine
// MARK: - Operator methods