Skip to content

Instantly share code, notes, and snippets.

View kolathee's full-sized avatar
🎯
Focusing

Kolathee kolathee

🎯
Focusing
  • Agoda
  • Bangkok
View GitHub Profile
//
// TimeCounter.swift
// test
//
// Created by Kolathee Payuhawattana on 15/2/2563 BE.
// Copyright © 2563 Cup. All rights reserved.
//
import Foundation
import SwiftDate
@kolathee
kolathee / seque.swift
Last active February 3, 2017 15:17
Prepare for seque
//========= FirstViewVC =========
/*
import UIKit
class FirstViewVC: UIViewController {
@IBOutlet weak var inputMessageTextBox: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
} */
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
@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 มารอไว้
@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 / 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
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 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 / 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 / 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 / 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")