Skip to content

Instantly share code, notes, and snippets.

View yuraist's full-sized avatar
🚀
Building something...

Yuri Istomin yuraist

🚀
Building something...
View GitHub Profile
@yuraist
yuraist / RemindersSync.swift
Created August 18, 2020 16:22
Synchronise tasks from the Reminders app within your iOS app using EventKit.
import EventKit
class RemindersSync {
let eventStore = EKEventStore()
var remindersCalendar: EKCalendar? = nil
var reminders: [EKReminder] = []
/// Requests access to the Reminders app
import SwiftUI
// MARK: - Root view
struct SheetPresenterView: View {
@State private var isPresented = false
var body: some View {
Button(action: showSheet) {
@yuraist
yuraist / TestView.swift
Last active May 16, 2021 11:50
View isn't updating with zIndex in ForEach
import SwiftUI
struct TestItemView: View {
@State var dragAmount = CGSize.zero
let letter: String
var body: some View {
Image(systemName: "\(letter).square")
import SwiftUI
class Task: ObservableObject, Identifiable {
let id = UUID()
var text: String
var done: Bool
init(text: String, done: Bool = false) {
self.text = text
self.done = done
@yuraist
yuraist / Extensions+UITextField.swift
Created July 10, 2019 08:21
UITextField Phone Number Format
import UIKit
extension UITextField {
func handlePhoneNumberField(withReplacingString string: String, in range: NSRange) {
let textFieldString = text! as NSString
var newString = textFieldString.replacingCharacters(in: range, with: string)
let validationSet = CharacterSet.decimalDigits.inverted
let numberArray = newString.components(separatedBy: validationSet)
@yuraist
yuraist / Extensions+String.swift
Created May 13, 2019 13:59
Swift String type extension for a height and width estimation
extension String {
func height(withConstraintWidth width: CGFloat, font: UIFont = UIFont.systemFont(ofSize: 17)) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect,
options: .usesLineFragmentOrigin,
attributes: [NSAttributedString.Key.font: font],
context: nil)
return ceil(boundingBox.height)
@yuraist
yuraist / Extensions+UIColor.swift
Created March 13, 2019 12:34
UIColor extension for simple rgb(red:green:blue) method
extension UIColor {
static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
}
}
@yuraist
yuraist / Extensions+UIView.swift
Last active March 14, 2019 23:44
Swift UIView Extension for convenient work with Auto Layouts
extension UIView {
func anchor(top: NSLayoutYAxisAnchor?, leading: NSLayoutXAxisAnchor?, bottom: NSLayoutYAxisAnchor?, trailing: NSLayoutXAxisAnchor?, padding: UIEdgeInsets = .zero, size: CGSize = .zero) {
translatesAutoresizingMaskIntoConstraints = false
if let top = top {
topAnchor.constraint(equalTo: top, constant: padding.top).isActive = true
}
if let leading = leading {
leadingAnchor.constraint(equalTo: leading, constant: padding.left).isActive = true