Kermitmarilavonne's Profile

80
Points

Questions
14

Answers
5

  • Asked on August 31, 2020 in iOS.

    You say, "Conforming MyProtocol2 to MyProtocol1 also doesn’t do the trick." Unless you have some trick in mind that you haven’t mentioned, it looks to me like the answer.

    The following works in a playground:

    protocol MyProtocol1 {     func test1() }  protocol MyProtocol2: MyProtocol1 {     func test2() }  class OutputClass: MyProtocol2 {     func test1() {         print("test1")     }     func test2() {         print("test2")     } }  protocol MyProtocol3 {     var output: MyProtocol2 { get } }  class MyClass: MyProtocol3 {      var output: MyProtocol2      init(output: MyProtocol2) {         self.output = output     } }  let o = OutputClass() o.test1() o.test2() let m = MyClass(output: o) 
    • 11 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in Swift.

    I am quite sure the problem is with my code and not with any connections in the storyboard.

    No, the problem is indeed a connection. According to a suggestion in your previous question you renamed Hint to hintButton which does not rename the connection automatically.

    In the storyboard delete the dead Hint connection and reconnect it to hintButton.

    • 12 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in iOS.

    For the re-usability, you may register different cells corresponding the different combination of UI elements. Then based on cell types, different sizes might be returned. For example, fixed size for the UIImageView icons, and different sizes for labels and etc.

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {          let item = dataArray[indexPath.item]      if item.type == .label {          return labelSize     } else if item.type == .icon {          return iconSize         }      return defaultSize } 

    For calculating the label size, I may suggest creating a custom label by extending the UILabel and override its intrinsicContentSize property. For giving a padding regardless of font size, defining insents and calculating the new size seems to be fine. Then you will not need to calculate label during creation of cells, instead it will be defined during label creation.

    override var intrinsicContentSize: CGSize {     let size = super.intrinsicContentSize     return CGSize(width: size.width + leftPadding + rightPadding,         height: size.height + topPadding + bottomPadding) } 
    • 15 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in iOS.

    You don’t appear to be calling searchTableView.reloadData(). It won’t reload the table unless you call that method.

    Generally you’d set a delegate for the MKLocalSearchCompleter and call reloadData in completerDidUpdateResults(_:).

    • 0 views
    • 1 answers
    • 0 votes
  • Asked on August 31, 2020 in .NET.

    Sadly, Code Contracts is no longer supported.

    The good news is that C#8 is going to include a new nullable reference types feature that will handle a large portion of the invariants and pre- and post-conditions for which Code Contracts was used. This will assist with detecting and avoiding possible null-reference exceptions.

    The bad news is that there is no built-in support for other types of contracts, and nothing like it has been announced for the future.

    Correctness guarantees will have to come from third-party tools, or another language will have to be used (e.g., Ada Spark).

    • 17 views
    • 1 answers
    • 0 votes