Skip to content

Instantly share code, notes, and snippets.

View w-i-n-s's full-sized avatar
🏠
Working from home

Sergey Vinogradov w-i-n-s

🏠
Working from home
  • Varna, Bulgaria
View GitHub Profile
@ljbatwh
ljbatwh / PagerManager.swift
Created August 9, 2020 22:47
swiftui page controller
import SwiftUI
struct PagerManager<Content: View>: View {
let pageCount: Int
@Binding var currentIndex: Int
let content: Content
//Set the initial values for the variables
init(pageCount: Int, currentIndex: Binding<Int>, @ViewBuilder content: () -> Content) {
self.pageCount = pageCount
struct ContentView: View {
@State private var currentPage = 0
var body: some View {
//Pager Manager
VStack{
PagerManager(pageCount: 2, currentIndex: $currentPage) {
Text("First page")
Text("Second page")
@masamichiueta
masamichiueta / PageView.swift
Created October 12, 2019 04:19
SwiftUI PageView
import SwiftUI
import UIKit
struct PageViewController: UIViewControllerRepresentable {
var controllers: [UIViewController]
@Binding var currentPage: Int
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
@unnamedd
unnamedd / MacEditorTextView.swift
Last active April 16, 2024 10:18
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@maltekrupa
maltekrupa / basic-auth.swift
Last active September 10, 2021 05:18
HTTP Basic Authentication using URLSession and URLCredentialStorage in swift 4 with xcode 9
import Foundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let credential = URLCredential(user: “username@gmail.com”, password: “password”, persistence: URLCredential.Persistence.forSession)
let protectionSpace = URLProtectionSpace(host: "example.com", port: 443, protocol: "https", realm: "Restricted", authenticationMethod: NSURLAuthenticationMethodHTTPBasic)
URLCredentialStorage.shared.setDefaultCredential(credential, for: protectionSpace)
let config = URLSessionConfiguration.default
@swhitty
swhitty / CGPathApply.swift
Created February 27, 2017 11:15
Bridges CoreGraphics.CGPathApplierFunction with a standard Swift closure
extension CGPath {
func apply(action: @escaping (CGPathElement)->()) {
var action = action
apply(info: &action) {
let action = $0!.bindMemory(to: ((CGPathElement)->()).self, capacity: 1).pointee
action($1.pointee)
}
}
}
@khorbushko
khorbushko / PHPhotoLibrary+SaveImage
Created December 29, 2016 09:27
PHPhotoLibrary+SaveImage - save image with Photos Framework swift 3
import UIKit
import Photos
extension PHPhotoLibrary {
// MARK: - PHPhotoLibrary+SaveImage
// MARK: - Public
func savePhoto(image:UIImage, albumName:String, completion:((PHAsset?)->())? = nil) {
func save() {
@rd13
rd13 / .swift
Last active September 11, 2022 17:00
Copy database file from bundle to documents in Swift 3
func copyDatabaseIfNeeded() {
// Move database file from bundle to documents folder
let fileManager = FileManager.default
let documentsUrl = fileManager.urls(for: .documentDirectory,
in: .userDomainMask)
guard documentsUrl.count != 0 else {
return // Could not find documents URL
@shu223
shu223 / CustomActivity.swift
Last active November 4, 2020 17:59
Custom UIActivity in Swift 3
import UIKit
class CustomActivity: UIActivity {
override class var activityCategory: UIActivityCategory {
return .action
}
override var activityType: UIActivityType? {
guard let bundleId = Bundle.main.bundleIdentifier else {return nil}
@ozgurshn
ozgurshn / Networking.swift
Last active July 8, 2019 09:07
Networking Request in Xcode 8.0 Playground.
import UIKit
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let url = URL(string: "http://ip.jsontest.com/")!
let session = URLSession.shared()
let q = session.dataTask(with: url) { data, response, error in
do {