Skip to content

Commit 763cea9

Browse files
author
Vinícius Soares
committed
Merge pull request #2 from AJ9/master
Swift 2.0 Support
2 parents 31b623a + 2415659 commit 763cea9

File tree

8 files changed

+198
-69
lines changed

8 files changed

+198
-69
lines changed

Demo/DatePickerDialogExample.xcodeproj/project.pbxproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@
123123
81EC6C741A1EADF7009440DB /* Project object */ = {
124124
isa = PBXProject;
125125
attributes = {
126-
LastUpgradeCheck = 0610;
126+
LastSwiftUpdateCheck = 0700;
127+
LastUpgradeCheck = 0700;
127128
ORGANIZATIONNAME = vinicius;
128129
TargetAttributes = {
129130
81EC6C7B1A1EADF7009440DB = {
@@ -206,6 +207,7 @@
206207
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
207208
COPY_PHASE_STRIP = NO;
208209
ENABLE_STRICT_OBJC_MSGSEND = YES;
210+
ENABLE_TESTABILITY = YES;
209211
GCC_C_LANGUAGE_STANDARD = gnu99;
210212
GCC_DYNAMIC_NO_PIC = NO;
211213
GCC_OPTIMIZATION_LEVEL = 0;
@@ -270,6 +272,7 @@
270272
INFOPLIST_FILE = PickerDialog/Info.plist;
271273
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
272274
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
275+
PRODUCT_BUNDLE_IDENTIFIER = "com.squimer.$(PRODUCT_NAME:rfc1034identifier)";
273276
PRODUCT_NAME = DatePickerDialogExample;
274277
};
275278
name = Debug;
@@ -281,6 +284,7 @@
281284
INFOPLIST_FILE = PickerDialog/Info.plist;
282285
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
283286
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
287+
PRODUCT_BUNDLE_IDENTIFIER = "com.squimer.$(PRODUCT_NAME:rfc1034identifier)";
284288
PRODUCT_NAME = DatePickerDialogExample;
285289
};
286290
name = Release;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0700"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "81EC6C7B1A1EADF7009440DB"
18+
BuildableName = "DatePickerDialogExample.app"
19+
BlueprintName = "DatePickerDialogExample"
20+
ReferencedContainer = "container:DatePickerDialogExample.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
buildConfiguration = "Debug"
27+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
28+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
shouldUseLaunchSchemeArgsEnv = "YES">
30+
<Testables>
31+
</Testables>
32+
<MacroExpansion>
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "81EC6C7B1A1EADF7009440DB"
36+
BuildableName = "DatePickerDialogExample.app"
37+
BlueprintName = "DatePickerDialogExample"
38+
ReferencedContainer = "container:DatePickerDialogExample.xcodeproj">
39+
</BuildableReference>
40+
</MacroExpansion>
41+
<AdditionalOptions>
42+
</AdditionalOptions>
43+
</TestAction>
44+
<LaunchAction
45+
buildConfiguration = "Debug"
46+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
47+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
48+
launchStyle = "0"
49+
useCustomWorkingDirectory = "NO"
50+
ignoresPersistentStateOnLaunch = "NO"
51+
debugDocumentVersioning = "YES"
52+
debugServiceExtension = "internal"
53+
allowLocationSimulation = "YES">
54+
<BuildableProductRunnable
55+
runnableDebuggingMode = "0">
56+
<BuildableReference
57+
BuildableIdentifier = "primary"
58+
BlueprintIdentifier = "81EC6C7B1A1EADF7009440DB"
59+
BuildableName = "DatePickerDialogExample.app"
60+
BlueprintName = "DatePickerDialogExample"
61+
ReferencedContainer = "container:DatePickerDialogExample.xcodeproj">
62+
</BuildableReference>
63+
</BuildableProductRunnable>
64+
<AdditionalOptions>
65+
</AdditionalOptions>
66+
</LaunchAction>
67+
<ProfileAction
68+
buildConfiguration = "Release"
69+
shouldUseLaunchSchemeArgsEnv = "YES"
70+
savedToolIdentifier = ""
71+
useCustomWorkingDirectory = "NO"
72+
debugDocumentVersioning = "YES">
73+
<BuildableProductRunnable
74+
runnableDebuggingMode = "0">
75+
<BuildableReference
76+
BuildableIdentifier = "primary"
77+
BlueprintIdentifier = "81EC6C7B1A1EADF7009440DB"
78+
BuildableName = "DatePickerDialogExample.app"
79+
BlueprintName = "DatePickerDialogExample"
80+
ReferencedContainer = "container:DatePickerDialogExample.xcodeproj">
81+
</BuildableReference>
82+
</BuildableProductRunnable>
83+
</ProfileAction>
84+
<AnalyzeAction
85+
buildConfiguration = "Debug">
86+
</AnalyzeAction>
87+
<ArchiveAction
88+
buildConfiguration = "Release"
89+
revealArchiveInOrganizer = "YES">
90+
</ArchiveAction>
91+
</Scheme>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>SchemeUserState</key>
6+
<dict>
7+
<key>DatePickerDialogExample.xcscheme</key>
8+
<dict>
9+
<key>orderHint</key>
10+
<integer>0</integer>
11+
</dict>
12+
</dict>
13+
<key>SuppressBuildableAutocreation</key>
14+
<dict>
15+
<key>81EC6C7B1A1EADF7009440DB</key>
16+
<dict>
17+
<key>primary</key>
18+
<true/>
19+
</dict>
20+
</dict>
21+
</dict>
22+
</plist>

Demo/Library/DatePickerDialog.swift

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
//
2+
// DatePicker.swift
3+
4+
import Foundation
15
import UIKit
26
import QuartzCore
37

8+
49
class DatePickerDialog: UIView {
510

611
/* Consts */
@@ -25,15 +30,16 @@ class DatePickerDialog: UIView {
2530
private var datePickerMode: UIDatePickerMode!
2631
private var callback: ((date: NSDate) -> Void)!
2732

33+
2834
/* Overrides */
29-
override init() {
35+
init() {
3036
super.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))
3137

3238
NSNotificationCenter.defaultCenter().addObserver(self, selector: "deviceOrientationDidChange:", name: UIDeviceOrientationDidChangeNotification, object: nil)
3339
}
34-
40+
3541
required init(coder aDecoder: NSCoder) {
36-
super.init(coder: aDecoder)
42+
fatalError("init(coder:) has not been implemented")
3743
}
3844

3945
/* Handle device orientation changes */
@@ -42,11 +48,11 @@ class DatePickerDialog: UIView {
4248
}
4349

4450
/* Create the dialog view, and animate opening the dialog */
45-
func show(#title: String, datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
46-
show(title: title, doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: datePickerMode, callback: callback)
51+
func show(title: String, datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
52+
show(title, doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: datePickerMode, callback: callback)
4753
}
4854

49-
func show(#title: String, doneButtonTitle: String, cancelButtonTitle: String, defaultDate: NSDate = NSDate(), datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
55+
func show(title: String, doneButtonTitle: String, cancelButtonTitle: String, defaultDate: NSDate = NSDate(), datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
5056
self.title = title
5157
self.doneButtonTitle = doneButtonTitle
5258
self.cancelButtonTitle = cancelButtonTitle
@@ -71,27 +77,27 @@ class DatePickerDialog: UIView {
7177

7278
/* Attached to the top most window (make sure we are using the right orientation) */
7379
let interfaceOrientation = UIApplication.sharedApplication().statusBarOrientation
74-
80+
7581
switch(interfaceOrientation) {
76-
case UIInterfaceOrientation.LandscapeLeft:
77-
let t: Double = M_PI * 270 / 180
78-
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
79-
break
82+
case UIInterfaceOrientation.LandscapeLeft:
83+
let t: Double = M_PI * 270 / 180
84+
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
85+
break
8086

81-
case UIInterfaceOrientation.LandscapeRight:
82-
let t: Double = M_PI * 90 / 180
83-
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
84-
break
85-
86-
case UIInterfaceOrientation.PortraitUpsideDown:
87-
let t: Double = M_PI * 180 / 180
88-
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
89-
break
90-
91-
default:
92-
break
93-
}
87+
case UIInterfaceOrientation.LandscapeRight:
88+
let t: Double = M_PI * 90 / 180
89+
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
90+
break
91+
92+
case UIInterfaceOrientation.PortraitUpsideDown:
93+
let t: Double = M_PI * 180 / 180
94+
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
95+
break
9496

97+
default:
98+
break
99+
}
100+
95101
self.frame = CGRectMake(0, 0, self.frame.width, self.frame.size.height)
96102
UIApplication.sharedApplication().windows.first!.addSubview(self)
97103

@@ -113,7 +119,7 @@ class DatePickerDialog: UIView {
113119
private func close() {
114120
let currentTransform = self.dialogView.layer.transform
115121

116-
let startRotation = (self.valueForKeyPath("layer.transform.rotation.z") as? NSNumber)? as? Double ?? 0.0
122+
let startRotation = (self.valueForKeyPath("layer.transform.rotation.z") as? NSNumber) as? Double ?? 0.0
117123
let rotation = CATransform3DMakeRotation((CGFloat)(-startRotation + M_PI * 270 / 180), 0, 0, 0)
118124

119125
self.dialogView.layer.transform = CATransform3DConcat(rotation, CATransform3DMakeScale(1, 1, 1))
@@ -133,7 +139,7 @@ class DatePickerDialog: UIView {
133139
}
134140

135141
self.removeFromSuperview()
136-
}
142+
}
137143
}
138144

139145
/* Creates the container view here: create the dialog, then add the custom content and buttons */
@@ -142,8 +148,8 @@ class DatePickerDialog: UIView {
142148
let dialogSize = CGSizeMake(
143149
300,
144150
230
145-
+ kDatePickerDialogDefaultButtonHeight
146-
+ kDatePickerDialogDefaultButtonSpacerHeight)
151+
+ kDatePickerDialogDefaultButtonHeight
152+
+ kDatePickerDialogDefaultButtonSpacerHeight)
147153

148154
// For the black background
149155
self.frame = CGRectMake(0, 0, screenSize.width, screenSize.height)
@@ -155,8 +161,8 @@ class DatePickerDialog: UIView {
155161
let gradient: CAGradientLayer = CAGradientLayer(layer: self.layer)
156162
gradient.frame = dialogContainer.bounds
157163
gradient.colors = [UIColor(red: 218/255, green: 218/255, blue: 218/255, alpha: 1).CGColor,
158-
UIColor(red: 233/255, green: 233/255, blue: 233/255, alpha: 1).CGColor,
159-
UIColor(red: 218/255, green: 218/255, blue: 218/255, alpha: 1).CGColor]
164+
UIColor(red: 233/255, green: 233/255, blue: 233/255, alpha: 1).CGColor,
165+
UIColor(red: 218/255, green: 218/255, blue: 218/255, alpha: 1).CGColor]
160166

161167
let cornerRadius = kDatePickerDialogCornerRadius
162168
gradient.cornerRadius = cornerRadius
@@ -201,7 +207,7 @@ class DatePickerDialog: UIView {
201207
private func addButtonsToView(container: UIView) {
202208
let buttonWidth = container.bounds.size.width / 2
203209

204-
self.cancelButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
210+
self.cancelButton = UIButton(type: UIButtonType.Custom) as UIButton
205211
self.cancelButton.frame = CGRectMake(
206212
0,
207213
container.bounds.size.height - kDatePickerDialogDefaultButtonHeight,
@@ -217,7 +223,7 @@ class DatePickerDialog: UIView {
217223
self.cancelButton.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
218224
container.addSubview(self.cancelButton)
219225

220-
self.doneButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
226+
self.doneButton = UIButton(type: UIButtonType.Custom) as UIButton
221227
self.doneButton.frame = CGRectMake(
222228
buttonWidth,
223229
container.bounds.size.height - kDatePickerDialogDefaultButtonHeight,
@@ -260,4 +266,4 @@ class DatePickerDialog: UIView {
260266
return CGSizeMake(screenWidth, screenHeight)
261267
}
262268

263-
}
269+
}

0 commit comments

Comments
 (0)