Skip to content

Instantly share code, notes, and snippets.

View runys's full-sized avatar

Tiago Pereira runys

View GitHub Profile
@runys
runys / local-notification.swift
Last active May 9, 2017 14:32
Simple local notification in swift for iOS 10 with Swift 3
// Referencias
// - https://www.appcoda.com/ios10-user-notifications-guide/
// - http://useyourloaf.com/blog/local-notifications-with-ios-10/
// - https://makeapppie.com/2016/08/08/how-to-make-local-notifications-in-ios-10/
// - https://developer.apple.com/reference/usernotifications
//: Local notifications
// 1. Importe o framework UserNotifications
import UserNotifications
@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
# ---------------------------------------------------------------------------
#
# Description: This file holds all my BASH configurations and aliases
#
# Sections:
# 1. Environment Configuration
# 2. Make Terminal Better (remapping defaults and adding functionality)
# 3. File and Folder Management
# 4. Searching
# 5. Process Management
@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 / date-and-time.swift
Created February 13, 2017 18:41
Ways to work with date and time in iOS 10 and Swift 3.
// 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 January 9, 2017 18:57
Simple Camera and Picture Library Tutorial using iOS 10 and Swift 3.
/*:
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:
@runys
runys / dismiss-keyboard.swift
Created December 27, 2016 14:48
How to dismiss the keyboard in iOS 10 with Swift 3.
// Dissmiss keyboard iOS
// Referências
// - http://stackoverflow.com/questions/18755410/how-to-dismiss-keyboard-ios-programmatically
// Existem algumas formas de esconder o teclado no iOS
// Aqui vamos ver algumas delas!
// 1. Implementando o UITextFieldDelegate e quando o usuário
// apertar no RETURN do teclado, terminamos a edição.
@runys
runys / reta.cpp
Last active August 29, 2015 14:07
Estudo da reta
#include <iostream>
#include <cmath>
#include <cstdio>
#define DIREITA -1
#define ESQUERDA 1
#define SOBRE 0
using namespace std;