Skip to content

Instantly share code, notes, and snippets.

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

Sergey Dikarev ArchieGoodwin

🏠
Working from home
View GitHub Profile
@ArchieGoodwin
ArchieGoodwin / gist:eaf3e1505c4cec500c640d2b56de2ec6
Created February 9, 2023 10:05
WKWebView helper class for SwiftUI with support of detecting url redirect
import SwiftUI
import WebKit
typealias WebCallBack = ((String?) -> Void)?
class MyWKDelegate: NSObject, WKNavigationDelegate {
private var webCallBack: WebCallBack = nil
init(webCallBack: WebCallBack) {
self.webCallBack = webCallBack
@ArchieGoodwin
ArchieGoodwin / KeyPad
Created February 1, 2023 13:25
KeyPad with support for long tap repeat digit
import SwiftUI
struct KeyPad: View {
@Binding var string: String
var action: () -> Void
var body: some View {
VStack {
KeyPadRow(keys: ["1", "2", "3"])
KeyPadRow(keys: ["4", "5", "6"])
KeyPadRow(keys: ["7", "8", "9"])
@ArchieGoodwin
ArchieGoodwin / SkeletonView
Created February 1, 2023 13:10
Basic skeleton view for usage in SwiftUI app.
public struct SkeletonGradientAnimationView: View {
@State var offset: CGFloat = 0
public var body: some View {
ZStack {
GeometryReader { reader in
let largestSide = reader.size.width > reader.size.height ? reader.size.width : reader.size.height
LinearGradient(
@ArchieGoodwin
ArchieGoodwin / gist:e0ece7770eeb6c747cde9b4b281186ce
Created October 23, 2017 09:14
Add border to any side of UIView
import Foundation
extension UIView{
func border(color : UIColor, side : String, width : CGFloat)
{
var borderFrame = CGRect.zero
switch side {
case "left":
borderFrame = CGRect(x: 0.0, y: 0.0, width: width, height: self.frame.size.height)
@ArchieGoodwin
ArchieGoodwin / gist:6d2d8f978c2921cfc59d94e4f75fc17d
Created December 15, 2016 09:16
group dispatch in swift 3
let backgroundQ = DispatchQueue.global(attributes: .qosDefault)
let group = DispatchGroup()
var someData:[Data] = []
for number in 0..<n {
group.enter()
backgroundQ.async(group: group, execute: {
if number > 50 {
fill.append(number)
}
@ArchieGoodwin
ArchieGoodwin / ContactsManager.swift
Created July 14, 2016 15:40
helper class for Contacts Framework
//
// ContactsManager.swift
// main
//
// Created by Nero Wolfe on 14/07/16.
// Copyright © 2016 Incoding. All rights reserved.
//
import UIKit
import Contacts
@ArchieGoodwin
ArchieGoodwin / gist:d07895ac1481d20af509ec08c93a6119
Last active May 23, 2016 18:58
Shows message for given time in upper part of screen above all windows including status bar (swift)
func showMessage(message : String, delay : NSTimeInterval, color : UIColor, completion: boolClosure?)
{
dispatch_async(self.GlobalMainQueue)
{
guard let window = appDelegate.window else
{
completion!(result: false,error: nil)
return
}
@ArchieGoodwin
ArchieGoodwin / gist:7d7b76e10c952d1ada05
Created August 16, 2015 12:30
CoreSpotlight search index addition in swift
func spotLighIndexingForContact(contact: MainContact) -> AnyObject
{
if #available(iOS 9, *) {
let attributeSet : CSSearchableItemAttributeSet = CSSearchableItemAttributeSet(itemContentType: kUTTypeImage as String)
let name : String = contact.firstname + " " + contact.lastname
attributeSet.title = name
attributeSet.contentDescription = "Main Contact"
@ArchieGoodwin
ArchieGoodwin / Address Book helper
Created June 30, 2015 11:33
Address Book helper in swift (create contact, get contact, add to group and so on)
//MARK: Address Book methods
func createAddressBook() -> Bool {
if self.adbk != nil {
return true
}
var err : Unmanaged<CFError>? = nil
let adbk : ABAddressBook? = ABAddressBookCreateWithOptions(nil, &err).takeRetainedValue()
if adbk == nil {
print(err)
@ArchieGoodwin
ArchieGoodwin / gist:10571582
Created April 13, 2014 06:26
UUID generate
f you are on OS X 10.8 or iOS 6 you can use the new NSUUID class to generate a string UUID, without having to go to Core Foundation:
NSString *uuidString = [[NSUUID UUID] UUIDString];
// Generates: 7E60066C-C7F3-438A-95B1-DDE8634E1072
But mostly, if you just want to generate a unique string for a file or directory name then you can use NSProcessInfo's globallyUniqueString method like:
NSString *uuidString = [[NSProcessInfo processInfo] globallyUniqueString];
// generates 56341C6E-35A7-4C97-9C5E-7AC79673EAB2-539-000001F95B327819
It's not a formal UUID, but it is unique for your network and your process and is a good choice for a lot of cases.