-1

Im using this library for my project - https://github.com/filletofish/CardsLayout and I tried to change the size of the items in CardsCollectionViewLayout.swift but it does not work.. it still stays the same.

I've also tried to make the changes by forking the library (as desribed by Technerd here: Editing locked files from a CocoaPods framework) but this does not work either.

Is there any other way of being able to make changes to Pods? Or am I simply doing something wrong in these two previous ways

Edit:

   @IBOutlet var collectionView: UICollectionView!
    let cardLayout = CardsCollectionViewLayout()

    override func viewDidLoad() {
        super.viewDidLoad()
        collectionView.collectionViewLayout = CardsCollectionViewLayout()
        collectionView.dataSource = self
        collectionView.delegate = self
        collectionView.isPagingEnabled = true
        collectionView.showsHorizontalScrollIndicator = false
        collectionView.isHidden = true
        // cardLayout.itemSize = CGSize(width: 50, height: 50)
        collectionView.collectionViewLayout = cardLayout
        searchInput.delegate = self
    }

AF6890
  • 43
  • 5

1 Answers1

0

You should show the code you wrote to setup your layout. This would make it easier to help you.

Put the code related to collectionView in the didSet block of your collectionView property.
The following code snippet should work for you:

@IBOutlet weak var collectionView: UICollectionView! {  
   didSet {  
      let cardLayout = CardsCollectionViewLayout()  
      cardLayout.itemSize = CGSize(width: 50, height: 50)  
      collectionView.collectionViewLayout = cardLayout  
      collectionView.dataSource = self  
      collectionView.delegate = self  
      collectionView.isPagingEnabled = true  
      collectionView.showsHorizontalScrollIndicator = false  
      collectionView.isHidden = true  
   }  
}  

Do never change a file in a pod! Your changes would be lost when updating the pod!
If you ever need to change the behavior of a pod, you have options:

  • write an extension, if that suits your needs
  • use subclassing
  • if you need to make bigger changes, use a fork as you already tried
  • or you may add the pods source files to your projects code base. But I wouldn't recommend this, because that would make it difficult to profit from updates published to the pods source.
Robin Schmidt
  • 1,153
  • 8
  • 15
  • Thanks for you answer! I now understand why and how to do it.. however in the project I get a "found nil while unwrapping optional value"-error on this line of code that is within my viewDidLoad(). `cardCollection.itemSize = CGSize(width: 50, height: 50)` I can edit my post with the specific part of my code you're asking for. – AF6890 Feb 09 '20 at 14:26
  • @AF6890 How do you initialize your collectionView and cardLayout? Do you use storyboard/xib file? If your collectionView / layout is an optional, safely unwrap it before customizing the itemSize property. – Robin Schmidt Feb 09 '20 at 15:31
  • @AF6890 Is `cardCollection` your collectionView or your CardsLayout instance? Can you show how you initialize this? – Robin Schmidt Feb 09 '20 at 15:36
  • @AF6890 I edited my answer. Put your collectionView setup code in the didSet block of your colletionView property like I did. This prevents your error "nil while unwrapping optional". Your `let cardLayout = CardsCollectionViewLayout()` isn't needed, except you relate to this layout anywhere else in your code. If this is the case, remove my first line in didSet block – Robin Schmidt Feb 09 '20 at 17:05
  • Thank you, it is working now! just had to put `collectionView.collectionViewLayout = cardLayout` before `cardLayout.size` :) – AF6890 Feb 09 '20 at 17:09