Skip to content

Commit

Permalink
Create project
Browse files Browse the repository at this point in the history
  • Loading branch information
corin8823 committed Aug 2, 2015
1 parent 37e65e1 commit 5b66a87
Show file tree
Hide file tree
Showing 16 changed files with 583 additions and 27 deletions.
28 changes: 28 additions & 0 deletions .gitignore
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/*
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
language: objective-c
osx_image: xcode6.4
10 changes: 10 additions & 0 deletions README.md
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"
```
50 changes: 47 additions & 3 deletions SwiftyExtensions.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
015B5AE91B6DD8DB0087F4D3 /* SwiftyExtensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 015B5AE81B6DD8DB0087F4D3 /* SwiftyExtensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
015B5AEF1B6DD8DB0087F4D3 /* SwiftyExtensions.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 015B5AE31B6DD8DB0087F4D3 /* SwiftyExtensions.framework */; };
015B5AF61B6DD8DB0087F4D3 /* SwiftyExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5AF51B6DD8DB0087F4D3 /* SwiftyExtensionsTests.swift */; };
015B5B081B6DD9BF0087F4D3 /* NSMutableAttributedString+Addtions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5AFF1B6DD9BF0087F4D3 /* NSMutableAttributedString+Addtions.swift */; };
015B5B0A1B6DD9BF0087F4D3 /* String+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B011B6DD9BF0087F4D3 /* String+Extension.swift */; };
015B5B0B1B6DD9BF0087F4D3 /* Swift+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B021B6DD9BF0087F4D3 /* Swift+Extensions.swift */; };
015B5B0C1B6DD9BF0087F4D3 /* UIColor+Hex.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B031B6DD9BF0087F4D3 /* UIColor+Hex.swift */; };
015B5B0D1B6DD9BF0087F4D3 /* UIImage+Additions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B041B6DD9BF0087F4D3 /* UIImage+Additions.swift */; };
015B5B0E1B6DD9BF0087F4D3 /* UIImageView+Addtions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B051B6DD9BF0087F4D3 /* UIImageView+Addtions.swift */; };
015B5B0F1B6DD9BF0087F4D3 /* UIView+Addtions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B061B6DD9BF0087F4D3 /* UIView+Addtions.swift */; };
015B5B141B6DDAF10087F4D3 /* UICollectionView+Register.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B111B6DDAF10087F4D3 /* UICollectionView+Register.swift */; };
015B5B151B6DDAF10087F4D3 /* UITableView+Register.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B121B6DDAF10087F4D3 /* UITableView+Register.swift */; };
015B5B161B6DDAF10087F4D3 /* UIViewController+UIStoryBoard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 015B5B131B6DDAF10087F4D3 /* UIViewController+UIStoryBoard.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -29,6 +39,16 @@
015B5AEE1B6DD8DB0087F4D3 /* SwiftyExtensionsTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyExtensionsTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
015B5AF41B6DD8DB0087F4D3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
015B5AF51B6DD8DB0087F4D3 /* SwiftyExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftyExtensionsTests.swift; sourceTree = "<group>"; };
015B5AFF1B6DD9BF0087F4D3 /* NSMutableAttributedString+Addtions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSMutableAttributedString+Addtions.swift"; sourceTree = "<group>"; };
015B5B011B6DD9BF0087F4D3 /* String+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "String+Extension.swift"; sourceTree = "<group>"; };
015B5B021B6DD9BF0087F4D3 /* Swift+Extensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Swift+Extensions.swift"; sourceTree = "<group>"; };
015B5B031B6DD9BF0087F4D3 /* UIColor+Hex.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIColor+Hex.swift"; sourceTree = "<group>"; };
015B5B041B6DD9BF0087F4D3 /* UIImage+Additions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImage+Additions.swift"; sourceTree = "<group>"; };
015B5B051B6DD9BF0087F4D3 /* UIImageView+Addtions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIImageView+Addtions.swift"; sourceTree = "<group>"; };
015B5B061B6DD9BF0087F4D3 /* UIView+Addtions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+Addtions.swift"; sourceTree = "<group>"; };
015B5B111B6DDAF10087F4D3 /* UICollectionView+Register.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UICollectionView+Register.swift"; sourceTree = "<group>"; };
015B5B121B6DDAF10087F4D3 /* UITableView+Register.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITableView+Register.swift"; sourceTree = "<group>"; };
015B5B131B6DDAF10087F4D3 /* UIViewController+UIStoryBoard.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+UIStoryBoard.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -53,9 +73,9 @@
015B5AD91B6DD8DB0087F4D3 = {
isa = PBXGroup;
children = (
015B5AE41B6DD8DB0087F4D3 /* Products */,
015B5AE51B6DD8DB0087F4D3 /* SwiftyExtensions */,
015B5AF21B6DD8DB0087F4D3 /* SwiftyExtensionsTests */,
015B5AE41B6DD8DB0087F4D3 /* Products */,
);
sourceTree = "<group>";
};
Expand All @@ -71,8 +91,18 @@
015B5AE51B6DD8DB0087F4D3 /* SwiftyExtensions */ = {
isa = PBXGroup;
children = (
015B5AE81B6DD8DB0087F4D3 /* SwiftyExtensions.h */,
015B5AE61B6DD8DB0087F4D3 /* Supporting Files */,
015B5AFF1B6DD9BF0087F4D3 /* NSMutableAttributedString+Addtions.swift */,
015B5B011B6DD9BF0087F4D3 /* String+Extension.swift */,
015B5B021B6DD9BF0087F4D3 /* Swift+Extensions.swift */,
015B5AE81B6DD8DB0087F4D3 /* SwiftyExtensions.h */,
015B5B111B6DDAF10087F4D3 /* UICollectionView+Register.swift */,
015B5B031B6DD9BF0087F4D3 /* UIColor+Hex.swift */,
015B5B041B6DD9BF0087F4D3 /* UIImage+Additions.swift */,
015B5B051B6DD9BF0087F4D3 /* UIImageView+Addtions.swift */,
015B5B121B6DDAF10087F4D3 /* UITableView+Register.swift */,
015B5B061B6DD9BF0087F4D3 /* UIView+Addtions.swift */,
015B5B131B6DDAF10087F4D3 /* UIViewController+UIStoryBoard.swift */,
);
path = SwiftyExtensions;
sourceTree = "<group>";
Expand All @@ -88,8 +118,8 @@
015B5AF21B6DD8DB0087F4D3 /* SwiftyExtensionsTests */ = {
isa = PBXGroup;
children = (
015B5AF51B6DD8DB0087F4D3 /* SwiftyExtensionsTests.swift */,
015B5AF31B6DD8DB0087F4D3 /* Supporting Files */,
015B5AF51B6DD8DB0087F4D3 /* SwiftyExtensionsTests.swift */,
);
path = SwiftyExtensionsTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -209,6 +239,16 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
015B5B081B6DD9BF0087F4D3 /* NSMutableAttributedString+Addtions.swift in Sources */,
015B5B0A1B6DD9BF0087F4D3 /* String+Extension.swift in Sources */,
015B5B0B1B6DD9BF0087F4D3 /* Swift+Extensions.swift in Sources */,
015B5B141B6DDAF10087F4D3 /* UICollectionView+Register.swift in Sources */,
015B5B0C1B6DD9BF0087F4D3 /* UIColor+Hex.swift in Sources */,
015B5B0D1B6DD9BF0087F4D3 /* UIImage+Additions.swift in Sources */,
015B5B0E1B6DD9BF0087F4D3 /* UIImageView+Addtions.swift in Sources */,
015B5B151B6DDAF10087F4D3 /* UITableView+Register.swift in Sources */,
015B5B0F1B6DD9BF0087F4D3 /* UIView+Addtions.swift in Sources */,
015B5B161B6DDAF10087F4D3 /* UIViewController+UIStoryBoard.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -329,6 +369,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = SwiftyExtensions/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -344,6 +385,7 @@
DYLIB_INSTALL_NAME_BASE = "@rpath";
INFOPLIST_FILE = SwiftyExtensions/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -399,6 +441,7 @@
015B5AFB1B6DD8DB0087F4D3 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
015B5AFC1B6DD8DB0087F4D3 /* Build configuration list for PBXNativeTarget "SwiftyExtensionsTests" */ = {
isa = XCConfigurationList;
Expand All @@ -407,6 +450,7 @@
015B5AFE1B6DD8DB0087F4D3 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
32 changes: 32 additions & 0 deletions SwiftyExtensions/NSMutableAttributedString+Addtions.swift
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))
}
}
29 changes: 29 additions & 0 deletions SwiftyExtensions/String+Extension.swift
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
}
}
35 changes: 35 additions & 0 deletions SwiftyExtensions/Swift+Extensions.swift
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)
}
2 changes: 1 addition & 1 deletion SwiftyExtensions/SwiftyExtensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SwiftyExtensions.h
// SwiftyExtensions
//
// Created by 髙橋 優介 on 8/2/15.
// Created by yusuke takahashi on 8/2/15.
// Copyright (c) 2015 yusuke takahashi. All rights reserved.
//

Expand Down
28 changes: 28 additions & 0 deletions SwiftyExtensions/UICollectionView+Register.swift
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
}
}
46 changes: 46 additions & 0 deletions SwiftyExtensions/UIColor+Hex.swift
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)
}
}
Loading

0 comments on commit 5b66a87

Please sign in to comment.