Skip to content

Instantly share code, notes, and snippets.

View schwjustin's full-sized avatar

Justin Schwartz schwjustin

View GitHub Profile
import { prefixStorage } from "unstorage";
import type { Storage } from "unstorage";
type Session = {
id: string
userId: string
expiredAt: Date
}
@alexpaul
alexpaul / Swift-Language-Primer.md
Created May 20, 2021 18:44
Swift Language Primer

Swift Language Primer

Types and Variables

Swift is a compiled, strongly-typed language. The compiler uses type inference to identify the type of an object, or you can explicitly use type annotation.

Type Inference

var favoritePeanut = "Charlie Brown" // String
extension UIHostingController {
convenience public init(rootView: Content, ignoreSafeArea: Bool) {
self.init(rootView: rootView)
if ignoreSafeArea {
disableSafeArea()
}
}
func disableSafeArea() {
@stleamist
stleamist / PageView.swift
Created May 19, 2020 11:08
A representation of UIPageViewController in SwiftUI.
import SwiftUI
struct PageView<Page: View>: UIViewControllerRepresentable {
var pages: [Page]
@Binding var currentPage: Int
func makeUIViewController(context: Context) -> UIPageViewController {
let pageViewController = UIPageViewController(transitionStyle: .scroll, navigationOrientation: .horizontal)
//
// ContentView.swift
//
// Created by Chris Eidhof on 20.04.20.
// Copyright © 2020 objc.io. All rights reserved.
//
import SwiftUI
import UIKit
@alexpaul
alexpaul / AccessToRootViewController.swift
Last active June 21, 2024 05:06
Getting access to the SceneDelegate window object in Xcode 11. SceneDelegate. Reset application window. Reset window. Reset rootviewcontroller. Root view controller. Scene delegate.
// accessing the window and changing the root view controller property
override func viewDidLoad() {
super.viewDidLoad()
// getting access to the window object from SceneDelegate
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let sceneDelegate = windowScene.delegate as? SceneDelegate
else {
return
}
let viewcontroller = UIViewController()
@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)
}
@kunofellasleep
kunofellasleep / InstaStories.swift
Created February 27, 2019 08:14
Share on Instagram stories
import UIKit
class InstaStories: NSObject {
private let urlScheme = URL(string: "instagram-stories://share")!
enum optionsKey: String {
case StickerImage = "com.instagram.sharedSticker.stickerImage"
case bgImage = "com.instagram.sharedSticker.backgroundImage"
case bgVideo = "com.instagram.sharedSticker.backgroundVideo"