Skip to content

Commit 5965d8b

Browse files
committed
Support iOS 11 and iPhone X
1 parent 9a83231 commit 5965d8b

33 files changed

+588
-287
lines changed

CHANGELOG.md

+24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
# Change Log
22
All notable changes to this project will be documented in this file.
33

4+
## 4.0.0
5+
6+
### Features
7+
* Swift 4.0 syntax
8+
* Added support for iOS 11 and iPhone X. From the readme:
9+
10+
SwiftMessages 4 supports iOS 11 out-of-the-box with built-in support for safe areas. To ensur that message view layouts look just right when overlapping safe areas, views that adopt the `MarginAdjustable` protocol (like `MessageView`) will have their layout margins automatically adjusted by SwiftMessages. However, there is no one-size-fits-all adjustment, so the following properties were added to `MarginAdjustable` to allow for additional adjustments to be made to the layout margins:
11+
12+
````swift
13+
public protocol MarginAdjustable {
14+
...
15+
/// Safe area top adjustment in iOS 11+
16+
var safeAreaTopOffset: CGFloat { get set }
17+
/// Safe area bottom adjustment in iOS 11+
18+
var safeAreaBottomOffset: CGFloat { get set }
19+
}
20+
````
21+
22+
If you're using using custom nib files or view classes and your layouts don't look quite right, try adjusting the values of these properties. `BaseView` (the super class of `MessageView`) declares these properties to be `@IBDesignable` and you can find sample values in the nib files included with SwiftMessages.
23+
24+
### Bug Fixes
25+
* Fix #100 memory leak.
26+
* Change `Layout` enum capitalization to current Swift conventions.
27+
428
## [3.5.1](https://github.com/SwiftKickMobile/SwiftMessages/releases/tag/3.5.0)
529

630
### Bug Fixes

Demo/Demo.xcodeproj/project.pbxproj

+18-4
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@
136136
isa = PBXProject;
137137
attributes = {
138138
LastSwiftUpdateCheck = 0730;
139-
LastUpgradeCheck = 0810;
139+
LastUpgradeCheck = 0900;
140140
ORGANIZATIONNAME = "SwiftKick Mobile";
141141
TargetAttributes = {
142142
86AEDCE11D5D1DB70030232E = {
143143
CreatedOnToolsVersion = 7.3.1;
144144
DevelopmentTeam = 38R82CD868;
145-
LastSwiftMigration = 0800;
145+
LastSwiftMigration = 0900;
146146
};
147147
};
148148
};
@@ -278,14 +278,20 @@
278278
CLANG_CXX_LIBRARY = "libc++";
279279
CLANG_ENABLE_MODULES = YES;
280280
CLANG_ENABLE_OBJC_ARC = YES;
281+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
281282
CLANG_WARN_BOOL_CONVERSION = YES;
283+
CLANG_WARN_COMMA = YES;
282284
CLANG_WARN_CONSTANT_CONVERSION = YES;
283285
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
284286
CLANG_WARN_EMPTY_BODY = YES;
285287
CLANG_WARN_ENUM_CONVERSION = YES;
286288
CLANG_WARN_INFINITE_RECURSION = YES;
287289
CLANG_WARN_INT_CONVERSION = YES;
290+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
291+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
288292
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
293+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
294+
CLANG_WARN_STRICT_PROTOTYPES = YES;
289295
CLANG_WARN_SUSPICIOUS_MOVE = YES;
290296
CLANG_WARN_UNREACHABLE_CODE = YES;
291297
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -326,14 +332,20 @@
326332
CLANG_CXX_LIBRARY = "libc++";
327333
CLANG_ENABLE_MODULES = YES;
328334
CLANG_ENABLE_OBJC_ARC = YES;
335+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
329336
CLANG_WARN_BOOL_CONVERSION = YES;
337+
CLANG_WARN_COMMA = YES;
330338
CLANG_WARN_CONSTANT_CONVERSION = YES;
331339
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
332340
CLANG_WARN_EMPTY_BODY = YES;
333341
CLANG_WARN_ENUM_CONVERSION = YES;
334342
CLANG_WARN_INFINITE_RECURSION = YES;
335343
CLANG_WARN_INT_CONVERSION = YES;
344+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
345+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
336346
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
347+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
348+
CLANG_WARN_STRICT_PROTOTYPES = YES;
337349
CLANG_WARN_SUSPICIOUS_MOVE = YES;
338350
CLANG_WARN_UNREACHABLE_CODE = YES;
339351
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -370,7 +382,8 @@
370382
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
371383
PRODUCT_BUNDLE_IDENTIFIER = it.swiftkick.Demo;
372384
PRODUCT_NAME = "$(TARGET_NAME)";
373-
SWIFT_VERSION = 3.0;
385+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
386+
SWIFT_VERSION = 4.0;
374387
};
375388
name = Debug;
376389
};
@@ -385,7 +398,8 @@
385398
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
386399
PRODUCT_BUNDLE_IDENTIFIER = it.swiftkick.Demo;
387400
PRODUCT_NAME = "$(TARGET_NAME)";
388-
SWIFT_VERSION = 3.0;
401+
SWIFT_SWIFT3_OBJC_INFERENCE = Off;
402+
SWIFT_VERSION = 4.0;
389403
};
390404
name = Release;
391405
};

