Search code examples
swiftcocoapodspodfile

How to make changes to cocoapods file?


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
    }


Solution

  • 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.