-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
583 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Mac | ||
.DS_Store | ||
|
||
# Xcode | ||
# | ||
build/ | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
*.xccheckout | ||
*.moved-aside | ||
DerivedData | ||
*.hmap | ||
*.ipa | ||
*.xcuserstate | ||
|
||
# CocoaPods | ||
Pods/ | ||
|
||
# Carthage | ||
Carthage/Build/* | ||
Carthage/Checkouts/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
language: objective-c | ||
osx_image: xcode6.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
# SwiftyExtensions | ||
A set of Swift extensions | ||
|
||
[![Build Status](https://travis-ci.org/corin8823/SwiftyExtensions.svg)](https://travis-ci.org/corin8823/SwiftyExtensions/) | ||
|
||
## Integration | ||
|
||
### Carthage (iOS 8+) | ||
You can use [Carthage](https://github.com/Carthage/Carthage) to install `SwiftyExtensions` by adding it to your `Cartfile` | ||
``` | ||
github "corin8823/SwiftyExtensions" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// NSMutableAttributedString+Addtions.swift | ||
// SwiftyExtensions | ||
// | ||
// Created by yusuke takahashi on 8/2/15. | ||
// Copyright (c) 2015 yusuke takahashi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSMutableAttributedString { | ||
|
||
public convenience init(string: String, image: UIImage?, point: CGPoint = CGPointZero, index: Int = 0) { | ||
self.init(string: string) | ||
if let image = image { | ||
var textAttachment = NSTextAttachment() | ||
textAttachment.image = image | ||
textAttachment.bounds = CGRect(origin: point, size: image.size) | ||
let ns = NSAttributedString(attachment: textAttachment) | ||
self.insertAttributedString(ns, atIndex: index) | ||
} | ||
} | ||
|
||
public convenience init(string: String, lineHeight: CGFloat) { | ||
self.init(string: string) | ||
let paragraphStyle = NSMutableParagraphStyle() | ||
paragraphStyle.maximumLineHeight = lineHeight | ||
self.addAttribute(NSParagraphStyleAttributeName, | ||
value: paragraphStyle, | ||
range: NSMakeRange(0, self.length)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// | ||
// String+Extension.swift | ||
// SwiftyExtensions | ||
// | ||
// Created by yusuke takahashi on 8/2/15. | ||
// Copyright (c) 2015 yusuke takahashi. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
extension String { | ||
|
||
public func insert(#string: String, atIndex: Int) -> String { | ||
return prefix(self, atIndex) + string + suffix(self, count(self) - atIndex) | ||
} | ||
|
||
public func trim() -> String { | ||
return self.stringByTrimmingCharactersInSet(.whitespaceAndNewlineCharacterSet()) | ||
} | ||
|
||
public func textHeight(width: CGFloat, font: UIFont) -> CGFloat { | ||
let size = CGSize(width: width, height: CGFloat.max) | ||
|
||
let rect = self.boundingRectWithSize(size, | ||
options: .UsesLineFragmentOrigin | .UsesFontLeading, | ||
attributes: [NSFontAttributeName: font], context: nil) | ||
return rect.size.height | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// | ||
// Swift+Extensions.swift | ||
// SwiftyExtensions | ||
// | ||
// Created by yusuke takahashi on 8/2/15. | ||
// Copyright (c) 2015 yusuke takahashi. All rights reserved. | ||
// | ||
|
||
public func delay(delay: Double, closure:() -> ()) { | ||
dispatch_after( | ||
dispatch_time( DISPATCH_TIME_NOW, | ||
Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), closure) | ||
} | ||
|
||
public func Localized(key: String) -> String { | ||
return NSLocalizedString(key, comment: "") | ||
} | ||
|
||
public func StringFromClass(object: AnyObject) -> String { | ||
return NSStringFromClass(object.dynamicType).componentsSeparatedByString(".").last! | ||
} | ||
|
||
public func LOG( _ body: AnyObject! = "", function: String = __FUNCTION__, line: Int = __LINE__) { | ||
#if DEBUG | ||
println("[\(function) : \(line)] \(body)") | ||
#endif | ||
} | ||
|
||
public func dispatch_async_main(closure: () -> ()) { | ||
dispatch_async(dispatch_get_main_queue(), closure) | ||
} | ||
|
||
public func dispatch_async_global(closure: () -> ()) { | ||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), closure) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// UICollectionView+Register.swift | ||
// SwiftyExtensions | ||
// | ||
// Created by yusuke takahashi on 8/2/15. | ||
// Copyright (c) 2015 yusuke takahashi. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
extension UICollectionView { | ||
|
||
public func registerNibFromClass<T: UICollectionViewCell>(type: T.Type) { | ||
let className = StringFromClass(T) | ||
let nib = UINib(nibName: className, bundle: nil) | ||
registerNib(nib, forCellWithReuseIdentifier: className) | ||
} | ||
|
||
public func registerClassFromClass<T: UICollectionViewCell>(type: T.Type) { | ||
let className = StringFromClass(T) | ||
registerClass(T.self, forCellWithReuseIdentifier: className) | ||
} | ||
|
||
public func dequeueReusableCell<T: UICollectionViewCell>(type: T.Type, | ||
forIndexPath indexPath: NSIndexPath) -> T { | ||
return dequeueReusableCellWithReuseIdentifier(StringFromClass(T), forIndexPath: indexPath) as! T | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// UIColor+Hex.swift | ||
// SwiftyExtensions | ||
// | ||
// Created by yusuke takahashi on 8/2/15. | ||
// Copyright (c) 2015 yusuke takahashi. All rights reserved. | ||
// to see : https://github.com/yeahdongcn/UIColor-Hex-Swift/blob/master/UIColorExtension.swift | ||
// | ||
|
||
import UIKit | ||
|
||
extension UIColor { | ||
|
||
public convenience init(rgba: String, alpha: CGFloat = 1.0) { | ||
var red: CGFloat = 0.0 | ||
var green: CGFloat = 0.0 | ||
var blue: CGFloat = 0.0 | ||
var alpha: CGFloat = alpha | ||
|
||
if rgba.hasPrefix("#") { | ||
let index = advance(rgba.startIndex, 1) | ||
let hex = rgba.substringFromIndex(index) | ||
let scanner = NSScanner(string: hex) | ||
var hexValue: CUnsignedLongLong = 0 | ||
if scanner.scanHexLongLong(&hexValue) { | ||
switch (count(hex)) { | ||
case 3: | ||
red = CGFloat((hexValue & 0xF00) >> 8) / 15.0 | ||
green = CGFloat((hexValue & 0x0F0) >> 4) / 15.0 | ||
blue = CGFloat(hexValue & 0x00F) / 15.0 | ||
case 6: | ||
red = CGFloat((hexValue & 0xFF0000) >> 16) / 255.0 | ||
green = CGFloat((hexValue & 0x00FF00) >> 8) / 255.0 | ||
blue = CGFloat(hexValue & 0x0000FF) / 255.0 | ||
default: | ||
LOG("Invalid RGB string, number of characters after '#' should be either 3 or 6") | ||
} | ||
} else { | ||
LOG("Scan hex error") | ||
} | ||
} else { | ||
LOG("Invalid RGB string, missing '#' as prefix") | ||
} | ||
self.init(red: red, green: green, blue: blue, alpha: alpha) | ||
} | ||
} |
Oops, something went wrong.