Skip to content

Commit b7b4221

Browse files
committed
Add code comments
Added comments to most public APIs except the MessageView class.
1 parent 6c5bf48 commit b7b4221

11 files changed

+321
-54
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Change Log
2+
All notable changes to this project will be documented in this file.
3+
4+
## [1.0.1](https://github.com/SwiftKickMobile/SwiftMessages/releases/tag/1.0.1)
5+
6+
* Add code comments.
7+
8+
## [1.0.0](https://github.com/SwiftKickMobile/SwiftMessages/releases/tag/1.0.0)
9+
10+
* Initial release.

Demo/Demo/Base.lproj/Main.storyboard

+7-7
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@
134134
<autoresizingMask key="autoresizingMask"/>
135135
<subviews>
136136
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PRESENTATION STYLE" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Epw-Yk-L8V">
137-
<rect key="frame" x="17.5" y="8" width="147" height="16"/>
137+
<rect key="frame" x="18" y="8" width="147" height="16"/>
138138
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
139139
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
140140
<nil key="highlightedColor"/>
141141
</label>
142142
<segmentedControl opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="top" segmentControlStyle="plain" selectedSegmentIndex="0" translatesAutoresizingMaskIntoConstraints="NO" id="Agu-Vo-ckI">
143-
<rect key="frame" x="18" y="28.5" width="119" height="29"/>
143+
<rect key="frame" x="18" y="29" width="119" height="29"/>
144144
<segments>
145145
<segment title="Top"/>
146146
<segment title="Bottom"/>
@@ -165,7 +165,7 @@
165165
<autoresizingMask key="autoresizingMask"/>
166166
<subviews>
167167
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PRESENTATION CONTEXT" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="CU0-87-ZCD">
168-
<rect key="frame" x="17.5" y="8" width="169" height="16"/>
168+
<rect key="frame" x="18" y="8" width="169" height="16"/>
169169
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
170170
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
171171
<nil key="highlightedColor"/>
@@ -230,7 +230,7 @@
230230
<autoresizingMask key="autoresizingMask"/>
231231
<subviews>
232232
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DIM MODE" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="TsP-n5-Vko">
233-
<rect key="frame" x="18" y="8" width="68.5" height="16"/>
233+
<rect key="frame" x="18" y="8" width="69" height="16"/>
234234
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
235235
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
236236
<nil key="highlightedColor"/>
@@ -363,13 +363,13 @@
363363
<autoresizingMask key="autoresizingMask"/>
364364
<subviews>
365365
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="DROP SHADOW" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MUL-on-v9R">
366-
<rect key="frame" x="18" y="8" width="101.5" height="16"/>
366+
<rect key="frame" x="18" y="8" width="102" height="16"/>
367367
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
368368
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
369369
<nil key="highlightedColor"/>
370370
</label>
371371
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="sqb-Fg-YR8">
372-
<rect key="frame" x="533" y="0.5" width="51" height="31"/>
372+
<rect key="frame" x="533" y="1" width="51" height="31"/>
373373
</switch>
374374
</subviews>
375375
<constraints>
@@ -398,7 +398,7 @@
398398
<autoresizingMask key="autoresizingMask"/>
399399
<subviews>
400400
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="TITLE" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="zs0-Qc-Tls">
401-
<rect key="frame" x="18" y="8" width="46.5" height="16"/>
401+
<rect key="frame" x="18" y="8" width="47" height="16"/>
402402
<fontDescription key="fontDescription" type="boldSystem" pointSize="13"/>
403403
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
404404
<nil key="highlightedColor"/>

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ let view: MessageView = try! SwiftMessages.viewFromNib(named: "MyCustomNib")
132132
let view: MyCustomView = try! SwiftMessages.viewFromNib()
133133
````
134134

135-
`MessageView` provides optional block-based tap handler for the button and another for the view itself:
135+
`MessageView` provides an optional block-based tap handler for the button and another for the view itself:
136136

137137
````swift
138138
// Hide when button tapped

SwiftMessages.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'SwiftMessages'
3-
spec.version = '1.0.0'
3+
spec.version = '1.0.1'
44
spec.license = { :type => 'MIT' }
55
spec.homepage = 'https://github.com/SwiftKickMobile/SwiftMessages'
66
spec.authors = { 'Timothy Moose' => 'tim@swiftkick.it' }
77
spec.summary = 'A very flexible message bar for iOS written in Swift.'
8-
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '1.0.0'}
8+
spec.source = {:git => 'https://github.com/SwiftKickMobile/SwiftMessages.git', :tag => '1.0.1'}
99
spec.platform = :ios, '8.0'
1010
spec.ios.deployment_target = '8.0'
1111
spec.source_files = 'SwiftMessages/**/*.swift'

SwiftMessages/BackgroundViewable.swift

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@
88

99
import UIKit
1010

11+
/**
12+
Message views that implement the `BackgroundViewable` protocol will have the
13+
pan-to-hide gesture recognizer installed in the `backgroundView`. Message views
14+
always span the full width of the containing view. Typically, the `backgroundView`
15+
property defines the message view's visible region, allowing for card-style views
16+
where the message view background is transparent and the background view is inset
17+
from by some amount. See CardView.nib, for example.
18+
19+
This protocol is optional. Message views that don't implement `BackgroundViewable`
20+
will have the pan-to-hide gesture installed in the message view itself.
21+
*/
1122
public protocol BackgroundViewable {
1223
var backgroundView: UIView! { get }
1324
}

SwiftMessages/BaseView.swift

+43
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@
88

99
import UIKit
1010

