nghialv / MaterialKit

Material design components for iOS written in Swift
MIT License
2.51k stars 290 forks source link

Update to Swift 3~5 (Xcode 8~11.2.1) + Resolve memory leaks + SPM support #66

Open ApolloZhu opened 7 years ago

ApolloZhu commented 7 years ago

Since the repo is no longer maintained, use this in your Podfile instead:

pod 'MaterialKit', :git => 'https://github.com/ApolloZhu/MaterialKit.git'

or in your Package.swift:

.package(url: "https://github.com/ApolloZhu/MaterialKit.git",
         .upToNextMinor(from: "0.6.6")),

This version is compatible, theoretically, with any version from Swift 3 to 5 (solve #63 and #72)

This implementation also removed the strong reference cycles (which are causing memory leaks). I'm aware of this [issue](https://github.com/LiulietLee/Pick-Color/issues/2) a long time ago, but had no idea why just declaring superLayer as `weak` causes unexpected crashes. Thanks to @theMeatloaf for his solutions in Swift 2, we only need to manually remove the observers by calling `recycle` method of MKLayer and MKRefreshControl if a class owns such properties directly. I can't figure out a way for us to automatically remove the observers, especially when the time `deinit` of MKLayer gets called, superLayer is already nil. Therefore, if you have a better solution, please definitely help. And yes, in addition to MKLayer and all other classes that has a property of type MKLayer, MKRefreshControl has [strong reference loop](https://github.com/nghialv/MaterialKit/blob/master/Source/MKRefreshControl.swift#L14) and [observer](https://github.com/nghialv/MaterialKit/blob/master/Source/MKRefreshControl.swift#L55) not removed, and MKSwitch has a [strong reference loop](https://github.com/nghialv/MaterialKit/blob/master/Source/MKSwitch.swift#L179), too.