質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

1049閲覧

swift 変数宣言

globalplus

総合スコア119

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2019/10/17 04:30

firebaseとの接続、stroyboardの設定は完了していますが
Use of undeclared type 'Firebase'

Use of unresolved identifier 'FEventType'
の2つのエラーが出てしまいます。
アドバイス頂けたら嬉しいです。
よろしくお願いします。

ViewController

1import UIKit 2import JSQMessagesViewController 3import Firebase 4 5class ViewController: JSQMessagesViewController { 6 7 var ref: Firebase! //Use of undeclared type 'Firebase' 8 9 var messages: [JSQMessage]? 10 var incomingBubble: JSQMessagesBubbleImage! 11 var outgoingBubble: JSQMessagesBubbleImage! 12 var incomingAvatar: JSQMessagesAvatarImage! 13 var outgoingAvatar: JSQMessagesAvatarImage! 14 15 func setupFirebase() { 16 17 // firebaseのセットアップ 18 ref = Firebase(url: "https://chat.firebaseio.com/") 19 20 // 最新25件のデータをデータベースから取得する 21 // 最新のデータ追加されるたびに最新データを取得する 22 ref.queryLimitedToLast(25).observeEventType(FEventType.ChildAdded, withBlock: { (snapshot) in //Use of unresolved identifier 'FEventType' 23 let text = snapshot.value["text"] as? String 24 let sender = snapshot.value["from"] as? String 25 let name = snapshot.value["name"] as? String 26 print(snapshot.value!) 27 let message = JSQMessage(senderId: sender, displayName: name, text: text) 28 self.messages?.append(message) 29 self.finishReceivingMessage() 30 }) 31 } 32 33 override func viewDidLoad() { 34 super.viewDidLoad() 35 // Do any additional setup after loading the view, typically from a nib. 36 inputToolbar!.contentView!.leftBarButtonItem = nil 37 automaticallyScrollsToMostRecentMessage = true 38 39 40 //自分のsenderId, senderDisokayNameを設定 41 self.senderId = "user1" 42 self.senderDisplayName = "hoge" 43 44 //吹き出しの設定 45 let bubbleFactory = JSQMessagesBubbleImageFactory() 46 self.incomingBubble = bubbleFactory?.incomingMessagesBubbleImage(with: UIColor.jsq_messageBubbleLightGray()) 47 self.outgoingBubble = bubbleFactory?.outgoingMessagesBubbleImage(with: UIColor.jsq_messageBubbleBlue()) 48 49 //アバターの設定 50 self.incomingAvatar = JSQMessagesAvatarImageFactory.avatarImage(with: UIImage(named: "Swift-Logo")!, diameter: 64) 51 self.outgoingAvatar = JSQMessagesAvatarImageFactory.avatarImage(with: UIImage(named: "Swift-Logo")!, diameter: 64) 52 53 //メッセージデータの配列を初期化 54 self.messages = [] 55 setupFirebase() 56 } 57 58 override func didReceiveMemoryWarning() { 59 super.didReceiveMemoryWarning() 60 // Dispose of any resources that can be recreated. 61 } 62 63 //Sendボタンが押された時に呼ばれる 64 func didPressSendButton(button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: NSDate!) { 65 66 //メッセージの送信処理を完了する(画面上にメッセージが表示される) 67 self.finishReceivingMessage(animated: true) 68 69 //firebaseにデータを送信、保存する 70 let post1 = ["from": senderId, "name": senderDisplayName, "text":text] 71 let post1Ref = ref.childByAutoId() 72 post1Ref.setValue(post1) 73 74 } 75 76 //アイテムごとに参照するメッセージデータを返す 77 func collectionView(collectionView: JSQMessagesCollectionView!, messageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageData! { 78 return self.messages?[indexPath.item] 79 } 80 81 //アイテムごとのMessageBubble(背景)を返す 82 func collectionView(collectionView: JSQMessagesCollectionView!, messageBubbleImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageBubbleImageDataSource! { 83 let message = self.messages?[indexPath.item] 84 if message?.senderId == self.senderId { 85 return self.outgoingBubble 86 } 87 return self.incomingBubble 88 } 89 90 //アイテムごとにアバター画像を返す 91 func collectionView(collectionView: JSQMessagesCollectionView!, avatarImageDataForItemAtIndexPath indexPath: NSIndexPath!) -> JSQMessageAvatarImageDataSource! { 92 let message = self.messages?[indexPath.item] 93 if message?.senderId == self.senderId { 94 return self.outgoingAvatar 95 } 96 return self.incomingAvatar 97 } 98 99 //アイテムの総数を返す 100 func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 101 return (self.messages?.count)! 102 } 103 104 105 } 106

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

https://firebase.google.com/docs/ios/setup?hl=ja

ステップ4の最後の手順、

.xcworkspace ファイルを開いて Xcode でプロジェクトを確認します。

というところがハマりやすいです(.xcodeprojの方を開いているとだめです)

投稿2019/10/17 06:19

takabosoft

総合スコア8356

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

globalplus

2019/10/17 06:22

回答ありがとうございます。 それが.xcworkspaceで開いています。 どうしたら良いでしょうか?
takabosoft

2019/10/17 06:24

うーん、podファイルの中身見せてもらえますか?
globalplus

2019/10/17 07:23

# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'chat' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # add the Firebase pod for Google Analytics pod 'Firebase/Analytics' # add pods for any other desired Firebase products # https://firebase.google.com/docs/ios/setup#available-pods pod 'JSQMessagesViewController', :git => 'https://github.com/jessesquires/JSQMessagesViewController', :tag => '7.2.0' # Pods for chat target 'chatTests' do inherit! :search_paths # Pods for testing end target 'chatUITests' do # Pods for testing end end よろしくお願いします。
takabosoft

2019/10/17 07:54 編集

ああ、すみません勘違いしていました。 var ref: Firebase! のFirebaseクラスってどこで定義されているやつでしょうか?(何に使うやつですか?) どこを見てこのコードを書いていますか?
takabosoft

2019/10/17 08:30

たぶん記事が古すぎます。 今はおそらく「Firebase Realtime Database」という名前で提供されていると思いますので、こちらの名前で検索してください。
globalplus

2019/10/17 15:53

firebase自体の設定は公式のが公表している手順をやったのですが。。。 firebase上でのアプリとの連携が完了しました。の通知も確認済です 今回のQiita記事コード古いんでしょうか?
globalplus

2019/10/17 16:50

もしかしたらswift5.1になってしまったからでしょうか? swiftUiとかoutletの繋ぐボタンとか無くなってわからなすぎて初心者にはホント勘弁して欲しいです。笑
takabosoft

2019/10/18 00:17

Qiitaの記事は古すぎます(と書いたつもりですが)。firebaseは様々な機能を提供しており、その一つがrealtime databaseです。名前の通りリアルタイムなデータベース機能になりますので、チャット機能とも相性が良いはずです。Swiftのバージョンも影響がないこともありませんが(特にqiitaの記事はswift2と書いてあり、5とはかなり違いがあります)、おそらくSwiftではなくFirebase側がいろいろバージョンアップして改変されていると思います。 SwiftUIかStoryboardかは新規作成時に選べますのでStoryboardの方を選べばいいです。
globalplus

2019/10/18 01:57

そうなんですね。ご説明ありがとうございます。real time databeseについて学習してみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問