Skip to content

v1.1.0 crash with UIView margins #461

@CristianoCastro

Description

@CristianoCastro

New Issue Checklist

🚫 If this template is not filled out your issue will be closed with no comment. 🚫

  • I have looked at the Documentation
    I have filled out this issue template.

Issue Info

Info Value
Platform ios
Platform Version 9.X & 10.X
Masonry Version 1.1.0
Integration Method cocoapods

Issue Description

Crash: -[UIView mas_bottomMargin]: unrecognized selector sent to instance 0x7fe34460a6a0
Possibly other margin methods too.

Worked with Masonry v1.0.2

Edit:
[UIView mas_bottomMargin] was working with Masonry 1.0.2 in XCodes 8.3.3 (8E3004b) and 9.0 (9A235), tested in devices and simulators iOS 9.X and 10.X.
Using Masonry v1.1.0 crashes with unrecognized selector, in any of the XCodes and simulators mentioned above, even after Project -> clean + clean build folder + manually deleting derived data.

I'm using MAS_SHORTHAND_GLOBALS

A quick difference I see is in View+MASAdditions.h, when defining mas_xxxMargin, its within conditional block:

  • Masonry v1.0.2: #if TARGET_OS_IPHONE || TARGET_OS_TV
  • Masonry v1.1.0: #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000)

My application's __IPHONE_OS_VERSION_MIN_REQUIRED is 90000

Edit 2:
I downloaded the repo and ran the Example project's Margins example and it did not crash.
I then decided to create a simple test project to try and reproduce the crash and I was able to.
My test project consisted of a Podfile with only Masonry 1.1.0 pod:

platform :ios, '9.0'

target 'test' do
  pod 'Masonry', '1.1.0'
end

My project's deployment target was 9.0 (and afterwards tested with 10.3), a single view controller with this code:

#import <Masonry/Masonry.h>

...

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    UIView *tmp = [[UIView alloc] init];
    tmp.backgroundColor = [UIColor blueColor];
    [self.view addSubview:tmp];
    [tmp mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view);
        make.height.equalTo(@20);
        make.bottom.equalTo(tmp.superview.mas_bottomMargin);
    }];
}

Crash:

