Giter Site home page Giter Site logo

wtkit's Introduction

WTKit

Build Status

Swift Extensions

Foundation Extensions

  • WTPrint
//this method only print at debug mode
WTPrint("wt print \(self)")
//AppDelegate.swift[19], application(_:didFinishLaunchingWithOptions:) wt print <WTKit.AppDelegate: 0x7fde38509d80>

DEBUGBlock { 
            //code will run at debug mode
        }
//note: Build Settings -> Other Swift Flags -> Debug -> -D DEBUG
  • NSObject
  • NSData
//parse json
public func jsonValue()->(AnyObject?,NSError?)

let json = data?.jsonValue()
let jsonObject:AnyObject? = json?.0
print(json?.0)
let error:NSError? = json?.1
print(json?.1)


//parse json
public func parseJSON(block:(AnyObject,NSError?)->Void)
data?.parseJSON({ (obj, error) in
            print(obj)
            print(error)
        })
  • NSURLSession
//create a request and start 
//optional parameters: method,parameters,headers
NSURLSession.dataTaskWith("url", completionHandler: { (data, response, error) in
                
            })
  • NSURLRequest
//create a request instance
//optional parameters: method,parameters,headers
let request:NSMutableURLRequest? = NSURLRequest.request("url", method: "GET", parameters: nil)
  • NSOperationQueue
NSOperationQueue.globalQueue { 
            print("current is  global queue")
        }
NSOperationQueue.gotoMainQueue { 
            print("current is main queue")
        }
NSOperationQueue.userInteractive { 
            print("current queue is global queue priority : userInteractive")
        }
NSOperationQueue.background { 
            print("current queue is global queue priority : background")
        }
  • String
let string = "swift"
print(string.length)//5
  • NSDate
// Get just one calendar unit value
public func numberFor(unit:NSCalendarUnit)->Int


let date = NSDate()
print("year:  \(date.numberFor(.Year)) month:\(date.numberFor(.Month)) day:\(date.numberFor(.Month))")
        

UIKit Extensions

  • UIColor
UIColor.colorWithHexString("#3")//result is #333333
UIColor.colorWithHexString("333333")//result is #333333
UIColor.colorWithHexString("#333333")//result is #333333
UIColor.colorWithHexString("ff0000",alpha: 0.5)//red colour with alpha : 0.5
  • UIApplication
//build version
UIApplication.buildVersion()
//app version
let appVersion:String = UIApplication.appVersion()
//documents path
let docPath:String = UIApplication.documentsPath()


//record current version
//note:call this method at application did finish launching
UIApplication.track()

//check current version is first launch ever
if UIApplication.sharedApplication().isFirstLaunchEver {
            print("is first launch for build")
        }else{
            print("not first launch for build")
        }
  • UIButton
// request image from internet(address is url),the set the image for the state,
// the place holder will be the default image
requestButton.setImageWith("url", forState: .Normal,placeHolder: nil)
  • UIImage
// create a rounded corner image for reciver
let image:UIImage = (self.imageView.image?.imageWithRoundCornerRadius(30))
  • UIImageView
//set image with a url
imageView.setImageWith("url")

//set hight lighted image with a url,and set a place holder image
imageView.sethighlightedImageWith("url", placeHolder: placeHolderImage)
  • UIViewController
//show loading activity indicator
self.showLoadingView()

//hide loading activity indicator 
self.hideLoadingView()
  • UIView
let image:UIImage = self.view.snapShot()//get a snap shot image
let pdf:NSData = self.view.pdf()//get a pdf shot 
  • UIScrollView || UITableView
//pull to refresh(very useful)
self.tableView.refreshHeader = RefreshHeader.headerWithRefreshing({ 
            printf("refresh data from internet")
        })
        
//finish refresh        
self.tableView.finishRefresh()
  • CALayer
//create snapshot
let image:UIImage =  self.view.layer.snapShot()
//pause layer animation
self.view.layer.pauseAnimation()
//resume layer animation
self.view.layer.resumeAnimation()

wtkit's People

Contributors

songwentong avatar

Watchers

James Cloos avatar zhangmeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.