Skip to content

Instantly share code, notes, and snippets.

View wzbozon's full-sized avatar

Denis Kutlubaev wzbozon

View GitHub Profile
@ricardopereira
ricardopereira / SubscriptionTests.swift
Created September 13, 2021 17:17
Using the SKTestSession in XCTest.
import XCTest
import StoreKitTest
@available(iOS 14.0, *)
class SubscriptionTests: XCTestCase {
private var session: SKTestSession!
private var subscriptionsController: SubscriptionsController!
override func setUpWithError() throws {
@gabrieltheodoropoulos
gabrieltheodoropoulos / PressActionsModifier.swift
Created November 1, 2020 17:56
PressActions modifier - Handle press and release events in SwiftUI
struct PressActions: ViewModifier {
var onPress: () -> Void
var onRelease: () -> Void
func body(content: Content) -> some View {
content
.simultaneousGesture(
DragGesture(minimumDistance: 0)
.onChanged({ _ in
onPress()
@quangDecember
quangDecember / Simple-browser-WKWebView-UIKit.md
Last active November 2, 2023 08:45
Creating Simple Web Browser with WKWebView & UINavigationController

WKWebView was first introduced on iOS 8. With Apple finally release a deadline for all apps to migrate away from UIWebView, this series and this post is here to help you explore the features of WKWebView. In this blog post you will create a simple web browser with some basic features such as displaying content, back and forward.

Setup Previews for your project

One of the most interesting things coming out with Xcode 11 is SwiftUI's PreviewProvider, which provides a way to preview the UI during development instantly on multiple devices, multiple settings at the same time.

To preview UIViewController and UIView, you need to download previewing code from NSHipster

Since we are making this browser with a navigation bar, our main UIViewController needs to be embedded inside a UINavigationController. Therefore the previewing code would be like this:

@CassiusPacheco
CassiusPacheco / UserDefaultsPropertyWrapper.swift
Created March 2, 2020 01:37
Testable @UserDefaults property wrapper
import Foundation
public protocol UserDefaultsInterface {
func set(_ value: Any?, forKey defaultName: String)
func object(forKey defaultName: String) -> Any?
}
extension UserDefaults: UserDefaultsInterface {}
class UserDefaultsMock: UserDefaultsInterface {
@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
}
@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")
}
@robertpainsi
robertpainsi / commit-message-guidelines.md
Last active October 30, 2024 19:51
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: "Fix bug" and not "Fixed
bug" or "Fixes bug." This convention matches up with commit messages
import Foundation
import RxSwift
extension ObservableType where E == Bool {
func negate() -> Observable<Bool> {
return map(!)
}
}
//
// CLGeocoder+Rx.swift
//
// Created by Daniel Tartaglia on 5/7/16.
// Copyright © 2018 Daniel Tartaglia. MIT License.
//
import RxSwift
import CoreLocation
import Contacts
@h2non
h2non / json-post.swift
Last active September 11, 2022 01:38
JSON POST example with Alamofire
let parameters = [
"username": "foo",
"password": "123456"
]
Alamofire.request(.POST, "https://httpbin.org/post", parameters: parameters, encoding: .JSON)
// -> HTTP body: {"foo": [1, 2, 3], "bar": {"baz": "qux"}}