Skip to content

Commit

Permalink
Merge pull request #91 from calvinchengx/master
Browse files Browse the repository at this point in the history
Convert to Swift 2
  • Loading branch information
vikmeup committed Aug 8, 2015
2 parents 4079353 + dbc3d12 commit 4a514b2
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 29 deletions.
9 changes: 8 additions & 1 deletion Example/SCLAlertViewExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@
CEABB2391942AD9700FCB13C /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0600;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = "Viktor Radchenko";
TargetAttributes = {
CEABB2401942AD9700FCB13C = {
Expand Down Expand Up @@ -268,6 +270,7 @@
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
Expand Down Expand Up @@ -332,6 +335,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
INFOPLIST_FILE = SCLAlertViewExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -344,6 +348,7 @@
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
INFOPLIST_FILE = SCLAlertViewExample/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand All @@ -364,6 +369,7 @@
INFOPLIST_FILE = SCLAlertViewExampleTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = YES;
PRODUCT_BUNDLE_IDENTIFIER = "SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
};
Expand All @@ -380,6 +386,7 @@
INFOPLIST_FILE = SCLAlertViewExampleTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
METAL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUNDLE_LOADER)";
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CEABB2401942AD9700FCB13C"
BuildableName = "SCLAlertViewExample.app"
BlueprintName = "SCLAlertViewExample"
ReferencedContainer = "container:SCLAlertViewExample.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CEABB2541942AD9700FCB13C"
BuildableName = "SCLAlertViewExampleTests.xctest"
BlueprintName = "SCLAlertViewExampleTests"
ReferencedContainer = "container:SCLAlertViewExample.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CEABB2401942AD9700FCB13C"
BuildableName = "SCLAlertViewExample.app"
BlueprintName = "SCLAlertViewExample"
ReferencedContainer = "container:SCLAlertViewExample.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CEABB2401942AD9700FCB13C"
BuildableName = "SCLAlertViewExample.app"
BlueprintName = "SCLAlertViewExample"
ReferencedContainer = "container:SCLAlertViewExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CEABB2401942AD9700FCB13C"
BuildableName = "SCLAlertViewExample.app"
BlueprintName = "SCLAlertViewExample"
ReferencedContainer = "container:SCLAlertViewExample.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SCLAlertViewExample.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>CEABB2401942AD9700FCB13C</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>CEABB2541942AD9700FCB13C</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion Example/SCLAlertViewExample/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
44 changes: 22 additions & 22 deletions Example/SCLAlertViewExample/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class SCLButton: UIButton {
super.init(frame: CGRectZero)
}

