ortuman / SwiftForms

A small and lightweight library written in Swift that allows you to easily create forms.
MIT License
1.33k stars 209 forks source link

Swift4 support? #158

Closed appsird closed 7 years ago

appsird commented 7 years ago

Would welcome a Swift4 compatible version. Any chance of this on the horizon?

appsird commented 7 years ago

FYI: For others looking to run under Swift 4.0

__

I went through the SwiftForm Xcode9 migration process from Swift 3.1 to Swift 4.0. This occurs when you launch the project, and Xcode9 detects your legendary code.

Many "fix-it's" appeared, and I clicked them all - many effectively prepends all #selector referenced functions with an @objc

For example, in FormSegmentedControl.swift the function:

internal func valueChanged(_ sender: UISegmentedControl) { }

becomes:

@objc internal func valueChanged(_ sender: UISegmentedControl) {
}

Some hard numeric references were also required to change from

    titleLabel.setContentCompressionResistancePriority(500, for: .horizontal)

to:

titleLabel.setContentCompressionResistancePriority(UILayoutPriority(rawValue: 500), for: .horizontal)


Once I achieved a clean compile I then ran and received the error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SwiftForms.FormSegmentedControlCell 0x105822400> valueForUndefinedKey:]: this class is not key value coding-compliant for the key segmentedControl.'

So, either the blind changes were problematic, or something fundamental changed preventing SwiftForms from functioning in Swift 4.

The WWDC What's New in Foundation video references changes to Key/Value observing.

https://developer.apple.com/videos/play/wwdc2017/212/

Uncertain if this is part of the issue.


Xcode9 now allows you to selectively decide which compiler to use for each each target. I selected the Pods project in Xcode, then clicked on the SwiftForms target, then under Build Settings set "Swift Language Version" to Swift 3.2

I was able to compile my project without key/value error described above. So this appears to be a near-term workaround, though a true Swift4 compatible version would be welcomed.

Thanks again for this nice library.

ortuman commented 7 years ago

A new Swift4 compatible branch has been uploaded. Hope it will be helpful. :)

appsird commented 7 years ago

Thank you very much.

On Mon, Jun 26, 2017 at 3:18 AM, Miguel Ángel Ortuño < notifications@github.com> wrote:

A new Swift4 compatible branch has been uploaded. Hope it will be helpful. :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ortuman/SwiftForms/issues/158#issuecomment-311020064, or mute the thread https://github.com/notifications/unsubscribe-auth/AIFFGfvMoExJXP-sa6OSRChPm6HfUj9Nks5sH4VdgaJpZM4Nzihm .

appsird commented 7 years ago

For others which may want this branch, use the following line in your Podfile

pod 'SwiftForms', :git => 'https://github.com/ortuman/SwiftForms.git', :branch => 'Swift4'

appsird commented 7 years ago

downloaded the iOS 11 beta 2/Xcode 9 beta 2 release. Using the Swift4 branch, everything compiles clean.

Though, when I load the form I receive the following message - again related to key value exception error. This was gone for a bit, though back with a vengeance. Any suggestions appreciated.

2017-07-04 14:42:01.302930-0700 [717:453953] [UIFocus] Focus system disabled 2017-07-04 14:42:01.314447-0700 [717:453953] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SwiftForms.FormSegmentedControlCell 0x1030d4200> valueForUndefinedKey:]: this class is not key value coding-compliant for the key segmentedControl.'