2017-10-19 3 views
0

내 코드에 문제가 있다고 의심 되나, 내가 잘못하고있는 부분을 정확히 지적 할 수 없습니다. 이 줄의 오류는 내 signUp 함수에있는 self.setUserInfo(firstLastName: firstLastName, user: user, username: username, location: location, biography: biography, password: password, pictureData: pictureData)입니다.'User'유형의 값을 변환 할 수 없습니다. 예상 인수 유형 'User!'

'사용자'유형의 값을 변환 할 수 없습니다. 예상 인수 유형 'User!' 사용 "!"에 의해 사용자 매개 변수의 미개봉 값을 설정 한 setUserInfo 방법에 enter image description here

func signUP(firstLastName: String, username: String, email: String, location: String, biography: String, password: String, pictureData: NSData!) { 

    Auth.auth().createUser(withEmail: email, password: password) { (user, error) in 
     if error == nil{ 

      self.setUserInfo(firstLastName: firstLastName, user: user, username: username, location: location, biography: biography, password: password, pictureData: pictureData) 

     }else{ 
      print(error?.localizedDescription) 
     } 
    } 


} 

private func setUserInfo(firstLastName: String, user: User!, username: String, location: String, biography: String, password: String, pictureData: NSData!){ 

    let imagePath = "profileImage\(user.uid)/userPic.jpg" 
    let imageRef = storageRef.child(imagePath) 

let metaData = StorageMetadata() 
    metaData.contentType = "image/jpeg" 
    imageRef.putData(pictureData as Data, metadata: metaData){(newMetaData, error) 
     in 
     if error == nil{ 
      let changeRequest = User.createProfileChangeRequest() 
      changeRequest.displayName = username 
      if let photoURL = newMetaData!.downloadURL(){ 
       changeRequest.photoURL = photoURL 

      } 
      changeRequest.commitChanges(completion: { (error) in 
       if error == nil{ 

        self.saveUserInfo(firstLastName: firstLastName, user: user, username: username, location: location, biography: biography, password: password) 

        print("user info set") 

       }else{ 
        print(error?.localizedDescription) 
       } 
      }) 

     }else{ 
      print(error?.localizedDescription) 
     } 

    } 

} 
+0

보기 구현 : '방법 – D4ttatraya

+0

당신의 사용자 클래스보기를 수행 이것이이 가져온 사용자 매개 변수 – Torewin

답변

-1

하지만 인증한다. 완성 블록은 그 값이 선택적인 것으로 보인다.

Auth.auth().createUser(withEmail: email, password: password) { [weak self] (user, error) in 

    guard let unwrappedError = error, 
      let unwrappedUser = user, 
      let strongSelf = self 
    else { 
     print(error?.localizedDescription) 
     return 
    } 

    strongSelf.setUserInfo(firstLastName: firstLastName, user: unwrappedUser, username: username, location: location, biography: biography, password: password, pictureData: pictureData) 
} 

편집 : 여기

당신이 그것을 해결할 수있는 방법이다 나는 strongSelf 패턴을 추가 가드 문을 사용, 당신은 여기에서 명시 적으로 자신을 유지하고 있기 때문에, (무없는 네트워크 콜백 폐쇄에!) 보호 진술은이 시나리오에서 유효성 검사를 처리하는 데 선호되는 방법입니다. 이는 사용자의 의도가 무엇인지 명확하게하기 때문입니다. . Auth.auth()는 createUser (withEmail`의

+0

처럼 "!"? (이미지 제공) – user8000557

+0

제거 setUserInfo에서 제공 – Woof

+0

를 선언 한 후 나에게 같은 오류 – user8000557

관련 문제