required public init(coder aDecoder: NSCoder) {
required public init?(coder aDecoder: NSCoder) {
super.init(coder:aDecoder)
}

Expand Down Expand Up @@ -100,15 +100,15 @@ public class SCLAlertView: UIViewController {
private var inputs = [UITextField]()
private var buttons = [SCLButton]()

required public init(coder aDecoder: NSCoder) {
required public init?(coder aDecoder: NSCoder) {
fatalError("NSCoding not supported")
}

required public init() {
super.init(nibName:nil, bundle:nil)
// Set up main view
view.frame = UIScreen.mainScreen().bounds
view.autoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth
view.autoresizingMask = [UIViewAutoresizing.FlexibleHeight, UIViewAutoresizing.FlexibleWidth]
view.backgroundColor = UIColor(red:0, green:0, blue:0, alpha:kDefaultShadowOpacity)
view.addSubview(baseView)
// Base View
Expand All @@ -126,7 +126,7 @@ public class SCLAlertView: UIViewController {
circleBG.layer.cornerRadius = circleBG.frame.size.height / 2
baseView.addSubview(circleBG)
circleBG.addSubview(circleView)
var x = (kCircleHeightBackground - kCircleHeight) / 2
let x = (kCircleHeightBackground - kCircleHeight) / 2
circleView.frame = CGRect(x:x, y:x, width:kCircleHeight, height:kCircleHeight)
circleView.layer.cornerRadius = circleView.frame.size.height / 2
// Title
Expand Down Expand Up @@ -194,8 +194,8 @@ public class SCLAlertView: UIViewController {
}
}

override public func touchesEnded(touches:Set<NSObject>, withEvent event:UIEvent) {
if event.touchesForView(view)?.count > 0 {
override public func touchesEnded(touches:Set<UITouch>, withEvent event:UIEvent?) {
if event?.touchesForView(view)?.count > 0 {
view.endEditing(true)
}
}
Expand Down Expand Up @@ -224,8 +224,8 @@ public class SCLAlertView: UIViewController {
btn.actionType = SCLActionType.Closure
btn.action = action
btn.addTarget(self, action:Selector("buttonTapped:"), forControlEvents:.TouchUpInside)
btn.addTarget(self, action:Selector("buttonTapDown:"), forControlEvents:.TouchDown | .TouchDragEnter)
btn.addTarget(self, action:Selector("buttonRelease:"), forControlEvents:.TouchUpInside | .TouchUpOutside | .TouchCancel | .TouchDragOutside )
btn.addTarget(self, action:Selector("buttonTapDown:"), forControlEvents:[.TouchDown, .TouchDragEnter])
btn.addTarget(self, action:Selector("buttonRelease:"), forControlEvents:[.TouchUpInside, .TouchUpOutside, .TouchCancel, .TouchDragOutside] )
return btn
}

Expand All @@ -235,8 +235,8 @@ public class SCLAlertView: UIViewController {
btn.target = target
btn.selector = selector
btn.addTarget(self, action:Selector("buttonTapped:"), forControlEvents:.TouchUpInside)
btn.addTarget(self, action:Selector("buttonTapDown:"), forControlEvents:.TouchDown | .TouchDragEnter)
btn.addTarget(self, action:Selector("buttonRelease:"), forControlEvents:.TouchUpInside | .TouchUpOutside | .TouchCancel | .TouchDragOutside )
btn.addTarget(self, action:Selector("buttonTapDown:"), forControlEvents:[.TouchDown, .TouchDragEnter])
btn.addTarget(self, action:Selector("buttonRelease:"), forControlEvents:[.TouchUpInside, .TouchUpOutside, .TouchCancel, .TouchDragOutside] )
return btn
}

Expand All @@ -261,7 +261,7 @@ public class SCLAlertView: UIViewController {
ctrl.sendAction(btn.selector, to:btn.target, forEvent:nil)
return
} else {
println("Unknow action type for button")
print("Unknow action type for button")
}
hideView()
}
Expand Down Expand Up @@ -377,9 +377,9 @@ public class SCLAlertView: UIViewController {
viewText.text = subTitle
// Adjust text view size, if necessary
let str = subTitle as NSString
let attr = [NSFontAttributeName:viewText.font]
let attr = [NSFontAttributeName:viewText.font] as [String: AnyObject!]
let sz = CGSize(width: kWindowWidth - 24, height:90)
let r = str.boundingRectWithSize(sz, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes:attr, context:nil)
let r = str.boundingRectWithSize(sz, options: NSStringDrawingOptions.UsesLineFragmentOrigin, attributes: attr, context: nil)
let ht = ceil(r.size.height)
if ht < kTextHeight {
kWindowHeight -= (kTextHeight - ht)
Expand Down Expand Up @@ -487,7 +487,7 @@ class SCLAlertViewStyleKit : NSObject {
// Drawing Methods
class func drawCheckmark() {
// Checkmark Shape Drawing
var checkmarkShapePath = UIBezierPath()
let checkmarkShapePath = UIBezierPath()
checkmarkShapePath.moveToPoint(CGPointMake(73.25, 14.05))
checkmarkShapePath.addCurveToPoint(CGPointMake(64.51, 13.86), controlPoint1: CGPointMake(70.98, 11.44), controlPoint2: CGPointMake(66.78, 11.26))
checkmarkShapePath.addLineToPoint(CGPointMake(27.46, 52))
Expand All @@ -508,21 +508,21 @@ class SCLAlertViewStyleKit : NSObject {

class func drawCross() {
// Cross Shape Drawing
var crossShapePath = UIBezierPath()
let crossShapePath = UIBezierPath()
crossShapePath.moveToPoint(CGPointMake(10, 70))
crossShapePath.addLineToPoint(CGPointMake(70, 10))
crossShapePath.moveToPoint(CGPointMake(10, 10))
crossShapePath.addLineToPoint(CGPointMake(70, 70))
crossShapePath.lineCapStyle = kCGLineCapRound;
crossShapePath.lineJoinStyle = kCGLineJoinRound;
crossShapePath.lineCapStyle = CGLineCap.Round;
crossShapePath.lineJoinStyle = CGLineJoin.Round;
UIColor.whiteColor().setStroke()
crossShapePath.lineWidth = 14
crossShapePath.stroke()
}

class func drawNotice() {
// Notice Shape Drawing
var noticeShapePath = UIBezierPath()
let noticeShapePath = UIBezierPath()
noticeShapePath.moveToPoint(CGPointMake(72, 48.54))
noticeShapePath.addLineToPoint(CGPointMake(72, 39.9))
noticeShapePath.addCurveToPoint(CGPointMake(66.38, 34.01), controlPoint1: CGPointMake(72, 36.76), controlPoint2: CGPointMake(69.48, 34.01))
Expand Down Expand Up @@ -563,7 +563,7 @@ class SCLAlertViewStyleKit : NSObject {

// Warning Group
// Warning Circle Drawing
var warningCirclePath = UIBezierPath()
let warningCirclePath = UIBezierPath()
warningCirclePath.moveToPoint(CGPointMake(40.94, 63.39))
warningCirclePath.addCurveToPoint(CGPointMake(36.03, 65.55), controlPoint1: CGPointMake(39.06, 63.39), controlPoint2: CGPointMake(37.36, 64.18))
warningCirclePath.addCurveToPoint(CGPointMake(34.14, 70.45), controlPoint1: CGPointMake(34.9, 66.92), controlPoint2: CGPointMake(34.14, 68.49))
Expand All @@ -581,7 +581,7 @@ class SCLAlertViewStyleKit : NSObject {


// Warning Shape Drawing
var warningShapePath = UIBezierPath()
let warningShapePath = UIBezierPath()
warningShapePath.moveToPoint(CGPointMake(46.23, 4.26))
warningShapePath.addCurveToPoint(CGPointMake(40.94, 2.5), controlPoint1: CGPointMake(44.91, 3.09), controlPoint2: CGPointMake(43.02, 2.5))
warningShapePath.addCurveToPoint(CGPointMake(34.71, 4.26), controlPoint1: CGPointMake(38.68, 2.5), controlPoint2: CGPointMake(36.03, 3.09))
Expand All @@ -605,7 +605,7 @@ class SCLAlertViewStyleKit : NSObject {
let color0 = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)

// Info Shape Drawing
var infoShapePath = UIBezierPath()
let infoShapePath = UIBezierPath()
infoShapePath.moveToPoint(CGPointMake(45.66, 15.96))
infoShapePath.addCurveToPoint(CGPointMake(45.66, 5.22), controlPoint1: CGPointMake(48.78, 12.99), controlPoint2: CGPointMake(48.78, 8.19))
infoShapePath.addCurveToPoint(CGPointMake(34.34, 5.22), controlPoint1: CGPointMake(42.53, 2.26), controlPoint2: CGPointMake(37.47, 2.26))
Expand All @@ -631,7 +631,7 @@ class SCLAlertViewStyleKit : NSObject {
let color = UIColor(red:1.0, green:1.0, blue:1.0, alpha:1.0)

// Edit shape Drawing
var editPathPath = UIBezierPath()
let editPathPath = UIBezierPath()
editPathPath.moveToPoint(CGPointMake(71, 2.7))
editPathPath.addCurveToPoint(CGPointMake(71.9, 15.2), controlPoint1: CGPointMake(74.7, 5.9), controlPoint2: CGPointMake(75.1, 11.6))
editPathPath.addLineToPoint(CGPointMake(64.5, 23.7))
Expand Down
8 changes: 4 additions & 4 deletions Example/SCLAlertViewExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ViewController: UIViewController {
let alert = SCLAlertView()
alert.addButton("First Button", target:self, selector:Selector("firstButton"))
alert.addButton("Second Button") {
println("Second button tapped")
print("Second button tapped")
}
alert.showSuccess(kSuccessTitle, subTitle: kSubtitle)
}
Expand All @@ -58,14 +58,14 @@ class ViewController: UIViewController {

@IBAction func showEdit(sender: AnyObject) {
let alert = SCLAlertView()
let txt = alert.addTextField(title:"Enter your name")
let txt = alert.addTextField("Enter your name")
alert.addButton("Show Name") {
println("Text value: \(txt.text)")
print("Text value: \(txt.text)")
}
alert.showEdit(kInfoTitle, subTitle:kSubtitle)
}

func firstButton() {
println("First button tapped")
print("First button tapped")
}
}
2 changes: 1 addition & 1 deletion Example/SCLAlertViewExampleTests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
Binary file not shown.
Loading

0 comments on commit 4a514b2

Please sign in to comment.