Firebase

About Using Firebase in Xcode Documentation

Imagem de capa

Code

Open Terminal and Type

Change Directory

cd projectpath

Create Xcode project and set directory of project in terminal

pod init

open Podfile

nano Podfile

platform :ios, '9.0'

target 'Student' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
   
  # Pods for Student
  pod 'Firebase/Core'
  pod 'Firebase/Database'

 

end
ctrl+x
Yes
Enter

Install third party lib’s

pod install

Open projectname.workspace file

Open ViewController.swift

//
//  ViewController.swift
//  StudentDiary
//
//  Created by yashn on 17/09/18.
//  Copyright © 2018 yashn. All rights reserved.
//

import UIKit
import Firebase
import FirebaseDatabase


class ViewController: UIViewController {
    
    var ref: DatabaseReference!
    var databaseHandle : DatabaseHandle!
    

    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        //Saving data in firebase
        ref = Database.database().reference()
        ref.child("name").childByAutoId().setValue("yash")
        ref.child("name").childByAutoId().setValue("yash2")
        
        
        //retriving data from firebase
        databaseHandle = ref.child("name").observe(.childAdded, with: { (data) in let name : String = (data.value as? String)!
            debugPrint(name)
            
            
        })
        
        
        
       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
        
    }
    
    
    


}

Date And time

//dataTime.text! = date
        let now = Date()
        
        let formatter = DateFormatter()
        
        formatter.timeZone = TimeZone.current
        
        formatter.dateFormat = "yyyy-MM-dd HH:mm"
        
        let dateString = formatter.string(from: now)
        print(dateString)
        
        dataTime.text! = dateString

PopUp/Alert

 func myalert(_ mytitle:String, _ mymessage:String)
    {
        let alert = UIAlertController(title: mytitle, message: mymessage, preferredStyle: .actionSheet)
        let ok = UIAlertAction(title: "Done", style: .default, handler: nil)
        alert.addAction(ok)
        self.present(alert,animated: true,completion: nil)
    }
    
    
myalert("Sucesss", "Student Registration sucessfully")    

Project file(GUI ONLY)

Want to see something else added? Open an issue.