Skip to content

Instantly share code, notes, and snippets.

Avatar

Tiago Pereira runys

  • Apple Developer Academy
  • Naples, Italy
View GitHub Profile
@runys
runys / SquareGame-After.swift
Last active Mar 2, 2022
Example code of a simple integration between SwiftUI and SpriteKit using the delegate pattern.
View SquareGame-After.swift
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 Aug 4, 2021
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)
View CoffeTimeApp.swift
// 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 Jun 16, 2021
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
View CareKitDetailedCardView.swift
// 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 Jun 7, 2021
How to read Property Lists in iOS 10 with Swift 3
View plist.swift
/*
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
How to add interface elements through code in iOS 10 with Swift 3
View ui.swift
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
How to use UserDefaults to record information in iOS 10 with Swift 3.0
View user-defaults.swift
/*:
## 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 Mar 27, 2017
How to create simple animations using iOS 10 and Swift 3. (Xcode Playground)
View simple-animation.swift
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 Mar 8, 2017
Tutorial about how to create a simple page view application in iOS 10 with Swift 3. Originally create to be seen in a playground.
View page-view-controller.swift
/*:
## 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 / date-and-time.swift
Created Feb 13, 2017
Ways to work with date and time in iOS 10 and Swift 3.
View date-and-time.swift
// 1. Como transformar Date em String?
let today = Date()
// 1: Criamos um NSDateFormatter
let dateFormatter = DateFormatter()
// 2: Definimos o formato da data
dateFormatter.dateFormat = "EEE, dd MMM yyy hh:mm:ss +zzzz"
@runys
runys / image-picker.swift
Created Jan 9, 2017
Simple Camera and Picture Library Tutorial using iOS 10 and Swift 3.
View image-picker.swift
/*:
Simples tutorial sobre como utilizar a Camera e a Biblioteca de fotos para capturar imagens e utilizá-las em seu aplicativo
Referências:
- https://makeapppie.com/2016/06/28/how-to-use-uiimagepickercontroller-for-a-camera-and-photo-library-in-swift-3-0/
- https://turbofuture.com/cell-phones/Access-Photo-Camera-and-Library-in-Swift
Antes de qualquer coisa, precisamos pedir autorização do usuário para acessarmos a camera e a biblioteca de fotos.
Para isso vá no info.plist e adicione as seguintes chaves: