gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 16:03:18 25 4
gpt4 key购买 nike

我正在尝试使用 Firebase 制作登录/注册屏幕。我创建了一个用于将数据发送到 Firebase 的快速类,并将该类称为“DataService”。我也有登录和注册类(class)。在“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()

})


})
}

}


}

}

注册类(class)。在这里我收到类似 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)


}

}

最佳答案

检查正确打开和关闭 {}。看起来您的 signUp 函数在其他函数中。

关于ios - Swift 3,无法在 viewcontroller 中创建多个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40677381/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com