Skip to content

Instantly share code, notes, and snippets.

View runys's full-sized avatar

Tiago Pereira runys

View GitHub Profile
@runys
runys / LocationManager.swift
Created October 6, 2023 13:26
Location Manager service providing an asynchronous way of accessing the user current location.
import CoreLocation
class LocationManager: NSObject, CLLocationManagerDelegate {
//MARK: Object to Access Location Services
private let locationManager = CLLocationManager()
//MARK: Set up the Location Manager Delegate
override init() {
super.init()
@runys
runys / SquareGame-After.swift
Last active July 14, 2023 01:28
Example code of a simple integration between SwiftUI and SpriteKit using the delegate pattern.
import SwiftUI
import SpriteKit
protocol SquareGameLogicDelegate {
var totalScore: Int { get }
mutating func addPoint() -> Void
}
// 1. Conform the ContentView to the SquareLogicDelegate protocol
@runys
runys / 1-ProductPageView.swift
Last active May 31, 2023 10:21
Example used in the article Preparing your App for Voice Over: Labels, Values and Hints on Create with Swift (https://www.createwithswift.com/)
struct Product {
let name: String
let type: String
let description: String
let imageName: String
}
struct ProductPageView: View {
@runys
runys / CoffeTimeApp.swift
Last active August 4, 2021 10:13
Sample code for the article User Interaction with Notifications with async/await (https://www.createwithswift.com/p/6c6bca46-a2b9-4f9e-97c5-a061f637e45c/) on Create with Swift (https://www.createwithswift.com)
// CoffeeTimeApp.swift
// Created by Tiago Pereira on 23/07/21.
import SwiftUI
@main
struct CoffeeTimeApp: App {
// 8. Set up our class as the application delegate
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@runys
runys / CareKitDetailedCardView.swift
Last active June 16, 2021 17:00
Using the new view GroupBox from SwiftUI 3 released for iOS 15 on WWDC 2021 to replicate the interface of a Detailed Contact Card View from the CareKit framework. You can see the reference view at: https://developer.apple.com/design/human-interface-guidelines/carekit/overview/views/#contacts
// Xcode 13 + iOS 15
struct CareKitDetailedCardView: View {
var body: some View {
VStack(alignment: .leading) {
// The header of the card
// - Photo, Full Name and Professional Title
HStack {
Circle()
.frame(width: 40, height: 40)
.foregroundColor(.gray)
@runys
runys / plist.swift
Last active June 7, 2021 07:39
How to read Property Lists in iOS 10 with Swift 3
/*
O que é um Property List (PList)?
- Ref: [Apple: About Info.plist](https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html)
- Ref: [Apple: Introduction to Property Lists](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PropertyLists/Introduction/Introduction.html)
- Ref: [](https://makeapppie.com/2016/02/11/how-to-use-property-lists-plist-in-swift/)
É um tipo de arquivo que pode armazenar informações de maneira estruturada.
Um plist é um arquivo que utiliza um notação XML para organizar a informação.
@runys
runys / activity-indicator.swift
Last active April 18, 2019 14:45
Activity indicator in iOS 11 with Swift 4
// Create the Activity Indicator
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
// Add it to the view where you want it to appear
view.addSubview(activityIndicator)
// Set up its size (the super view bounds usually)
activityIndicator.frame = view.bounds
// Start the loading animation
activityIndicator.startAnimating()
@runys
runys / page-view-controller.swift
Created March 8, 2017 13:48
Tutorial about how to create a simple page view application in iOS 10 with Swift 3. Originally create to be seen in a playground.
/*:
## Tutorial de UIPageViewController
Referências:
- [How to Use UIPageViewController in Swift 2.2](https://spin.atomicobject.com/2015/12/23/swift-uipageviewcontroller-tutorial/)
- [How to Move Page Dots in a UIPageViewController with Delegation](https://spin.atomicobject.com/2016/02/11/move-uipageviewcontroller-dots/)
- [](https://developer.apple.com/reference/uikit/uipageviewcontroller)
- [](https://developer.apple.com/reference/uikit/uipageviewcontrollerdatasource)
- [](https://developer.apple.com/reference/uikit/uipageviewcontrollerdelegate)
@runys
runys / search-controller.swift
Last active September 27, 2018 14:47
Search Controller in Table View Controller in iOS 11 with Swift 4. From: https://www.raywenderlich.com/113772/uisearchcontroller-tutorial
// The code bellow must be written in your Table View Controller
// Remember to use your own classes and properties when creating your own search.
// 1. Create a new property in your class
// The Search Controller is the responsible to do the "searching magic"
let searchController = UISearchController(searchResultsController: nil)
// 2. At the viewDidLoad() add those initializations
searchController.searchResultsUpdater = self // You will get an error here for now, but it will vanish at step number 5
searchController.dimsBackgroundDuringPresentation = false
@runys
runys / alert.swift
Last active December 20, 2017 09:54
Simples alert for iOS 11 with Swift 4.
// 1. Creating the AlertController
let alert: UIAlertController = UIAlertController(title: "Teste",
message: "Aprendendo a fazer alertas",
preferredStyle: .alert)
// 1.1. Create the actions
let okAction = UIAlertAction(title: "OK", style: .default) { (okAction) in
// Insert here the code to be executed when the user select the action
print("O usuário escolheu: \(okAction.title!)")
}