Skip to content

With swift, will crash on iOS 8.1, iOS 8.2 for bad access while work well on iOS 8.4 #21

Open
@MichaelPei

Description

@MichaelPei

Just use like below:

var stackView = UIStackView()

Activity

changed the title [-]Will crash on iOS 8.1, iOS 8.2 while work well on iOS 8.4[/-] [+]With swift, will crash on iOS 8.1, iOS 8.2 while work well on iOS 8.4[/+] on Nov 18, 2015
changed the title [-]With swift, will crash on iOS 8.1, iOS 8.2 while work well on iOS 8.4[/-] [+]With swift, will crash on iOS 8.1, iOS 8.2 for bad access while work well on iOS 8.4[/+] on Nov 18, 2015
MichaelPei

MichaelPei commented on Nov 19, 2015

@MichaelPei
Author

I managed to workaround this issue by create the UIStackView in Objective-C code and get it in swift code as function return value.

mokai

mokai commented on Jan 7, 2016

@mokai

@MichaelPei I try this,But always return nil by create the UIStackView in Objective-C code

MichaelPei

MichaelPei commented on Jan 13, 2016

@MichaelPei
Author

@mokai Following code works for me

+ (UIStackView *)stackView {
    return [[UIStackView alloc] init];
}

You may have a try. It seems that UIStack implementation is replaced by FDStackView using assembly code, which should works fine in Objective-C runtime.

MichaelPei

MichaelPei commented on Jan 19, 2016

@MichaelPei
Author

@mokai if use it as pod, make sure to use it as static library otherwise you could get nil.
I just updated pod to dynamic library and found nil will returned in old method. I have to copy FDStackView files to project to make it work. Ugly, but works.

mokai

mokai commented on Jan 20, 2016

@mokai

@MichaelPei Yea,I use it as pod。。。。

nobre84

nobre84 commented on Mar 21, 2016

@nobre84

At first we disabled availability checks to reference UIStackView in swift code, but it crashes all if #available(iOS 9.0, *) blocks
Then we took this approach when referencing stack view from IB in swift code (extend the protocol as needed to interact with the Stack View). I believe this could be built in the library with the full supported API.

@objc protocol StackableView {
    var arrangedSubviews:[UIView] { get }
    func removeArrangedSubview(view:UIView)
    func layoutIfNeeded()
}
​
@available(iOS 9.0, *)
extension UIStackView: StackableView {

}
​
extension FDStackView: StackableView {

}
​
@IBOutlet var stackViewAnswers: StackableView!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nobre84@MichaelPei@mokai

        Issue actions

          With swift, will crash on iOS 8.1, iOS 8.2 for bad access while work well on iOS 8.4 · Issue #21 · forkingdog/FDStackView