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 / 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 / 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 / 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 / ui.swift
Last active May 3, 2017 20:00
How to add interface elements through code in iOS 10 with Swift 3
import UIKit
class ViewController: UIViewController {
/*
Como adicionar elementos na interface pelo código?
Cada componente da interface no iOS é um objeto da classe UIView ou que herda da classe UIView.
Componentes como botões, labels, image views e table views, possuem sua respectiva classe que por consequência herda de UIView.
Toda UIViewController, ou seja, classe que herda de UIViewController, possue uma propriedade chamada view. Essa propriedade se refere a tela da view que a view controller comanda. Quando vamos adicionar componentes na interface pelo código temos que adicionar o componente na view da view controller.
@runys
runys / user-defaults.swift
Created May 3, 2017 18:04
How to use UserDefaults to record information in iOS 10 with Swift 3.0
/*:
## Usando UserDefaults
- [API Reference: UserDefaults](https://developer.apple.com/reference/foundation/userdefaults)
O User Defaults é uma forma que temos para armazenar informações a respeito da aplicação, como pequenas configurações e preferências do usuário.
Nele podemos armazenar informações em um dicionário. Os tipos de dados que podemos armazenar são:
- Data
@runys
runys / simple-animation.swift
Last active March 27, 2017 20:10
How to create simple animations using iOS 10 and Swift 3. (Xcode Playground)
import UIKit
/*:
#### Animações básicas
- Ref: [Getting Started](https://www.raywenderlich.com/146603/ios-animation-tutorial-getting-started-2)
- Ref: [Custom View Controller Presentation Transitions](https://www.raywenderlich.com/146692/ios-animation-tutorial-custom-view-controller-presentation-transitions-2)
Para animar componentes do UIKit podemos utilizar o método de animação básico
*/
@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)