2016-10-20 6 views
0

重複としてマーキングする前に:このトピックのスレッドをたくさん見つけましたが、すべて警告メッセージを_ =で消して解決しました。私は警告を黙らせたくありません。私は結果を使用したい!Swift 3 /警告の使用方法

私はスウィフト3にフォークフレームワークを変換しようとしていると警告で立ち往生しています:コールの

結果は、次のコードでは、未使用の

です:

func setupViews() { 
    contentView.addSubview(imageView) 
    imageView.autoLayoutToSuperview() // here, result of autoLayoutToSuperview() is unused 
    imageView.contentMode = .scaleAspectFill 
    imageView.clipsToBounds = true 
    imageView.backgroundColor = UIColor.white 
} 

autoLayouttoSuperviewは、NSLayoutConstraintの配列を返すそのフレームワークの関数です。

func autoLayoutToSuperview(_ attributes: [NSLayoutAttribute] = [.left, .right, .top, .bottom], inset: CGFloat = 0) -> [NSLayoutConstraint] { 

    var constraints: [NSLayoutConstraint] = [] 
    translatesAutoresizingMaskIntoConstraints = false 

    for attribute in attributes { 

     var constant = inset 
     switch attribute { 
     case .right: 
      constant = -inset 
     case .bottom: 
      constant = -inset 
     default: 
      break 
     } 

     let constraint = NSLayoutConstraint(
      item: self, 
      attribute: attribute, 
      relatedBy: .equal, 
      toItem: self.superview, 
      attribute: attribute, 
      multiplier: 1, 
      constant: constant 
     ) 
     self.superview?.addConstraint(constraint) 
     constraints.append(constraint) 
    } 

    return constraints 
} 

私は警告を沈黙することですが、結果は慣れないので、imageView募集外観には表示されません。

のPIC画像:

enter image description here

はそれを使用します。間違った外観と

enter image description here

imageView

enter image description here

どのように私は結果を使用していますか?ヘルプは非常に感謝しています。

答えて

0

あなたは言うかもしれない:

let constraints = imageView.autoLayoutToSuperview() 
NSLayoutConstraint.activate(constraints) 
関連する問題