Demo/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
"idiom" : "iphone",
4040
"size" : "60x60",
4141
"scale" : "3x"
42+
},
43+
{
44+
"idiom" : "ios-marketing",
45+
"size" : "1024x1024",
46+
"scale" : "1x"
4247
}
4348
],
4449
"info" : {

Demo/Demo/Base.lproj/Main.storyboard

+29-9
Large diffs are not rendered by default.

Demo/Demo/ExploreViewController.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ class ExploreViewController: UITableViewController, UITextFieldDelegate {
1818
let view: MessageView
1919
switch layout.selectedSegmentIndex {
2020
case 1:
21-
view = MessageView.viewFromNib(layout: .CardView)
21+
view = MessageView.viewFromNib(layout: .cardView)
2222
case 2:
23-
view = MessageView.viewFromNib(layout: .TabView)
23+
view = MessageView.viewFromNib(layout: .tabView)
2424
case 3:
25-
view = MessageView.viewFromNib(layout: .StatusLine)
25+
view = MessageView.viewFromNib(layout: .statusLine)
2626
default:
2727
view = try! SwiftMessages.viewFromNib()
2828
}
@@ -51,7 +51,7 @@ class ExploreViewController: UITableViewController, UITextFieldDelegate {
5151
default:
5252
let iconText = ["🐸", "🐷", "🐬", "🐠", "🐍", "🐹", "🐼"].sm_random()
5353
view.configureTheme(backgroundColor: UIColor.purple, foregroundColor: UIColor.white, iconImage: nil, iconText: iconText)
54-
view.button?.setImage(Icon.ErrorSubtle.image, for: .normal)
54+
view.button?.setImage(Icon.errorSubtle.image, for: .normal)
5555
view.button?.setTitle(nil, for: .normal)
5656
view.button?.backgroundColor = UIColor.clear
5757
view.button?.tintColor = UIColor.green.withAlphaComponent(0.7)

Demo/Demo/TacoDialogView.xib

+27-15
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="11762" systemVersion="16D32" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13196" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
77
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11757"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13173"/>
99
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
1010
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1111
</dependencies>
12+
<customFonts key="customFonts">
13+
<array key="Futura.ttc">
14+
<string>Futura-CondensedMedium</string>
15+
<string>Futura-Medium</string>
16+
</array>
17+
</customFonts>
1218
<objects>
1319
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1420
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
@@ -17,19 +23,19 @@
1723
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1824
<subviews>
1925
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="dp3-Ae-zep" userLabel="Background view">
20-
<rect key="frame" x="18" y="18" width="572" height="281"/>
26+
<rect key="frame" x="30" y="10" width="560" height="289"/>
2127
<subviews>
2228
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" spacing="10" translatesAutoresizingMaskIntoConstraints="NO" id="RJH-Fp-YDa" userLabel="Content view">
23-
<rect key="frame" x="30" y="30" width="512" height="221"/>
29+
<rect key="frame" x="30" y="30" width="500" height="229"/>
2430
<subviews>
2531
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="Irk-mj-bK8">
26-
<rect key="frame" x="0.0" y="0.0" width="512" height="60"/>
32+
<rect key="frame" x="0.0" y="0.0" width="500" height="60"/>
2733
<subviews>
2834
<stackView opaque="NO" contentMode="scaleToFill" distribution="fillProportionally" alignment="center" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="aav-a1-ogq">
29-
<rect key="frame" x="0.0" y="0.0" width="512" height="60"/>
35+
<rect key="frame" x="-30" y="0.0" width="500" height="60"/>
3036
<subviews>
3137
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xLT-bX-GJE">
32-
<rect key="frame" x="0.0" y="0.0" width="512" height="60"/>
38+
<rect key="frame" x="0.0" y="0.0" width="500" height="60"/>
3339
<subviews>
3440
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="252" verticalHuggingPriority="251" horizontalCompressionResistancePriority="748" text="🌮" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="pFx-Py-lZQ" userLabel="Icon label">
3541
<rect key="frame" x="0.0" y="0.0" width="50" height="60"/>
@@ -44,7 +50,7 @@
4450
<nil key="highlightedColor"/>
4551
</label>
4652
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" horizontalCompressionResistancePriority="1000" text="Just one, please." textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YAk-Zs-x2f">
47-
<rect key="frame" x="65" y="0.0" width="447" height="60"/>
53+
<rect key="frame" x="95" y="0.0" width="435" height="60"/>
4854
<accessibility key="accessibilityConfiguration">
4955
<bool key="isElement" value="NO"/>
5056
</accessibility>
@@ -70,7 +76,7 @@
7076
</subviews>
7177
</stackView>
7278
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" verticalCompressionResistancePriority="748" text="How many tocos would you like?" textAlignment="center" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="gMT-Vh-S3z">
73-
<rect key="frame" x="0.0" y="73.5" width="512" height="23.5"/>
79+
<rect key="frame" x="0.0" y="75.5" width="500" height="23.5"/>
7480
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
7581
<accessibility key="accessibilityConfiguration">
7682
<bool key="isElement" value="NO"/>
@@ -80,13 +86,13 @@
8086
<nil key="highlightedColor"/>
8187
</label>
8288
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Adjust the taco slider and place your order." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="U9w-CI-YK7">
83-
<rect key="frame" x="0.0" y="111" width="512" height="17"/>
89+
<rect key="frame" x="0.0" y="115" width="500" height="17"/>
8490
<fontDescription key="fontDescription" name="Futura-CondensedMedium" family="Futura" pointSize="14"/>
8591
<color key="textColor" red="0.60392156862745094" green="0.44313725490196076" blue="0.10588235294117647" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
8692
<nil key="highlightedColor"/>
8793
</label>
8894
<slider opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" value="1" minValue="1" maxValue="5" translatesAutoresizingMaskIntoConstraints="NO" id="MKs-Kv-aPL">
89-
<rect key="frame" x="-2" y="141.5" width="516" height="31"/>
95+
<rect key="frame" x="-2" y="147.5" width="504" height="31"/>
9096
<color key="minimumTrackTintColor" red="0.94509803921568625" green="0.57647058823529407" blue="0.078431372549019607" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
9197
<connections>
9298
<action selector="tacoSliderFinished:" destination="JI3-gM-XBO" eventType="touchUpInside" id="ekV-4L-MLR"/>
@@ -95,10 +101,10 @@
95101
</connections>
96102
</slider>
97103
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" alignment="bottom" translatesAutoresizingMaskIntoConstraints="NO" id="x8I-RG-nBX">
98-
<rect key="frame" x="0.0" y="185" width="512" height="36"/>
104+
<rect key="frame" x="0.0" y="193" width="500" height="36"/>
99105
<subviews>
100106
<stackView opaque="NO" contentMode="scaleToFill" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="8Qt-TE-nPO">
101-
<rect key="frame" x="355" y="0.0" width="157" height="36"/>
107+
<rect key="frame" x="343" y="0.0" width="157" height="36"/>
102108
<subviews>
103109
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="yFi-Ik-klX">
104110
<rect key="frame" x="0.0" y="0.0" width="58" height="36"/>
@@ -143,7 +149,7 @@
143149
</constraints>
144150
<userDefinedRuntimeAttributes>
145151
<userDefinedRuntimeAttribute type="number" keyPath="layer.cornerRadius">
146-
<integer key="value" value="5"/>
152+
<integer key="value" value="10"/>
147153
</userDefinedRuntimeAttribute>
148154
</userDefinedRuntimeAttributes>
149155
</view>
@@ -152,7 +158,7 @@
152158
<constraints>
153159
<constraint firstAttribute="trailing" secondItem="dp3-Ae-zep" secondAttribute="trailing" constant="10" id="gGP-zK-6VU"/>
154160
<constraint firstItem="dp3-Ae-zep" firstAttribute="leading" secondItem="JI3-gM-XBO" secondAttribute="leadingMargin" constant="10" id="gyP-aD-uO3"/>
155-
<constraint firstAttribute="bottom" secondItem="dp3-Ae-zep" secondAttribute="bottom" constant="10" id="le8-gK-lcY"/>
161+
<constraint firstAttribute="bottomMargin" secondItem="dp3-Ae-zep" secondAttribute="bottom" constant="10" id="le8-gK-lcY"/>
156162
<constraint firstItem="dp3-Ae-zep" firstAttribute="top" secondItem="JI3-gM-XBO" secondAttribute="topMargin" constant="10" id="s15-z9-aHc"/>
157163
</constraints>
158164
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
@@ -163,6 +169,12 @@
163169
<userDefinedRuntimeAttribute type="number" keyPath="statusBarOffset">
164170
<real key="value" value="10"/>
165171
</userDefinedRuntimeAttribute>
172+
<userDefinedRuntimeAttribute type="number" keyPath="safeAreaTopOffset">
173+
<real key="value" value="-8"/>
174+
</userDefinedRuntimeAttribute>
175+
<userDefinedRuntimeAttribute type="number" keyPath="safeAreaBottomOffset">
176+
<real key="value" value="-18"/>
177+
</userDefinedRuntimeAttribute>
166178
</userDefinedRuntimeAttributes>
167179
<connections>
168180
<outlet property="backgroundView" destination="dp3-Ae-zep" id="ZiK-GN-SXH"/>

Demo/Demo/Utils.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ extension UILabel {
1313
func configureBodyTextStyle() {
1414
let bodyStyle = NSMutableParagraphStyle()
1515
bodyStyle.lineSpacing = 5.0
16-
attributedText = NSAttributedString(string: text ?? "", attributes: [NSParagraphStyleAttributeName : bodyStyle])
16+
attributedText = NSAttributedString(string: text ?? "", attributes: [NSAttributedStringKey.paragraphStyle : bodyStyle])
1717
}
1818

1919
func configureCodeStyle(on substring: String?) {
20-
var attributes: [String : Any] = [:]
20+
var attributes: [NSAttributedStringKey : Any] = [:]
2121
let codeFont = UIFont(name: "CourierNewPSMT", size: font.pointSize)!
22-
attributes[NSFontAttributeName] = codeFont
23-
attributes[NSBackgroundColorAttributeName] = UIColor(white: 0.96, alpha: 1)
22+
attributes[NSAttributedStringKey.font] = codeFont
23+
attributes[NSAttributedStringKey.backgroundColor] = UIColor(white: 0.96, alpha: 1)
2424
attributedText = attributedText?.setAttributes(attributes: attributes, onSubstring: substring)
2525
}
2626
}
2727

2828
extension NSAttributedString {
2929

30-
public func setAttributes(attributes: [String : Any], onSubstring substring: String?) -> NSAttributedString {
30+
public func setAttributes(attributes: [NSAttributedStringKey : Any], onSubstring substring: String?) -> NSAttributedString {
3131
let mutableSelf = NSMutableAttributedString(attributedString: self)
3232
if let substring = substring {
3333
var range = NSRange()
@@ -46,7 +46,7 @@ extension NSAttributedString {
4646
return mutableSelf
4747
}
4848

49-
private static func set(attributes newAttributes: [String : Any], in range: NSRange, of mutableString: NSMutableAttributedString) {
49+
private static func set(attributes newAttributes: [NSAttributedStringKey : Any], in range: NSRange, of mutableString: NSMutableAttributedString) {
5050
if range.length > 0 {
5151
var attributes = mutableString.attributes(at: range.location, effectiveRange: nil)
5252
for (key, value) in newAttributes {

0 commit comments

Comments
 (0)