You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
}
//以下省略…
準備完了!!!
1度ビルドしてみてください.
使用
1.ViewController.swiftの編集
databaseの更新を行っています.
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)
}
//以下省略…