11+
/*
12+
The `BaseView` class is a reusable message view base class that implements some
13+
of the optional SwiftMessages protocols and provides some convenience methods
14+
and a configurable tap handler. Message views do not need to inherit from `BaseVew`.
15+
*/
1116
public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
1217

1318
/*
1419
MARK: - IB outlets
1520
*/
1621

22+
/**
23+
Fulfills the `BackgroundViewable` protocol and is the target for
24+
the optional `tapHandler` block. Defaults to `self`.
25+
*/
1726
@IBOutlet public var backgroundView: UIView! {
1827
didSet {
1928
if let old = oldValue {
@@ -23,6 +32,17 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
2332
}
2433
}
2534

35+
/**
36+
The view containing the message view content and the target of the
37+
`installContentView` convenience method. Defaults to `self`.
38+
39+
This view has no specific functionality in SwiftMessages, but is provided
40+
as a reference to the content as a convenience. It is a distinctly separate
41+
property from `backgroundView`, though they may point to the same view (and
42+
they both point to `self` by default) to accommodate `UIStackViews` as
43+
content views, which do not render a background
44+
(see MessageView.nib and CardView.nib).
45+
*/
2646
@IBOutlet public var contentView: UIView!
2747

2848
/*
@@ -47,6 +67,15 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
4767
MARK: - Installing content
4868
*/
4969

70+
/**
71+
A convenience method for installing a content view as a subview of `backgroundView`
72+
and pinning the edges to `backgroundView` with the specified `insets`.
73+
74+
- Parameter contentView: The view to be installed into the background view
75+
and assigned to the `contentView` property.
76+
- Parameter insets: The amount to inset the content view from the background view.
77+
Default is zero inset.
78+
*/
5079
public func installContentView(contentView: UIView, insets: UIEdgeInsets = UIEdgeInsetsZero) {
5180
contentView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
5281
contentView.translatesAutoresizingMaskIntoConstraints = true
@@ -59,6 +88,9 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
5988
MARK: - Tap handler
6089
*/
6190

91+
/**
92+
An optional tap handler that will be called when the `backgroundView` is tapped.
93+
*/
6294
public var tapHandler: ((view: BaseView) -> Void)? {
6395
didSet {
6496
installTapRecognizer()
@@ -87,6 +119,10 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
87119

88120
/*
89121
MARK: - MarginAdjustable
122+
123+
These properties fulfill the `MarginAdjustable` protocol and are exposed
124+
as `@IBInspectables` so that they can be adjusted directly in nib files
125+
(see MessageView.nib).
90126
*/
91127

92128
@IBInspectable public var bounceAnimationOffset: CGFloat = 5.0
@@ -98,6 +134,12 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
98134
MARK: - Setting preferred height
99135
*/
100136

137+
/**
138+
An optional value that sets the message view's intrinsic content height.
139+
This can be used as a way to specify a fixed height for the message view.
140+
Note that this height is not guaranteed depending on anyt Auto Layout
141+
constraints used within the message view.
142+
*/
101143
public var preferredHeight: CGFloat? {
102144
didSet {
103145
setNeedsLayout()
@@ -118,6 +160,7 @@ public class BaseView: UIView, BackgroundViewable, MarginAdjustable {
118160

119161
extension BaseView {
120162

163+
/// A convenience method to configure a default drop shadow effect.
121164
public func configureDropShadow() {
122165
let layer = backgroundView.layer
123166
layer.shadowColor = UIColor.blackColor().CGColor

SwiftMessages/Error.swift

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
import Foundation
1010

11+
/**
12+
The `Error` enum contains the errors thrown by SwiftMessages.
13+
*/
1114
enum Error: ErrorType {
1215
case CannotLoadViewFromNib(nibName: String)
1316
case NoRootViewController

SwiftMessages/Icon.swift

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import UIKit
1010

11+
/// The Icon enum provides type-safe access to the included icons.
1112
public enum Icon: String {
1213

1314
case Error = "errorIcon"
@@ -23,6 +24,7 @@ public enum Icon: String {
2324
case SuccessSubtle = "successIconSubtle"
2425
case InfoSubtle = "infoIconSubtle"
2526

27+
/// Returns the associated image.
2628
public var image: UIImage {
2729
return UIImage(named: rawValue, inBundle: NSBundle.sm_frameworkBundle(), compatibleWithTraitCollection: nil)!
2830
}

SwiftMessages/Identifiable.swift

+9
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
import Foundation
1010

11+
/**
12+
Message views that implement the `Identifiable` protocol will have duplicate messages
13+
removed from the `MessageView` queue. Typically, the `id` would be set to a string
14+
representation of the content of the message view. For example, `MessageView`, combines
15+
the title and message body text.
16+
17+
This protocol is optional. Messave views that don't implement `Identifiable` will not
18+
have duplicates removed.
19+
*/
1120
public protocol Identifiable {
1221
var id: String { get }
1322
}

SwiftMessages/MarginAdjustable.swift

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88

99
import UIKit
1010

11+
/*
12+
Message views that implement the `MarginAdjustable` protocol will have their
13+
`layoutMargins` adjusted by SwiftMessages to account for the height of the
14+
status bar (when displayed under the status bar) and a small amount of
15+
overshoot in the bounce animation. `MessageView` implements this protocol
16+
by way of its parent class `BaseView`.
17+
18+
For the effect of this protocol to work, subviews should be pinned to the
19+
message view's margins and the `layoutMargins` property should not be modified.
20+
21+
This protocol is optional. A message view that doesn't implement `MarginAdjustable`
22+
is responsible for setting is own internal margins appropriately.
23+
*/
1124
public protocol MarginAdjustable {
1225
var bounceAnimationOffset: CGFloat { get set }
1326
var statusBarOffset: CGFloat { get set }

0 commit comments

Comments
 (0)