2017-09-21 12:52:31.898 test[47946:212235] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView mas_bottomMargin]: unrecognized selector sent to instance 0x7ffcdda05420'
*** First throw call stack:
(
	0   CoreFoundation                      0x000000010b0c4b0b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000010ab29141 objc_exception_throw + 48
	2   CoreFoundation                      0x000000010b134134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
	3   CoreFoundation                      0x000000010b04b840 ___forwarding___ + 1024
	4   CoreFoundation                      0x000000010b04b3b8 _CF_forwarding_prep_0 + 120
	5   test                                0x0000000108ca5940 __29-[ViewController viewDidLoad]_block_invoke + 608
	6   test                                0x0000000108cb7ada -[UIView(MASAdditions) mas_makeConstraints:] + 138
...

Edit 3:
Sample project: test.zip

Edit 4:
As @robertjpayne said, use_frameworks! could be used as workaround if you are able to (which isn't my case).

I've researched a bit more and found that, even though my Podfile states I target iOS 9, each individual pod has its own deployment target. I checked the Masonry pod and found it is targeting iOS 6, leading to the crash. My workaround was setting each pod minimum deployment target equal to my project's with a post install hook as such:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
    end
  end
end

Reference: https://stackoverflow.com/a/37289688/1077288

Activity

beloso

beloso commented on Sep 20, 2017

@beloso

It happens with me too

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

This doesn't make much sense as the code here has hardly changed at all… Does it work with Xcode 9 and Masonry 1.0.2?

ghost

ghost commented on Sep 21, 2017

@ghost

Xcode 9.0 + Masonry 1.1.0 crashes, Clean -> Build, then goes OK, confused.

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

@guofengld so it doesn't crash once you do a full clean + build? Sounds like a weird Xcode issue

jonz-tech

jonz-tech commented on Sep 21, 2017

@jonz-tech

xcode 8.3.3 build the lasted version will cash when use XXXMargin . so i don't think so it's a weird xcode issuse.

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

@jonz-tech have you tried a full clean? Including deleting your DerrivedData folder? It seems super suspicious because nothing about these API's changed.

ghost

ghost commented on Sep 21, 2017

@ghost

@robertjpayne "ios deployment_target" was set to "6.0", so __IPHONE_OS_VERSION_MIN_REQUIRED equals to 60000, mas_leftMargin、mas_rightMargin were not implemented, but they were declared 😂

jonz-tech

jonz-tech commented on Sep 21, 2017

@jonz-tech

i had try. here is my issue.

#460

i had checked your project .it seems nothing change, and still cause some problem.
does the implement was missing in podspec?

CristianoCastro

CristianoCastro commented on Sep 21, 2017

@CristianoCastro
Author

Updated issue to add some info about Xcode, devices tested and configurations

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

@CristianoCastro super helpful thank you, I have no idea why it's letting the header go through but not the API, gah!

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

@CristianoCastro just one last question -- does it crash on device? Or just simulators?

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

Hrm I'm not really sure what to say here, if I clone this project and run the Masonry iOS Examples and tap into the Margins example it doesn't crash.

This is with shorthand mode on.

Whats your min deployment target set to?

beloso

beloso commented on Sep 21, 2017

@beloso

It crashes on simulators as well. We are testing our UI on the iPhone X simulator and it crashes there.

robertjpayne

robertjpayne commented on Sep 21, 2017

@robertjpayne
Member

@beloso can you try just downloading the .tar.gz of the v1.1.0 release and running the examples and tapping into the margins example?

I can't replicate the crash on my end…

CristianoCastro

CristianoCastro commented on Sep 21, 2017

@CristianoCastro
Author

@robertjpayne updated issue to include results of running the example Margins and a test project

17 remaining items

CristianoCastro

CristianoCastro commented on Sep 28, 2017

@CristianoCastro
Author

@robertjpayne the test project is working now when using the master branch, tested in XCode 9 on iOS 10 & 11. Though I have warnings about some enumerations in masonry being partial (I don't recall if they are new or not)

screen shot 2017-09-28 at 14 33 38

hhyymm

hhyymm commented on Oct 23, 2017

@hhyymm

cocoapods
Masonry Version | 1.1.0
iOS Simulator 8.4 && 11.0
Xcode 8.3.3 + Xcode9.0

Podfile use setting blow

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'
end
end
end

It works well

robertjpayne

robertjpayne commented on Oct 24, 2017

@robertjpayne
Member

@CristianoCastro did you ever find a way around the warnings?

CristianoCastro

CristianoCastro commented on Oct 25, 2017

@CristianoCastro
Author

@robertjpayne I didn't research the subject further due to a deadline and the cocoapods workaround of setting each target's IPHONEOS_DEPLOYMENT_TARGET doing the trick

xingheng

xingheng commented on Oct 31, 2017

@xingheng

I don't think this is an issue related cocoapods, the cocoapods uses the main app project's deployment target when running pod install at the first time only, AFAIK. However, this library's deployment target is iOS 6.0 in the podspec file, then the precompiler should support all the above iOS systems. The margins (leftMargins and bottomMargin) is supported on iOS 8 only, those symbols shouldn't be occurred in the main project code which has an iOS 6/7 deployment target. It should be a kind of compiling error there.

The new introduced macros in 1.1.0 get the hint.

#if TARGET_OS_IPHONE || TARGET_OS_TV

@robertjpayne

Rogerlin2013

Rogerlin2013 commented on Apr 17, 2018

@Rogerlin2013

@xingheng Can't agree you more

godera

godera commented on Apr 24, 2018

@godera

@robertjpayne when adding files to project, i take no error. But podding it cause 'unrecognized selector sent to instance xxx'.

Lucashuang0802

Lucashuang0802 commented on Jun 28, 2018

@Lucashuang0802

@xingheng so do we have a solution here?

Suncoldx333

Suncoldx333 commented on Sep 6, 2018

@Suncoldx333

wx20180906-153509 2x

by command "pod install --verbose", I find cocoapods install masonry with 6.0 which decided in Masonry.podspec

wx20180906-154302 2x

so click Pods->Masonry, search "deployment target" in "Build Settings", check if it is 6.0, and choose version you want

wx20180906-155300 2x

ghost

ghost commented on Dec 27, 2018

@ghost

This one fixes the Crash, Thanks! @Suncoldx333

The iOS Deployment Target is changed to "iOS 6.0", Change back to 8.0 or higher works for me

xingheng

xingheng commented on Dec 27, 2018

@xingheng

@Suncoldx333 I don't think that's a good fix, the Pods/Pods.xcodeproj is under the Pods directory which is added to .gitignore in SCM in general, because cocoapods manages the project file via automation completely.

Suncoldx333

Suncoldx333 commented on Dec 27, 2018

@Suncoldx333

@Suncoldx333 I don't think that's a good fix, the Pods/Pods.xcodeproj is under the Pods directory which is added to .gitignore in SCM in general, because cocoapods manages the project file via automation completely.

yes you are right. what I did will be nothing after pod install. and I think this issue has been solved when @CristianoCastro share the Edit 4, just add those code into podfile.

ghost

ghost commented on Dec 27, 2018

@ghost

I notice there is a Waring for my project after pods install, Xcode 10 will automatically change
iOS deployment target to the right one.
image

image

RbBtSn0w

RbBtSn0w commented on Sep 13, 2019

@RbBtSn0w

So, how about now?

desperadocarl

desperadocarl commented on Aug 4, 2021

@desperadocarl

So, how about now? confused!

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

        @robertjpayne@teerapap@beloso@RbBtSn0w@xingheng

        Issue actions

          v1.1.0 crash with UIView margins · Issue #461 · SnapKit/Masonry