2016-10-24 6 views
-4

こんにちは私はプロジェクトを行っていますが、オープンすると簡単な3つのエラーが表示されます。怒鳴るスウィフト2からスウィフト2.3ガードレットとエラーの場合

let location, let response, let error) in 

     guard let _:NSURL = location, let _:NSURLResponse = response where error == nil else { 
      print("error") 
      return 
     } 

とエラー

の下で私のコードパラメータ属性が許可されていないとして「聞かせて」、予想される「」マルチ句条件の一部に参加し、

for constraint in self.contentView.constraints { 
     if let item = constraint.firstItem as? UIView where item == containerView { 
     let newConstraint = NSLayoutConstraint(item: anAnimationView, attribute: constraint.firstAttribute, 
      relatedBy: constraint.relation, toItem: constraint.secondItem, attribute: constraint.secondAttribute, 
      multiplier: constraint.multiplier, constant: constraint.constant) 

     newConstraints.append(newConstraint) 
     } else if let item: UIView = constraint.secondItem as? UIView where item == containerView { 
     let newConstraint = NSLayoutConstraint(item: constraint.firstItem, attribute: constraint.firstAttribute, 
      relatedBy: constraint.relation, toItem: anAnimationView, attribute: constraint.secondAttribute, 
      multiplier: constraint.multiplier, constant: constraint.constant) 

     newConstraints.append(newConstraint) 
     } 
    } 

とエラー

マルチ句条件の接合部()

func removeAllSubViews(){ 
     for (var i = 0 ; i < subviews.count ; i++){ 
      subviews[i].removeFromSuperview() 
     } 
    } 

    func loadViewFromNib(nibName:String) -> UIView { 

     let bundle = NSBundle(forClass: self.dynamicType) 
     let nib = UINib(nibName: nibName, bundle: bundle) 
     let v = nib.instantiateWithOwner(self, options: nil)[0] as! UIView 

     return v 
    } 

} 

エラー

'は、' 期待 '.dynamicType'推奨されません。代わりに 'タイプ(of:...)'を使用してください

私はすべてを試してみましたが、それを解決しませんでした。 ty

+1

、 '。 'self.dynamicType'の代わりに' type(of:) 'を使います。 –

答えて

3

1)

(location, response, error) in 
    guard error == nil else { 
     print(error!) 
     return 
    } 
// In this scope `location` and `response` are optional but guaranteed not `nil` 

または

(location, response, error) in 
    guard let loc = location, let resp = response, error == nil else { 
     print(error!) 
     return 
    } 

2)

if let item = constraint.firstItem as? UIView, item == containerView { 

3)

let bundle = NSBundle(forClass: type(of:self)) 
0123の type(of:)を使用するようにコードを更新代わり `WHERE`使用`の

removeAllSubViewsのスウィフト方法である(NO醜いCスタイルのループ)

func removeAllSubViews() { subViews.forEach{ $0.removeFromSuperview() } 
1

スウィフト3では、かなりの変更がありました。パラメータ属性が許可されていないとして、マルチ句条件の一部に参加する「」期待「しましょう」

あなたがguardまたはif let文で行うすべての割付操作接頭辞は適切なletまたはvarであり、コンマで区切る必要があります。

where句はもうguard文で使用することができない()マルチ句条件の部品を接合する '' 期待

    1. whereを削除して、それを ,セパレータに置き換えることができます。

      1. '.dynamicType'は非推奨です。 '(の:...)タイプ' を使用してください代わりに

      メソッドシグネチャ.dynamicTypetype(of:)に変更されました。だからではなく、dynamicType

  • 関連する問題