Skip to content

Commit

Permalink
compatible with Swift 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdycat committed Oct 11, 2018
1 parent 52a8dd4 commit 5f9a85b
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 89 deletions.
10 changes: 7 additions & 3 deletions Cupcake-Demo/Cupcake-Demo.xcodeproj/project.pbxproj
Expand Up @@ -175,7 +175,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0910;
LastUpgradeCheck = 1000;
ORGANIZATIONNAME = nerdycat;
TargetAttributes = {
841B2C6D1E7BC5900084B37C = {
Expand Down Expand Up @@ -285,13 +285,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -340,13 +342,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -385,7 +389,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nerdycat.Cupcake-Demo";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
Expand All @@ -400,7 +404,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "nerdycat.Cupcake-Demo";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = 1;
};
name = Release;
Expand Down
Binary file not shown.
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0910"
LastUpgradeVersion = "1000"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,7 +26,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
Expand All @@ -46,7 +45,6 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
2 changes: 1 addition & 1 deletion Cupcake-Demo/Cupcake-Demo/AppDelegate.swift
Expand Up @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

let sel = NSSelectorFromString("setContentInsetAdjustmentBehavior:")
if UIScrollView().responds(to: sel) {
Expand Down
6 changes: 3 additions & 3 deletions Cupcake-Demo/Cupcake-Demo/AppStoreViewController.swift
Expand Up @@ -53,7 +53,7 @@ class AppStoreCell: UITableViewCell {
HStack(indexLabel, iconView, 10, midStack, "<-->", 10, actionStack).embedIn(self.contentView, 10, 0, 10, 15)
}

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupUI()
}
Expand All @@ -69,7 +69,7 @@ class AppStoreViewController: UITableViewController {
var appList: Array<Dictionary<String, Any>>!

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
return UITableView.automaticDimension
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
Expand All @@ -92,7 +92,7 @@ class AppStoreViewController: UITableViewController {

self.tableView.estimatedRowHeight = 84
self.tableView.register(AppStoreCell.self, forCellReuseIdentifier: "cell")
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 34, 0)
self.tableView.contentInset = UIEdgeInsets.init(top: 0, left: 0, bottom: 34, right: 0)

let path = Bundle.main.path(forResource: "appList", ofType: "plist")
appList = NSArray(contentsOfFile: path!) as? Array<Dictionary<String, Any>>
Expand Down
2 changes: 1 addition & 1 deletion Cupcake-Demo/Cupcake-Demo/ExamplesViewController.swift
Expand Up @@ -114,7 +114,7 @@ class DashboardViewController: BaseViewController {
class DashButton: UIButton {
let subtitle: String!

override func setTitle(_ title: String?, for state: UIControlState) {
override func setTitle(_ title: String?, for state: UIControl.State) {
if state == .normal {
let att = AttStr(
AttStr(title).font("18").color("#181D42"), "\n",
Expand Down
2 changes: 1 addition & 1 deletion Cupcake.podspec
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "Cupcake"
s.version = "1.2.2"
s.version = "1.2.3"
s.summary = "An easy way to create and layout UI components for iOS."

s.description = <<-DESC
Expand Down
52 changes: 43 additions & 9 deletions Cupcake/AttStr.swift
Expand Up @@ -104,21 +104,36 @@ public extension NSMutableAttributedString {
.underline(.styleDouble, "red") //double underline with red color
...
*/
@discardableResult public func underline(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
#if swift(>=4.2)
@discardableResult public func underline(_ style: NSUnderlineStyle = .single, _ color: Any? = nil) -> Self {
var styles = NSNumber(value: style.rawValue)
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
if style != .none && style != .single && style != .thick && style != .double {
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.single.rawValue)
}

cpk_addAttribute(name: "NSUnderline", value: styles)
if let underlineColor = Color(color) {
cpk_addAttribute(name: "NSUnderlineColor", value: underlineColor)
}
if let underlineColor = Color(color) { cpk_addAttribute(name: "NSUnderlineColor", value: underlineColor) }
return self
}
#else
@discardableResult public func underline(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
var styles = NSNumber(value: style.rawValue)
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
}

cpk_addAttribute(name: "NSUnderline", value: styles)
if let underlineColor = Color(color) { cpk_addAttribute(name: "NSUnderlineColor", value: underlineColor) }
return self
}
#endif

@discardableResult public func underline(_ color: Any) -> Self {
#if swift(>=4.2)
return underline(.single, color)
#else
return underline(.styleSingle, color)
#endif
}

/**
Expand All @@ -132,10 +147,11 @@ public extension NSMutableAttributedString {
.strikethrough(.styleDouble, "red") //double strikethrough with red color
...
*/
@discardableResult public func strikethrough(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
#if swift(>=4.2)
@discardableResult public func strikethrough(_ style: NSUnderlineStyle = .single, _ color: Any? = nil) -> Self {
var styles = NSNumber(value: style.rawValue)
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
if style != .none && style != .single && style != .thick && style != .double {
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.single.rawValue)
}

cpk_addAttribute(name: "NSStrikethrough", value: styles)
Expand All @@ -144,9 +160,27 @@ public extension NSMutableAttributedString {
}
return self
}
#else
@discardableResult public func strikethrough(_ style: NSUnderlineStyle = .styleSingle, _ color: Any? = nil) -> Self {
var styles = NSNumber(value: style.rawValue)
if style != .styleNone && style != .styleSingle && style != .styleThick && style != .styleDouble {
styles = NSNumber(value: style.rawValue | NSUnderlineStyle.styleSingle.rawValue)
}

cpk_addAttribute(name: "NSStrikethrough", value: styles)
if let strikethroughColor = Color(color) {
cpk_addAttribute(name: "NSStrikethroughColor", value: strikethroughColor)
}
return self
}
#endif

@discardableResult public func strikethrough(_ color: Any) -> Self {
#if swift(>=4.2)
return strikethrough(.single, color)
#else
return strikethrough(.styleSingle, color)
#endif
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Cupcake/Button.swift
Expand Up @@ -185,10 +185,10 @@ public extension UIButton {
self.cpkGap = spacing
let halfGap = spacing / 2

self.titleEdgeInsets = UIEdgeInsetsMake(0, halfGap, 0, -halfGap)
self.imageEdgeInsets = UIEdgeInsetsMake(0, -halfGap, 0, halfGap)
self.titleEdgeInsets = UIEdgeInsetsMake_(0, halfGap, 0, -halfGap)
self.imageEdgeInsets = UIEdgeInsetsMake_(0, -halfGap, 0, halfGap)

var insets = self.cpkInsets ?? UIEdgeInsetsMake(0, 0, 0, 0)
var insets = self.cpkInsets ?? UIEdgeInsetsMake_(0, 0, 0, 0)
insets.left += halfGap
insets.right += halfGap
self.contentEdgeInsets = insets
Expand Down
39 changes: 23 additions & 16 deletions Cupcake/CPKStackView.swift
Expand Up @@ -33,7 +33,7 @@ public class CPKStackView: UIView {

private var _alignment: CPKStackAlignment = .left
private var _spacing: CGFloat = 0
private var _axis: UILayoutConstraintAxis = .horizontal
private var _axis: UILayoutConstraintAxis_ = .horizontal
private var _headAttachSpace: CGFloat?

public private(set) var arrangedSubviews = [UIView]()
Expand All @@ -49,7 +49,7 @@ public class CPKStackView: UIView {
set { if _spacing != newValue { _spacing = newValue; spacingDidChange() } }
}

public var axis: UILayoutConstraintAxis {
public var axis: UILayoutConstraintAxis_ {
get { return _axis }
set { if _axis != newValue { _axis = newValue; axisDidChange() } }
}
Expand Down Expand Up @@ -82,9 +82,16 @@ public class CPKStackView: UIView {
view.translatesAutoresizingMaskIntoConstraints = false
view.addObserver(self, forKeyPath: "hidden", options: [.new, .old], context: nil)

#if swift(>=4.2)
if view.layoutMargins == UIEdgeInsetsMake_(8, 8, 8, 8) {
view.layoutMargins = UIEdgeInsets.zero
}
#else
if UIEdgeInsetsEqualToEdgeInsets(view.layoutMargins, UIEdgeInsetsMake(8, 8, 8, 8)) {
view.layoutMargins = UIEdgeInsets.zero
}
#endif


if !view.isHidden {
addAndActivateConstraintsForView(at: index)
Expand Down Expand Up @@ -148,7 +155,7 @@ public class CPKStackView: UIView {
}

public override func sizeThatFits(_ size: CGSize) -> CGSize {
return systemLayoutSizeFitting(UILayoutFittingCompressedSize)
return systemLayoutSizeFitting(UILayoutFittingCompressedSize_)
}


Expand Down Expand Up @@ -256,7 +263,7 @@ public class CPKStackView: UIView {
@discardableResult
private func addAlignmentConstraint(at index: Int) -> [NSLayoutConstraint] {
var newConstraints = [NSLayoutConstraint]()
var att = NSLayoutAttribute.notAnAttribute
var att = NSLayoutAttribute_.notAnAttribute

if self.alignment == .fill {

Expand Down Expand Up @@ -337,7 +344,7 @@ public class CPKStackView: UIView {
newConstraints.append(makeConstraint(index, .topMargin, .equal, -1, .topMargin, enclosurePriority))
newConstraints.append(makeConstraint(index, .topMargin, .greaterThanOrEqual, -1, .topMargin, 1000))

var att: NSLayoutAttribute = .bottomMargin
var att: NSLayoutAttribute_ = .bottomMargin
if self.alignment == .baseline {
att = .lastBaseline
}
Expand Down Expand Up @@ -391,8 +398,8 @@ public class CPKStackView: UIView {
return nil
}

var att1 = NSLayoutAttribute.notAnAttribute
var att2 = NSLayoutAttribute.notAnAttribute
var att1 = NSLayoutAttribute_.notAnAttribute
var att2 = NSLayoutAttribute_.notAnAttribute

if self.axis == .vertical {
att1 = (item1 == self ? .topMargin : .bottomMargin)
Expand Down Expand Up @@ -524,7 +531,7 @@ public class CPKStackView: UIView {
}

if !hasConstraint {
let att: NSLayoutAttribute = (self.axis == .vertical ? .height : .width)
let att: NSLayoutAttribute_ = (self.axis == .vertical ? .height : .width)
let c = makeConstraint(i, att, .equal, index, att, 1, 0, kSpringPriority)
self.springConstraints.append(c)
newConstraints.append(c)
Expand Down Expand Up @@ -559,10 +566,10 @@ public class CPKStackView: UIView {

//MARK: Utils
private func makeConstraint(_ index1: Int,
_ att1: NSLayoutAttribute,
_ relation: NSLayoutRelation,
_ att1: NSLayoutAttribute_,
_ relation: NSLayoutRelation_,
_ index2: Int,
_ att2: NSLayoutAttribute,
_ att2: NSLayoutAttribute_,
_ multiplier: CGFloat,
_ constant: CGFloat,
_ priority: UILayoutPriority) -> NSLayoutConstraint {
Expand All @@ -583,10 +590,10 @@ public class CPKStackView: UIView {
}

private func makeConstraint(_ index1: Int,
_ att1: NSLayoutAttribute,
_ relation: NSLayoutRelation,
_ att1: NSLayoutAttribute_,
_ relation: NSLayoutRelation_,
_ index2: Int,
_ att2: NSLayoutAttribute,
_ att2: NSLayoutAttribute_,
_ priority: UILayoutPriority) -> NSLayoutConstraint {

return makeConstraint(index1, att1, relation, index2, att2, 1, 0, priority)
Expand Down Expand Up @@ -675,9 +682,9 @@ class CPKTransformLayer: CATransformLayer {


public class StackSpring: UIView {
private var _axis: UILayoutConstraintAxis = .horizontal
private var _axis: UILayoutConstraintAxis_ = .horizontal

fileprivate var axis: UILayoutConstraintAxis {
fileprivate var axis: UILayoutConstraintAxis_ {
get { return _axis }
set {
if _axis != newValue {
Expand Down
2 changes: 1 addition & 1 deletion Cupcake/Font.swift
Expand Up @@ -41,7 +41,7 @@ public func Font(_ any: Any) -> UIFont {
}

let value = "UICTFontTextStyle" + string.capitalized
return UIFont.preferredFont(forTextStyle: UIFontTextStyle(rawValue: value))
return UIFont.preferredFont(forTextStyle: UIFontTextStyle_(rawValue: value))
}

return UIFont.systemFont(ofSize: CPKFloat(any))
Expand Down
2 changes: 1 addition & 1 deletion Cupcake/ImageView.swift
Expand Up @@ -48,7 +48,7 @@ public extension UIImageView {
.mode(.center)
...
*/
@objc @discardableResult public func mode(_ contentMode: UIViewContentMode) -> Self {
@objc @discardableResult public func mode(_ contentMode: UIViewContentMode_) -> Self {
self.contentMode = contentMode
return self
}
Expand Down
2 changes: 1 addition & 1 deletion Cupcake/StaticTable.swift
Expand Up @@ -311,7 +311,7 @@ public extension StaticRow {
.style(.value2)
...
*/
@discardableResult public func style(_ style: UITableViewCellStyle) -> Self {
@discardableResult public func style(_ style: UITableViewCellStyle_) -> Self {
self.cellStyle = style
return self
}
Expand Down

0 comments on commit 5f9a85b

Please sign in to comment.