将swift连接到FirebaseDatabase

时间:2017-11-20 10:34:27

标签: ios swift firebase firebase-realtime-database

想要将此代码连接到FirebaseDatabase。 但是在连接到它时我收到错误。

错误: - 无法转换类型' [Datasnapshot]'预期的参数类型' UView'。

FirebaseDatabase

  

下面是它的代码片段。

import UIKit
import FirebaseDatabase
import FirebaseAuth

class HomeViewController: UIViewController, iCarouselDelegate, iCarouselDataSource 
{

@IBOutlet var carouselView: iCarousel!

        var snaps : [DataSnapshot] = []
        override func viewDidLoad() {
            super.viewDidLoad()
            if let currentUserUid = Auth.auth().currentUser?.uid {
                Database.database().reference().child("posts").child("photoUrl").observe(.childAdded, with: { (snapshot) in
                    self.snaps.append(snapshot)
                    self.carouselView.reloadData()
                })
            }

            carouselView.type = .coverFlow
        }

        func numberOfItems(in carousel: iCarousel) -> Int {
            return snaps.count
        }

        func carousel(_ carousel: iCarousel, viewForItemAt index: Int, reusing view: UIView?) -> UIView {
            let tempView = UIView(frame: CGRect(x: 0, y: 0, width: 374, height: 417))
           tempView.addSubview(snaps)
            return tempView
        }

        func carousel(_ carousel: iCarousel, valueFor option: iCarouselOption, withDefault value: CGFloat) -> CGFloat {
            if option == iCarouselOption.spacing {
                return value * 2.1
            }
            return value
        }
        override func didReceiveMemoryWarning() {
            super.didReceiveMemoryWarning()
            // Dispose of any resources that can be recreated.
        }
}

1 个答案:

答案 0 :(得分:0)

错误清楚地表明您正在将快照值添加到UIView中。

tempView.addSubview(snaps)
上面代码片段中的

是DataSnapshot Type的数组。您无法将DataSnapshot数组添加为子视图。