Skip to content

Instantly share code, notes, and snippets.

View kolathee's full-sized avatar
🎯
Focusing

Kolathee kolathee

🎯
Focusing
  • Agoda
  • Bangkok
View GitHub Profile
@kolathee
kolathee / Embed-Firebase-Medium.swift
Last active December 28, 2016 05:06
Firebase - Overview
import UIKit
// 1 import Firebase
import FirebaseDatabase
// 2 create a reference (fromURL: ,etc)
let referance = FIRDatabase.database().reference(fromURL: "....")
// 3 Attach a closure to read the data
referance.observe(.childAdded, with:{ (snapshot) in
@kolathee
kolathee / Embed-Firebase-Medium.swift
Last active December 28, 2016 05:07
Firebase - sample #QueryLimited
/*
users
.
...AX4FE3W21l9
. .
. ...email : "test@gmail.com"
. .
. ...age : "18"
. .
. ...name : "Kolathee"
@kolathee
kolathee / Embed-Firebase-Medium.swift
Last active December 28, 2016 05:07
Summary - Firebase
// import
import Firebase
import FirebaseDatabase
import FireAuth
// Data reference
let referance = FIRDatabase.database().reference(fromURL: "https://...com")
let referance = FIRDatabase.database().reference(fromURL: "https://...com").child("users").child(ID)
let referance = FIRDatabase.database().reference(fromURL: "https://...com").child("users/KI2PEQ4W1")
@kolathee
kolathee / AVFoundation.swift
Created December 26, 2016 19:36
AVFoundation Framework (Playing Sound)
import AVFoundation
let url = NSURL(string: "http://radiowink.wink.in.th")! as URL
private var player = AVPlayer(url:url)
player.play()
player.pause()
@kolathee
kolathee / PickerView.swift
Last active December 28, 2016 05:07
PickerView
//1.Inheritance UIPickerViewDelegate, UIPickerViewDataSource
class RadioVC: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var pickerView: UIPickerView!
//2.Create data source for picker view
let pickerData = ["Tree","Cup","Goal","Blast"]
override func viewDidLoad() {
super.viewDidLoad()
//3.Set delegate
@kolathee
kolathee / Embed-Map-GeoFire-Medium.swift
Last active August 11, 2018 22:17
MapKit And GeoFire - Example
//====== MapKit ======================================
// 1.Import MapKit
import Mapkit
// 2.Imprement MKMapViewDelegate, CLLocationManagerDelegate
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet weak var mapView: MKMapView!
@kolathee
kolathee / Embed-Map-GeoFire-Medium.swift
Last active December 28, 2016 07:22
Embedding - To pan the map
//Get previous map center
mapCenter = myMapView.centerCoordinate
//Set new location
mapCenter = mapView.convert(CGPoint.init(x: 1, y: mapView.frame.size.height/2.0), toCoordinateFrom: mapView)
//Set new center
mapView.setCenter(mapCenter, animated: true)
@kolathee
kolathee / Embed-Map-GeoFire-Medium.swift
Last active December 28, 2016 07:23
Embedding - Setting region
// Struct
public struct MKCoordinateRegion {
public var center: CLLocationCoordinate2D
public var span: MKCoordinateSpan
public init()
public init(center: CLLocationCoordinate2D, span: MKCoordinateSpan)
}
// Setting region
MKCoordinateRegionMake(centerCoordinate: CLLocationCoordinate2D, span: MKCoordinateSpan)
@kolathee
kolathee / Embed-Map-GeoFire-Medium.swift
Created December 28, 2016 07:17
Embedding - To change the zoom level
MKCoordinateRegion theRegion = mapView.region
//Zoom out
theRegion.span.longitudeDelta *= 2.0
theRegion.span.latitudeDelta *= 2.0
mapView.setRegion(theRegion, animated: true)
@kolathee
kolathee / delegate.swift
Last active January 31, 2017 16:50
How to implement a delegate
Example - Implementing delegate in Swift
// 1.Make a protocol
// จะเขียนแยกใส่ไฟล์(.swift)หรือเขียนใน Class ที่จะเรียกใช้ delegate ก็ได้
protocol messageSenderDelegate{
func receivedMessage(message:String)
}
// 2.Declare delegate you want to call
// สร้างตัวแปรสำหรับเก็บ class ที่เป็น delegate มารอไว้