I have a objective-C and Swift mix project. I m using Masonry library for autolayout. I m able to use masonry in Objective C code but not in swift. How to do that ?
Asked
Active
Viewed 404 times
1 Answers
1
Create bridging header file if you haven't yet, and paste following line
#import "Masonry.h"
If you are using CocoaPods to add Masonry to your project, you might see error Masonry.h file not found, this is because you need to set User Header Search Paths, to do so goto TARGETS > Build Settings and paste following
//:configuration = Debug
USER_HEADER_SEARCH_PATHS = pods/**
//:configuration = Release
USER_HEADER_SEARCH_PATHS = pods/**
//:completeSettings = some
USER_HEADER_SEARCH_PATHS
Screenshot to make sure User Header Search Paths is properly set
Note After setting above header, you do not need import Masonry line in your swift file
Usage
UIView.mas_makeConstraints { (make:MASConstraintMaker!) in
make.centerY.mas_equalTo()(anotherView)
make.left.mas_equalTo()(15)
make.height.mas_equalTo()(30)
make.width.mas_equalTo()(30)
}
AamirR
- 11,672
- 4
- 59
- 73
