Skip to content

Commit

Permalink
Added first double extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
Esqarrouth committed Dec 19, 2015
1 parent 9bc51ba commit cafc537
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 26 deletions.
2 changes: 1 addition & 1 deletion EZSwiftExtensions.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "EZSwiftExtensions"
s.version = "0.9"
s.version = "1.0"
s.summary = ":smirk: How Swift standard types and classes were supposed to work"
s.description = ":smirk: How Swift standard types and classes were supposed to work."
s.homepage = "https://github.com/goktugyil/EZSwiftExtensions"
Expand Down
17 changes: 17 additions & 0 deletions EZSwiftExtensions/DoubleExtensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// DoubleExtensions.swift
// EZSwiftExtensionsExample
//
// Created by Goktug Yilmaz on 12/19/15.
// Copyright © 2015 Goktug Yilmaz. All rights reserved.
//

import UIKit

extension Double {
/// EZSwiftExtensions
public var toString: String { return String(self) }
/// EZSwiftExtensions
public var toInt: Int { return Int(self) }
}

2 changes: 2 additions & 0 deletions EZSwiftExtensions/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiresFullScreen</key>
<true/>
</dict>
</plist>
4 changes: 4 additions & 0 deletions EZSwiftExtensionsExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
E1839E371BF79974002212C6 /* UITextViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1839E1B1BF79974002212C6 /* UITextViewExtensions.swift */; };
E1839E381BF79974002212C6 /* UIViewControllerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1839E1C1BF79974002212C6 /* UIViewControllerExtensions.swift */; };
E1839E391BF79974002212C6 /* UIViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1839E1D1BF79974002212C6 /* UIViewExtensions.swift */; };
E1CB3C1A1C25FB3500DF77CD /* DoubleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1CB3C191C25FB3500DF77CD /* DoubleExtensions.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand Down Expand Up @@ -78,6 +79,7 @@
E1839E1B1BF79974002212C6 /* UITextViewExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UITextViewExtensions.swift; path = Sources/UITextViewExtensions.swift; sourceTree = SOURCE_ROOT; };
E1839E1C1BF79974002212C6 /* UIViewControllerExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIViewControllerExtensions.swift; path = Sources/UIViewControllerExtensions.swift; sourceTree = SOURCE_ROOT; };
E1839E1D1BF79974002212C6 /* UIViewExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = UIViewExtensions.swift; path = Sources/UIViewExtensions.swift; sourceTree = SOURCE_ROOT; };
E1CB3C191C25FB3500DF77CD /* DoubleExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DoubleExtensions.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -106,6 +108,7 @@
E1839E0B1BF79974002212C6 /* CGFloatExtensions.swift */,
E1839E0C1BF79974002212C6 /* CGRectExtensions.swift */,
E1839E0D1BF79974002212C6 /* DictionaryExtensions.swift */,
E1CB3C191C25FB3500DF77CD /* DoubleExtensions.swift */,
E1839E0E1BF79974002212C6 /* EZSwiftExtensions.swift */,
E1839E0F1BF79974002212C6 /* IntExtentions.swift */,
E1839E101BF79974002212C6 /* NSDateExtensions.swift */,
Expand Down Expand Up @@ -249,6 +252,7 @@
E1839E331BF79974002212C6 /* UIFontExtensions.swift in Sources */,
E1839E261BF79974002212C6 /* BoolExtentions.swift in Sources */,
E1839E2B1BF79974002212C6 /* IntExtentions.swift in Sources */,
E1CB3C1A1C25FB3500DF77CD /* DoubleExtensions.swift in Sources */,
E1839E341BF79974002212C6 /* UIImageExtensions.swift in Sources */,
E1839E241BF79974002212C6 /* BlockTap.swift in Sources */,
E1839E1F1BF79974002212C6 /* BlockButton.swift in Sources */,
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,17 @@ var myFloat = myInt.toFloat
var myCGFloat = myInt.toCGFloat
var myString = myInt.toString
```

##Double Extensions

Easily convert between different types:

``` swift
var myString = "33.3"
var myDouble = myString.toString
var myInt = myDouble.toInt
```

##String Extensions

Easily access with subscripts:
Expand Down
51 changes: 26 additions & 25 deletions Sources/EZSwiftExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@ import UIKit
//TODO: others standart video, gif

public struct ez {

/// EZSwift Extensions
public static var appDisplayName: String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleDisplayName") as? String
?? NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleName") as! String
}

/// EZSwift Extensions
public static var appVersion: String {
return NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as! String
}

/// EZSwiftExtensions
public static var appBuild: String {
return NSBundle.mainBundle().objectForInfoDictionaryKey(kCFBundleVersionKey as String) as! String
}

/// EZSwiftExtensions
public static var appVersionAndBuild: String {
let version = appVersion, build = appBuild
return version == build ? "v\(version)" : "v\(version)(\(build))"
}

/// EZSwiftExtensions - Gives you the VC on top so you can easily push your popups
public static var topMostVC: UIViewController? {
var presentedVC = UIApplication.sharedApplication().keyWindow?.rootViewController
while let pVC = presentedVC?.presentedViewController {
presentedVC = pVC
}

if presentedVC == nil {
print("EZSwiftExtensions Error: You don't have any views set. You may be calling them in viewDidLoad. Try viewDidAppear instead.")
}
return presentedVC
}

/// EZSwiftExtensions
public static var screenOrientation: UIInterfaceOrientation {
return UIApplication.sharedApplication().statusBarOrientation
}

/// EZSwiftExtensions
public static var screenWidth: CGFloat {
if UIInterfaceOrientationIsPortrait(screenOrientation) {
Expand All @@ -59,7 +59,7 @@ public struct ez {
return UIScreen.mainScreen().bounds.size.height
}
}

/// EZSwiftExtensions
public static var screenHeight: CGFloat {
if UIInterfaceOrientationIsPortrait(screenOrientation) {
Expand All @@ -68,12 +68,12 @@ public struct ez {
return UIScreen.mainScreen().bounds.size.width
}
}

/// EZSwiftExtensions
public static var screenStatusBarHeight: CGFloat {
return UIApplication.sharedApplication().statusBarFrame.height
}

/// EZSwiftExtensions
public static var screenHeightWithoutStatusBar: CGFloat {
if UIInterfaceOrientationIsPortrait(screenOrientation) {
Expand All @@ -82,7 +82,7 @@ public struct ez {
return UIScreen.mainScreen().bounds.size.width - screenStatusBarHeight
}
}

/// EZSwiftExtensions - Calls action when a screen shot is taken
public static func detectScreenShot(action: () -> ()) {
let mainQueue = NSOperationQueue.mainQueue()
Expand All @@ -91,40 +91,40 @@ public struct ez {
action()
}
}

// MARK: - Dispatch

/// EZSwiftExtensions
public static func runThisMany(times times: Int, block: () -> ()) {
for _ in 0..<times {
block()
}
}

/// EZSwiftExtensions
public static func runThisAfterDelay(seconds seconds: Double, after: () -> ()) {
runThisAfterDelay(seconds: seconds, queue: dispatch_get_main_queue(), after: after)
}

//TODO: Make this easier
/// EZSwiftExtensions - dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0)
public static func runThisAfterDelay(seconds seconds: Double, queue: dispatch_queue_t, after: ()->()) {
let time = dispatch_time(DISPATCH_TIME_NOW, Int64(seconds * Double(NSEC_PER_SEC)))
dispatch_after(time, queue, after)
}

/// EZSwiftExtensions - Submits a block for asynchronous execution on the main queue
public static func runThisInMainThread(block: dispatch_block_t) {
dispatch_async(dispatch_get_main_queue(), block)
}

/// EZSwiftExtensions - Runs in Default priority queue
public static func runThisInBackground(block: () -> ()) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
}

// MARK: - DownloadTask

/// EZSwiftExtensions
public static func requestImage(url: String, success: (UIImage?) -> Void) {
requestURL(url, success: { (data) -> Void in
Expand All @@ -133,7 +133,7 @@ public struct ez {
}
})
}

/// EZSwiftExtensions
public static func requestJSON(url: String, success: (AnyObject? -> Void), error: ((NSError) -> Void)?) {
requestURL(url,
Expand All @@ -147,7 +147,7 @@ public struct ez {
}
})
}

/// EZSwiftExtensions
private static func dataToJsonDict(data: NSData?) -> AnyObject? {
if let d = data {
Expand All @@ -161,7 +161,7 @@ public struct ez {
error = error1
json = nil
}

if let _ = error {
return nil
} else {
Expand All @@ -171,9 +171,10 @@ public struct ez {
return nil
}
}

/// EZSwiftExtensions
private static func requestURL(url: String, success: (NSData?) -> Void, error: ((NSError) -> Void)? = nil) {
//TODO: Seems this is depreceated, update it
NSURLConnection.sendAsynchronousRequest(
NSURLRequest(URL: NSURL (string: url)!),
queue: NSOperationQueue.mainQueue(),
Expand All @@ -185,5 +186,5 @@ public struct ez {
}
})
}

}

0 comments on commit cafc537

Please sign in to comment.