0

I am using this module to display an image: https://github.com/huynguyencong/ImageScrollView/blob/master/Sources/ImageScrollView.swift

I have added it to my project using CocoaPods and I want to change the value of the var "maxScaleFromMinScale". I just cant figure out how.

First I tried to just override the var which is not possible.

I then tried to override the intializers by just copying and overriding the same ones that are overrided by the creator of the module.

override init(frame: CGRect) {
    super.init(frame: frame)
}

required public init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
}

That does not work, it gives me an error on the top initializer saying that I am not overriding the designated initializer. It feels like I cannot override it since it is not public like the second one. Correct?

Last thing I tried was to make an extension:

extension ImageScrollView {
    public func setMaxScale(scale: CGFloat) {
        maxScaleFromMinScale = scale
    }
}

That does not work either, maxScaleFromMinScale is an unresolved identifier. This also seems to be because it is an internal var and I do not have access to it (another module). Does this mean that my ONLY option is to copy the whole file and modify the source. Was hoping for a minimal and elegant solution.

If this is the case, why can you override the built in UIKit elements but not this one that I downloaded using CocoaPods.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Alex
  • 731
  • 1
  • 11
  • 24

2 Answers2

1

Yes, you cannot override the variable/function because it's internal. That's the point of access modifiers.

Certain UIKit functions are public so you can override them.

Code
  • 6,041
  • 4
  • 35
  • 75
  • So basically, when using modules if something needs changing in their code you have to do the "stupid" thing and just copy the whole thing? – Alex Jun 23 '16 at 09:24
  • @Alex Yes. If it's not `public` then it's not meant to be overridden. – Code Jun 23 '16 at 09:28
-1

Go to the pod file and unlock the file (It prompts to do that on editing), and change

var maxScaleFromMinScale: CGFloat = 3.0

to

public var maxScaleFromMinScale: CGFloat = 3.0
Lazy
  • 670
  • 5
  • 14