Skip to content

Commit

Permalink
support Swift 2.0 now
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlui committed Sep 12, 2015
1 parent 48b325c commit 0b8728b
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 49 deletions.
40 changes: 20 additions & 20 deletions SwiftColors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extension SWColor {
Create non-autoreleased color with in the given hex string
Alpha will be set as 1 by default

:param: hexString
:returns: color with the given hex string
- parameter hexString:
- returns: color with the given hex string
*/
convenience init?(hexString: String) {
self.init(hexString: hexString, alpha: 1.0)
Expand All @@ -43,32 +43,32 @@ extension SWColor {
/**
Create non-autoreleased color with in the given hex string and alpha

:param: hexString
:param: alpha
:returns: color with the given hex string and alpha
- parameter hexString:
- parameter alpha:
- returns: color with the given hex string and alpha
*/
convenience init?(hexString: String, alpha: Float) {
var hex = hexString

// Check for hash and remove the hash
if hex.hasPrefix("#") {
hex = hex.substringFromIndex(advance(hex.startIndex, 1))
hex = hex.substringFromIndex(hex.startIndex.advancedBy(1))
}

if let match = hex.rangeOfString("(^[0-9A-Fa-f]{6}$)|(^[0-9A-Fa-f]{3}$)", options: .RegularExpressionSearch) {
if let _ = hex.rangeOfString("(^[0-9A-Fa-f]{6}$)|(^[0-9A-Fa-f]{3}$)", options: .RegularExpressionSearch) {

// Deal with 3 character Hex strings
if count(hex) == 3 {
var redHex = hex.substringToIndex(advance(hex.startIndex, 1))
var greenHex = hex.substringWithRange(Range<String.Index>(start: advance(hex.startIndex, 1), end: advance(hex.startIndex, 2)))
var blueHex = hex.substringFromIndex(advance(hex.startIndex, 2))
if hex.characters.count == 3 {
let redHex = hex.substringToIndex(hex.startIndex.advancedBy(1))
let greenHex = hex.substringWithRange(Range<String.Index>(start: hex.startIndex.advancedBy(1), end: hex.startIndex.advancedBy(2)))
let blueHex = hex.substringFromIndex(hex.startIndex.advancedBy(2))

hex = redHex + redHex + greenHex + greenHex + blueHex + blueHex
}

let redHex = hex.substringToIndex(advance(hex.startIndex, 2))
let greenHex = hex.substringWithRange(Range<String.Index>(start: advance(hex.startIndex, 2), end: advance(hex.startIndex, 4)))
let blueHex = hex.substringWithRange(Range<String.Index>(start: advance(hex.startIndex, 4), end: advance(hex.startIndex, 6)))
let redHex = hex.substringToIndex(hex.startIndex.advancedBy(2))
let greenHex = hex.substringWithRange(Range<String.Index>(start: hex.startIndex.advancedBy(2), end: hex.startIndex.advancedBy(4)))
let blueHex = hex.substringWithRange(Range<String.Index>(start: hex.startIndex.advancedBy(4), end: hex.startIndex.advancedBy(6)))

var redInt: CUnsignedInt = 0
var greenInt: CUnsignedInt = 0
Expand All @@ -94,8 +94,8 @@ extension SWColor {
Create non-autoreleased color with in the given hex value
Alpha will be set as 1 by default

:param: hex
:returns: color with the given hex value
- parameter hex:
- returns: color with the given hex value
*/
convenience init?(hex: Int) {
self.init(hex: hex, alpha: 1.0)
Expand All @@ -104,12 +104,12 @@ extension SWColor {
/**
Create non-autoreleased color with in the given hex value and alpha

:param: hex
:param: alpha
:returns: color with the given hex value and alpha
- parameter hex:
- parameter alpha:
- returns: color with the given hex value and alpha
*/
convenience init?(hex: Int, alpha: Float) {
var hexString = NSString(format: "%2X", hex)
let hexString = NSString(format: "%2X", hex)
self.init(hexString: hexString as String, alpha: alpha)
}
}
9 changes: 8 additions & 1 deletion SwiftSideslipLikeQQ.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@
465932FD1AD7F60700969878 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0630;
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0700;
ORGANIZATIONNAME = com.lvwenhan;
TargetAttributes = {
465933041AD7F60700969878 = {
Expand Down Expand Up @@ -308,6 +310,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -375,6 +378,7 @@
INFOPLIST_FILE = SwiftSideslipLikeQQ/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -386,6 +390,7 @@
INFOPLIST_FILE = SwiftSideslipLikeQQ/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -404,6 +409,7 @@
);
INFOPLIST_FILE = SwiftSideslipLikeQQTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftSideslipLikeQQ.app/SwiftSideslipLikeQQ";
};
Expand All @@ -419,6 +425,7 @@
);
INFOPLIST_FILE = SwiftSideslipLikeQQTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "com.lvwenhan.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftSideslipLikeQQ.app/SwiftSideslipLikeQQ";
};
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 = "465933041AD7F60700969878"
BuildableName = "SwiftSideslipLikeQQ.app"
BlueprintName = "SwiftSideslipLikeQQ"
ReferencedContainer = "container:SwiftSideslipLikeQQ.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 = "465933191AD7F60700969878"
BuildableName = "SwiftSideslipLikeQQTests.xctest"
BlueprintName = "SwiftSideslipLikeQQTests"
ReferencedContainer = "container:SwiftSideslipLikeQQ.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "465933041AD7F60700969878"
BuildableName = "SwiftSideslipLikeQQ.app"
BlueprintName = "SwiftSideslipLikeQQ"
ReferencedContainer = "container:SwiftSideslipLikeQQ.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 = "465933041AD7F60700969878"
BuildableName = "SwiftSideslipLikeQQ.app"
BlueprintName = "SwiftSideslipLikeQQ"
ReferencedContainer = "container:SwiftSideslipLikeQQ.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "465933041AD7F60700969878"
BuildableName = "SwiftSideslipLikeQQ.app"
BlueprintName = "SwiftSideslipLikeQQ"
ReferencedContainer = "container:SwiftSideslipLikeQQ.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>SwiftSideslipLikeQQ.xcscheme</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>465933041AD7F60700969878</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>465933191AD7F60700969878</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
2 changes: 1 addition & 1 deletion SwiftSideslipLikeQQ/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
application.statusBarStyle = UIStatusBarStyle.LightContent

// 改变 navigation bar 的背景色
var navigationBarAppearace = UINavigationBar.appearance()
let navigationBarAppearace = UINavigationBar.appearance()
navigationBarAppearace.translucent = false
navigationBarAppearace.barTintColor = UIColor(hex: 0x25b6ed)

Expand Down
5 changes: 3 additions & 2 deletions SwiftSideslipLikeQQ/Base.lproj/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8154"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
Expand Down
Loading

0 comments on commit 0b8728b

Please sign in to comment.