chiahsien/CHTCollectionViewWaterfallLayout

Swift 3

SebastianKumor opened this issue · 18 comments

How did you resolve this ins swift 3 ?

let yOffset = ((self.columnHeights[section] as AnyObject).object(columnIndex) as AnyObject).doubleValue

gives me error 'Cannot call value of non-function type 'Any?!''

(self.columnHeights[section] as AnyObject).enumerateObjects({(object : AnyObject!, idx : NSInteger,pointer :UnsafeMutablePointer) and this one gives error ' Cannot invoke 'enumerateObjects' with an argument list of type '((AnyObject!, NSInteger, UnsafeMutablePointer) -> ())';

I used Xcode 8 converter and this is the result, thx for help

Same here .. any updates ?

I did manage to resolve the errors but the func longestColumnIndexInSection () is crashing m app

func shortestColumnIndexInSection (_ section: NSInteger) -> NSInteger {
        var index = 0
        var shorestHeight = MAXFLOAT
        (self.columnHeights[section] as AnyObject).enumerateObjects { (obj: Any, idx: NSInteger, pointer: UnsafeMutablePointer<ObjCBool>) in
            let height = obj as! Float
            if (height<shorestHeight){
                shorestHeight = height
                index = idx
            }
        }
        return index
    }

@SebastianKumor here's how I did it

@MindaugasJucius thx buddy, it seems like it working, tho I still have crash elsewhere , in a

func prepare() section 3 my yOffset is nil, how are you getting it ? this is what I have let yOffset = ((self.columnHeights[section] as? NSMutableArray)?.object (at: columnIndex) as AnyObject).doubleValue

The Swift version is contributed by community, I personally don't adopt to Swift yet. So, welcome to send me a PR.

Ok guys thx, I managed to make it work

Hello Sebastian , can you please share your CHT file that works ? Thank you in advance.

@gsmeros @chiahsien I updated the swift file in fork I created, it works for me https://github.com/SebastianKumor/CHTCollectionViewWaterfallLayout
please see if it works as expected, I did not manage to crash it

rlam3 commented

@SebastianKumor If it works for you. Please create a new cocoapods for the for the swift version since OP wont support swift. Or create a pull request for OP to create a new branch for? Thanks!

I've merged this PR #149
Can anyone help to test if everything works as expected?

@rlam3 done, can you please also test it if it works as expected ? thanks

@SebastianKumor, it works :) . Thanks

I have an Issue when building this in Xcode 8.1, the layout does not take effect. It just lays everything out in one column.

@OviBortas same here, for me it crashes on func longestColumnIndexInSection()
the issue is cause I believe due to the new handling of optionals implicitly cast as Any in xcode 8.1

jvk75 commented

Hi,
I created a pull #152 which makes the swift class more swifty and fixes issues with Xcode8.1

@jvk75 tested, and it works. @OviBortas try new update @jvk75 made

Hi all, I've merged #152 to develop, also I've merged #151 and #153.
Could anyone help to test if the develop branch works as expected?

Hi @chiahsien , I tested this on xcode 8.1 and swift 3.0.1 and it works well.