Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Sergey Vinogradov w-i-n-s

🏠
Working from home
  • Varna, Bulgaria
View GitHub Profile
@ljbatwh
ljbatwh / PagerManager.swift
Created Aug 9, 2020
swiftui page controller
View PagerManager.swift
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
View ContentView.swift
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")
View PageView.swift
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 Nov 13, 2021
[SwiftUI] MacEditorTextView - A simple and small NSTextView wrapped by SwiftUI.
View MacEditorTextView.swift
/**
* MacEditorTextView
* Copyright (c) Thiago Holanda 2020-2021
* https://twitter.com/tholanda
*
* MIT license
*/
import Combine
import SwiftUI
@maltekrupa
maltekrupa / basic-auth.swift
Last active Sep 10, 2021
HTTP Basic Authentication using URLSession and URLCredentialStorage in swift 4 with xcode 9
View basic-auth.swift
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 Feb 27, 2017
Bridges CoreGraphics.CGPathApplierFunction with a standard Swift closure
View CGPathApply.swift
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 Dec 29, 2016
PHPhotoLibrary+SaveImage - save image with Photos Framework swift 3
View PHPhotoLibrary+SaveImage
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 Aug 5, 2021
Copy database file from bundle to documents in Swift 3
View .swift
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 Nov 4, 2020
Custom UIActivity in Swift 3
View CustomActivity.swift
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 Jul 8, 2019
Networking Request in Xcode 8.0 Playground.
View Networking.swift
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 {