Skip to content

Instantly share code, notes, and snippets.

View erolando's full-sized avatar
🤠

Rolando Avila erolando

🤠
View GitHub Profile
@karigrooms
karigrooms / swiftui-uihostingcontroller-example.swift
Created February 17, 2021 20:50
SwiftUI UIHostingController example for Lessons in SwiftUI blog post
import SwiftUI
import UIKit
class MyViewController: UIViewController {
// this is how you embed a SwiftUI View
lazy var host: UIViewController = {
return UIHostingController(rootView: MySwiftUIView())
}()
@rintoandrews90
rintoandrews90 / xcframework_generate.md
Created December 25, 2020 07:05 — forked from lalkrishna/xcframework_generate.md
Create xcframework instead of Universal(fat) frameworks.

Advantages of xcframework

  • Support for multiple platforms in the same framework.
  • Support for Swift, Objective-C and C.
  • Support for dynamic frameworks and static libraries.
  • Support for Swift Package Manager.
  • End of fat binaries.

Steps to create Aggregate target:

  1. Open Current framework project
@mrackwitz
mrackwitz / AutoHeightLabelView.swift
Created October 27, 2020 19:53
A UILabel-based SwiftUI view which auto-expands to the width of the container, and only expand to render the full height of the label.
struct AutoHeightLabelView: View {
var attributedString: NSAttributedString
var body: some View {
HorizontalGeometryReader { width in
UILabelView(
attributedString: attributedString,
preferredMaxLayoutWidth: width
)
}
@Amzd
Amzd / UIKitTabView.swift
Last active July 14, 2024 20:28
UIKitTabView. SwiftUI tab bar view that respects navigation stacks when tabs are switched (unlike the TabView implementation)
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched.
public struct UIKitTabView: View {
private var viewControllers: [UIHostingController<AnyView>]
private var selectedIndex: Binding<Int>?
@State private var fallbackSelectedIndex: Int = 0
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) {
self.viewControllers = views().map {
let host = UIHostingController(rootView: $0.view)
host.tabBarItem = $0.barItem
@MarioIannotta
MarioIannotta / Decodable+CustomDateFormat.swift
Last active February 3, 2021 06:07
A little extension to easily decode date with custom formats
import Foundation
var json = """
{
"lastSyncDate": "2018-10-28T09:03:59+0000",
"posts": [
{
"id": 0,
"title": "Swift 4 Codable: tips and tricks",
"link": "https://medium.com/@MarioIannotta/swift-4-codable-tips-and-tricks-7ab4674736d2",
import Foundation
public struct Log
{
public static var isEnabled = true
public static func debug(_ m: @autoclosure ()->String, _ file: Any? = #file, _ f: String = #function, _ line: UInt = #line) {
print(m(), file ?? "", f, line)
}
@gonzalezreal
gonzalezreal / KeyedDecodingContainer+EmptyRepresentable.swift
Last active January 11, 2023 08:25
A technique to avoid having optional array properties in your models when decoding JSON using Swift 4
/// A type that has an "empty" representation.
public protocol EmptyRepresentable {
static func empty() -> Self
}
extension Array: EmptyRepresentable {
public static func empty() -> Array<Element> {
return Array()
}
}
@bnickel
bnickel / Queue Playground.swift
Last active June 23, 2020 16:33
Swift retry operation playground
import Foundation
protocol Completable {
func addCompletionOperation(on queue: OperationQueue, complete: @escaping (Self) -> Void) -> Operation
}
extension Completable where Self: Operation {
func addCompletionOperation(on queue: OperationQueue, complete: @escaping (Self) -> Void) -> Operation {
let completionOperation = BlockOperation {
// Basic.swift
extension Notification.Name {
func post(object:Any? = nil, userInfo:[AnyHashable: Any]? = nil) {
NotificationCenter.default.post(self, object: object, userInfo: userInfo)
}
}
// DataModel.swift
extension Notification.Name {
static let AccountBalanceUpdated = Notification.Name("accountBalanceUpdated")
@tadija
tadija / FontNames-iOS-17.4.swift
Last active May 31, 2024 19:23
iOS - All Font Names
/*
*** Academy Engraved LET ***
AcademyEngravedLetPlain
---------------------
*** Al Nile ***
AlNile
AlNile-Bold
---------------------
*** American Typewriter ***
AmericanTypewriter