Skip to content

Instantly share code, notes, and snippets.

View ramiresnas's full-sized avatar

Ramires Moreira ramiresnas

View GitHub Profile
@ramiresnas
ramiresnas / .swift
Created April 26, 2018 02:35
controle do teclado
class ViewController: UIViewController , UITextFieldDelegate{
@IBOutlet weak var scrollView : UIScrollView!
@IBOutlet var textFields: [UITextField]!
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: .UIKeyboardWillShow , object: nil)
@ramiresnas
ramiresnas / .swift
Created June 11, 2018 14:30
Request in swift
//
// Router.swift
// TestMasterDetail
//
// Created by Ramires Moreira on 5/20/18.
// Copyright © 2018 Ada 2018. All rights reserved.
//
import Foundation
@ramiresnas
ramiresnas / .swift
Created August 7, 2018 14:24
create a property list
//MARK: PList
func createPList() {
let fm = FileManager.default
let docDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
guard let dir = docDirectory else {return}
let path = dir.appending("/example.plist")
if !fm.fileExists(atPath: path) {
let dict = [["name":"Ramires","age":24,"salary":798.89],["name":"Bia","age":18,"salary":798.89]] as NSArray
if dict.write(toFile: path, atomically: true) {
print("created on \(path)")
@ramiresnas
ramiresnas / .swift
Created August 10, 2018 12:19
UserDefaults
//escrevendo
let user = User(email: "ramires.nas@gmail.com", password: "academy2018")
if let userDefaults = UserDefaults(suiteName: "group.com.ramires") {
do {
let data = try JSONEncoder().encode(user)
userDefaults.set(data, forKey: "user")
}catch {
print(error.localizedDescription)
}
}
@ramiresnas
ramiresnas / .swift
Created August 10, 2018 12:24
UserDefaults
let defaults = UserDefaults.standard
defaults.set(1.5, forKey: "velocidade")
//depois você pode ler essa informação usando
let velocidade = defaults.float(forKey: "velocidade")

Note

Apple will reject apps that are using private url schemes (Ugh, Apple....) if they are pretty much obvius. Some apps are rejected and others are not, so, be aware of this issue before implementing any of those URL's in your app as a feature.

Updates

  • [UPDATE 4] iOS 10 update: apparently settings now can be reached using App-Pref instead of prefs
  • [UPDATE 3] For now you just can use url schemes to open your apps's settings with Swift 3.0 (Xcode 8). I'll keep you informed when OS preferences can be reached
  • [UPDATE 2] The openURL() method of UIApplication is now deprecated. You should use application(_:open:options:) instead
  • [UPDATE 1] Not yet tested in iOS 10. It will fail because of policies changes in URL scheme handling.
@ramiresnas
ramiresnas / .java
Created December 24, 2018 15:23
Reader file from resource folder when use maven.
/**
* This code snippet help you read file content from resorce folder.
* When you use the maven, the method:
*
* this.getClass().getResource(fileName)
*
* Don't work, so to resolve this problem, we use the this.getClass().getResourceAsStream(fileName)
* and we read all content of file. This code snippet was only tested with text content, ex: file.txt, person.json and so on.
*/
@ramiresnas
ramiresnas / .js
Created February 19, 2019 21:59
Service
export default class Service {
constructor(){
this.host = process.env.API_URL
const headers = new Headers()
const token = sessionStorage.getItem('token')
headers.append('Authorization',`Bearer ${token}`)
this.options = {
headers : headers,
method : 'GET',
@ramiresnas
ramiresnas / .js
Created February 19, 2019 22:01
PedidoService
import Service from './Service'
export default class PedidoService extends Service {
getPedidosAlteracoesDoCampus(campus){
return super.get(`/pedidos/pedidos_alteracoes/${campus}`)
}
getPedidosAlteracoes(){
return super.get(`/pedidos/pedidos_alteracoes/servidor`)
}
@ramiresnas
ramiresnas / .swift
Created February 25, 2019 14:01
Comunicação com GameController
override func viewDidLoad() {
super.viewDidLoad()
let center = NotificationCenter.default
let notification: NSNotification.Name = Notification.Name.GCControllerDidConnect
let selector = #selector(didConnection)
center.addObserver(self, selector: selector, name: notification, object: nil)
}
@objc func didConnection(){