Swift 3,无法在viewcontroller中创建多个函数?

时间:2016-11-18 12:39:41

标签: ios swift

我正在尝试使用Firebase登录/注册屏幕。我创建了一个快速类来发送数据到Firebase,我称之为“DataService”类。我还登录并注册了课程。在“DataService”类中,我无法创建多个函数,我收到的错误如 当我尝试创建时,DataService类型的值没有成员“注册” 注册功能。但另一个功能正常。我可以在这个类中只有一个函数(DataService)。

DATASERVICE类

  import Foundation
  import Firebase
  import FirebaseAuth
  import FirebaseStorage

let rootRef = FIRDatabase.database().reference()

class DataService {

static let dataService = DataService()

private var _BASE_REF = rootRef
private var _PHOTO_REF = rootRef.child("photos")

var BASE_REF: FIRDatabaseReference {
    return _BASE_REF
}

var PHOTO_REF: FIRDatabaseReference {
    return _PHOTO_REF
}

var storageRef: FIRStorageReference{
    return FIRStorage.storage().reference()
}

var fileUrl: String!



// Share Photo Data

func shareNewPhoto(user: FIRUser, caption: String, data: NSData) {
let filePath = "\(user.uid)/\     (Int(NSDate.timeIntervalSinceReferenceDate))"
 let metaData = FIRStorageMetadata()
    metaData.contentType = "image/jpg"
    storageRef.child(filePath).put(data as Data, metadata: metaData) { (metadata, error) in
        if let error = error {
            print("Error uploading: /\(error.localizedDescription)")

        }

        // Create a Url for data ( Story Photo)

        self.fileUrl = metadata!.downloadURLs![0].absoluteString
        if let user = FIRAuth.auth()?.currentUser {
            let idPhotoRoom = self.BASE_REF.child("PhotoRooms").childByAutoId()
            idPhotoRoom.setValue(["caption": caption, "StoryPhotoUrlFromStorage": self.storageRef.child(metadata!.path!).description, "fileUrl": self.fileUrl])
        }
    }


    // Story Photo (upload and dowload from server)

func fetchDataFromServer(callback:@escaping (StoryPhoto) -> ()) {
    DataService.dataService._PHOTO_REF.observe(.childAdded, with: { (snapshot) in
        let photo = StoryPhoto(key: snapshot.key, snapshot: snapshot.value as! Dictionary<String, AnyObject>)
            callback(photo)

        })



       // Sign Up

func signUp(username: String, email: String, password: String, data: NSData) {
    FIRAuth.auth()?.createUser(withEmail: email, password: password, completion: { (user, error) in
        if let error = error {
            print(error.localizedDescription)
            return
        }

        let changeRequest = user?.profileChangeRequest()
        changeRequest?.displayName = username
        changeRequest?.commitChanges(completion: { (error) in
            if let error = error{
                print(error.localizedDescription)
                return
            }
        })

        let filePath = "profileimage/\(user!.uid)"
        let metaData = FIRStorageMetadata()
        metaData.contentType = "image/jpeg"

        self.storageRef.child(filePath).put(data as Data, metadata: metaData, completion: { (metadata, error) in
            if let error = error {
                print("\(error.localizedDescription)")
                return
            }
            self .fileUrl = metadata?.downloadURLs![0].absoluteString
            let changeRequestPhoto = user!.profileChangeRequest()
            changeRequestPhoto.photoURL = NSURL(string: self.fileUrl) as URL?
            changeRequestPhoto.commitChanges(completion: { (error) in
                if let error = error {
                    print(error.localizedDescription)
                    return
                }else{
                    print("profile uptaded")
                }
            })

            let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
            appDelegate.Login()

        })


    })
}

}


}

}

注册课程。在这里我收到的错误如 DataService类型的值没有成员“注册”。

// Register Button

@IBAction func RegisterDidTapped(_ sender: AnyObject) {
    guard let email = emailTextField.text, let password = passwordTextField.text, let username = usernameTextField.text else {
        return
    }

    var data = NSData()
    data = UIImageJPEGRepresentation(profileImage.image!, 0.1)! as NSData

    //Signin up


  Here i am getting Error: (Value of type DataService has no member "sign Up")

    DataService.dataService.signUp(username: username, email: email, password: password, data: data)


 }

}

1 个答案:

答案 0 :(得分:1)

检查正确的打开和关闭Range("A2:A11").Copy Sheets("Sheet2").Cells(2, Columns.Count).End(xlToLeft).Offset(, 1) 。看起来你的{}函数在其他函数中。