こちらからFirebaseのデータベースを登録していきます.
2の途中でCocoaPodsでinstallする流れとなっていますが、少々使用方法によってinstallが異なるため注意してください.今回は以下の2つをinstallすることにしました.いくつかあります
target 'FirebaseiOS' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
pod 'Firebase/Core'
pod 'Firebase/Database'
# Pods for FirebaseiOS
end
AppDelegate.swiftとはこちらより
import UIKit
//追加
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//追加
FirebaseApp.configure()
return true
}
//以下省略…
import UIKit
//追加
import Firebase
class ViewController: UIViewController {
//firebaseに追加するtext入力
@IBOutlet weak var inputText: UITextField!
// インスタンス変数
var DBRef:DatabaseReference!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//インスタンスを作成
DBRef = Database.database().reference()
}
//sendボタンが押されたら
@IBAction func sendFirebase(_ sender: Any) {
//databaseにあげるデータ
let data = ["name": inputText.text!]
//databaseにあげるデータ更新
DBRef.child("/").updateChildValues(data)
}
//以下省略…