swiftTools

String+Exten.swift

//
// String+Exten.swift
// swiftTest
//
// Created by napiao on 15/11/27.
// Copyright © 2015年 JINMARONG. All rights reserved.
// import Foundation
import CoreLocation extension String {
/// 将字符串转换成经纬度
func stringToCLLocationCoordinate2D(separator: String) -> CLLocationCoordinate2D? {
let arr = self.componentsSeparatedByString(separator)
if arr.count != 2 {
return nil
} let latitude: Double = NSString(string: arr[1]).doubleValue
let longitude: Double = NSString(string: arr[0]).doubleValue return CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
} }

UIColor+Exten.swift

//
// ColorHex.swift
// swiftTest
//
// Created by napiao on 15/11/26.
// Copyright © 2015年 JINMARONG. All rights reserved.
// import Foundation extension UIColor { public class func colorWithHexString (hex:String) -> UIColor {
var cString:String
= hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString if (cString.hasPrefix("#")){
cString = cString.substringFromIndex(cString.startIndex.advancedBy(1))
} if (cString.characters.count != 6) {
return UIColor.grayColor()
} var rString = cString.substringToIndex(cString.startIndex.advancedBy(2)) var gString = cString.substringFromIndex(cString.startIndex.advancedBy(2)).substringToIndex(cString.startIndex.advancedBy(3)) var bString = cString.substringFromIndex(cString.startIndex.advancedBy(4)).substringToIndex(cString.startIndex.advancedBy(2)) var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0; NSScanner.init(string: rString).scanHexInt(&r) NSScanner.init(string: gString).scanHexInt(&g) NSScanner.init(string: bString).scanHexInt(&b) return UIColor(red:CGFloat(r)/CGFloat(255.0), green:CGFloat(g)/CGFloat(255.0), blue:CGFloat(b)/CGFloat(255.0), alpha:CGFloat(1)) } class func colorWith(red: Int, green: Int, blue: Int, alpha: CGFloat) -> UIColor {
let color = UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: alpha)
return color
} }

UIImage+Exten.swift

//
// UIImage+Name.swift
// swiftTest
//
// Created by napiao on 15/11/27.
// Copyright © 2015年 JINMARONG. All rights reserved.
// import Foundation extension UIImage { static func addRoundedRectToPath(context:CGContextRef, rect:CGRect, ovalWidth:CGFloat,
ovalHeight:CGFloat)
{
let fw:CGFloat, fh:CGFloat; if (ovalWidth == 0 || ovalHeight == 0)
{
CGContextAddRect(context, rect)
return
} CGContextSaveGState(context)
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect))
CGContextScaleCTM(context, ovalWidth, ovalHeight)
fw = CGRectGetWidth(rect) / ovalWidth
fh = CGRectGetHeight(rect) / ovalHeight CGContextMoveToPoint(context, fw, fh/2); // Start at lower right corner
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // Top right corner
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1); // Top left corner
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1); // Lower left corner
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // Back to lower right CGContextClosePath(context)
CGContextRestoreGState(context)
} // 圆角图片的生成 class func creatRoundedRectImage(image:UIImage, size:CGSize, radius:CGFloat)-> UIImage {
let w = Int(size.width)
let h = Int(size.height)
var img = image let colorSpace:CGColorSpaceRef = CGColorSpaceCreateDeviceRGB()!;
let bitmapInfo = CGBitmapInfo(rawValue:CGImageAlphaInfo.PremultipliedFirst.rawValue)
var a:Void
let context:CGContextRef = CGBitmapContextCreate(&a, w, h, 8, 4 * w, colorSpace, bitmapInfo.rawValue)!;
let rect = CGRectMake(0, 0,CGFloat(w), CGFloat(h)); CGContextBeginPath(context)
self.addRoundedRectToPath(context, rect: rect, ovalWidth: radius, ovalHeight: radius)
CGContextClosePath(context)
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, CGFloat(w), CGFloat(h)), img.CGImage)
let imageMasked:CGImageRef = CGBitmapContextCreateImage(context)!
img = UIImage(CGImage:imageMasked)
return img;
} // 根据颜色生成图片
class func createImageWithColor(color:UIColor)->UIImage {
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)
UIGraphicsBeginImageContext(rect.size);
let context:CGContextRef = UIGraphicsGetCurrentContext()!
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
let theImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext();
return theImage;
} // 图片拉伸
class func resizedImageWithName(name:String!, left:Float, right:Float)->UIImage {
let image = UIImage(named: name)!
return (image.stretchableImageWithLeftCapWidth(Int(Float((image.size.width)) * left), topCapHeight:Int(Float((image.size.height)) * right)))
} // 图片中间拉伸
class func resizedImageWithName(name:String)->UIImage {
return self.resizedImageWithName(name, left: 0.5, right: 0.5)
} // 图片的缩放
func transformWidth(width:CGFloat,height:CGFloat)->UIImage {
let destW = width
let destH = height
let sourceW = width
let sourceH = height let imageRef:CGImageRef = self.CGImage!
let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue | CGBitmapInfo.ByteOrder32Little.rawValue)
var tempa:Void
let bitmap:CGContextRef = CGBitmapContextCreate(&tempa,Int(destW), Int(destH), CGImageGetBitsPerComponent(imageRef),Int(4*destW),CGImageGetColorSpace(imageRef), bitmapInfo.rawValue)! CGContextDrawImage(bitmap, CGRectMake(0, 0, sourceW, sourceH), imageRef) let ref:CGImageRef = CGBitmapContextCreateImage(bitmap)!
let resultImage:UIImage = UIImage(CGImage: ref)
return resultImage;
} /// 按尺寸裁剪图片大小
class func imageClipToNewImage(image: UIImage, newSize: CGSize) -> UIImage {
UIGraphicsBeginImageContext(newSize)
image.drawInRect(CGRect(origin: CGPointZero, size: newSize))
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage
} /// 将传入的图片裁剪成带边缘的原型图片
class func imageWithClipImage(image: UIImage, borderWidth: CGFloat, borderColor: UIColor) -> UIImage {
let imageWH = image.size.width
// let border = borderWidth
let ovalWH = imageWH + 2 * borderWidth UIGraphicsBeginImageContextWithOptions(CGSizeMake(ovalWH, ovalWH), false, 0)
let path = UIBezierPath(ovalInRect: CGRectMake(0, 0, ovalWH, ovalWH))
borderColor.set()
path.fill() let clipPath = UIBezierPath(ovalInRect: CGRectMake(borderWidth, borderWidth, imageWH, imageWH))
clipPath.addClip()
image.drawAtPoint(CGPointMake(borderWidth, borderWidth)) let clipImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext() return clipImage
} /// 将传入的图片裁剪成圆形图片
func imageClipOvalImage() -> UIImage {
UIGraphicsBeginImageContextWithOptions(self.size, false, 0.0)
let ctx = UIGraphicsGetCurrentContext()
let rect = CGRectMake(0, 0, self.size.width, self.size.height)
CGContextAddEllipseInRect(ctx, rect) CGContextClip(ctx)
self.drawInRect(rect) let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
} func imageByApplyingAlpha(alpha:CGFloat)-> UIImage {
UIGraphicsBeginImageContextWithOptions(self.size, false, 0.0) let ctx:CGContextRef = UIGraphicsGetCurrentContext()!
let area:CGRect = CGRectMake(0, 0, self.size.width, self.size.height); CGContextScaleCTM(ctx, 1, -1);
CGContextTranslateCTM(ctx, 0, -area.size.height); CGContextSetBlendMode(ctx, CGBlendMode.Multiply); CGContextSetAlpha(ctx, alpha); CGContextDrawImage(ctx, area, self.CGImage); let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return newImage
} // 图片的旋转
func imageRotatedByDegrees(degrees:CGFloat)-> UIImage {
let width = CGImageGetWidth(self.CGImage);
let height = CGImageGetHeight(self.CGImage); var rotatedSize = CGSize() rotatedSize.width = CGFloat(width);
rotatedSize.height = CGFloat(height); UIGraphicsBeginImageContext(rotatedSize);
let bitmap:CGContextRef = UIGraphicsGetCurrentContext()!
CGContextTranslateCTM(bitmap, rotatedSize.width/2, rotatedSize.height/2);
CGContextRotateCTM(bitmap, degrees * CGFloat(M_PI) / 180);
CGContextRotateCTM(bitmap,CGFloat(M_PI));
CGContextScaleCTM(bitmap, -1.0, 1.0);
CGContextDrawImage(bitmap, CGRectMake(-rotatedSize.width/2, -rotatedSize.height/2, rotatedSize.width, rotatedSize.height), self.CGImage);
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage; } }

UserIDCard.swift

//
// UserIDCard.swift
// swiftTest
//
// Created by napiao on 15/11/25.
// Copyright © 2015年 JINMARONG. All rights reserved.
// 根据身份正获取信息 import Foundation class UserIDCard{ // 获取年
class func obtainYearWith(IDCard:String) ->String {
var newIDCard = IDCard
if self.validate18PaperId(IDCard) {
if IDCard.characters.count == 15 {
newIDCard = self .exchange15IDCardTo18IDCard(IDCard)
}
return self .getStringWithRange(newIDCard, value1: 6, value2: 4)
}
return ""
} //获取月
class func obtainMonthWith(IDCard:String) ->String {
var newIDCard = IDCard
if self.validate18PaperId(IDCard) {
if IDCard.characters.count == 15 {
newIDCard = self .exchange15IDCardTo18IDCard(IDCard)
}
return self .getStringWithRange(newIDCard, value1: 10, value2: 2)
}
return ""
} // 获取日
class func obtainDayWith(IDCard:String) ->String {
var newIDCard = IDCard
if self.validate18PaperId(IDCard) {
if IDCard.characters.count == 15 {
newIDCard = self .exchange15IDCardTo18IDCard(IDCard)
}
return self.getStringWithRange(newIDCard, value1: 12, value2: 2)
}
return ""
} //获取生日
class func obtainBirthdayWith(IDCard:String)->String {
var newIDCard = IDCard
if self.validate18PaperId(IDCard) {
if IDCard.characters.count == 15 {
newIDCard = self .exchange15IDCardTo18IDCard(IDCard)
}
return self.getStringWithRange(newIDCard, value1: 6, value2: 4)+"-"+self.getStringWithRange(newIDCard, value1: 10, value2: 2)+"-"+self.getStringWithRange(newIDCard, value1: 12, value2: 2)
}
return ""
} //获取年龄
class func obtainAgeWith(IDCard:String)->String {
let IDCardYear: Int = Int(self.obtainYearWith(IDCard))!
let IDCardMonth:Int = Int(self.obtainMonthWith(IDCard))!
let IDCardDay:Int = Int(self.obtainDayWith(IDCard))! var iAge = 0 let now = NSDate() let cal = NSCalendar.currentCalendar() let unitFlags:NSCalendarUnit = [NSCalendarUnit.Year,NSCalendarUnit.Month,NSCalendarUnit.Day, NSCalendarUnit.Hour,NSCalendarUnit.Minute , NSCalendarUnit.Second] let dateComponents:NSDateComponents = cal.components(unitFlags, fromDate: now)
let y = dateComponents.year
let m = dateComponents.month
let d = dateComponents.day if let IDyear:Int = IDCardYear, let IDMonth:Int = IDCardMonth, let IDDay:Int = IDCardDay {
if y > IDyear {
iAge += y - IDyear - 1 if m > IDMonth {
++iAge
} else if m == IDMonth{
if d >= IDDay {
++iAge
}
}
}
}
return String(iAge)
} // 获取性别
class func obtainSexWith(IDCard:String)->String {
var newIDCard = IDCard
if self.validate18PaperId(IDCard) {
if IDCard.characters.count == 15 {
newIDCard = self.exchange15IDCardTo18IDCard(IDCard)
}
let a = self.getStringWithRange(newIDCard, value1: 14, value2: 3) if a == "1" {
return "男"
} else {
return "女"
}
}
return ""
} //15位身份证转为18位身份证
private class func exchange15IDCardTo18IDCard(IDCard:String)->String {
var carid:String = IDCard // 加权因子
let R:[Int] = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]
// 校验码
let sChecker:[String] = ["1","0", "X" , "9", "8", "7", "6", "5", "4", "3","2" ] var mString:String = IDCard if IDCard.characters.count == 15 {
mString.insert(Character.init("1"), atIndex: mString.startIndex.advancedBy(6))
mString.insert(Character.init("9"), atIndex: mString.startIndex.advancedBy(7)) var p = 0 let pid = (mString as NSString).UTF8String for i in 0...16 {
p += (pid[i]-48)*R[i]
} let o:Int = p%11 let string_content = String(format: "%@", sChecker[o]) mString.insert(Character.init(string_content), atIndex: mString.endIndex.advancedBy(0)) carid = mString
}
return carid;
} // 验证身份证是否合法
private class func validate18PaperId(input:String) ->Bool{
if (input.characters.count != 15)&&(input.characters.count != 18) {
return false
} let carid:String = input var lSumQT = 0
// 加权因子
let R:[Int] = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]
// 校验码
let sChecker:[String] = ["1","0", "X" , "9", "8", "7", "6", "5", "4", "3","2" ] var mString:String = input if input.characters.count == 15 {
mString.insert(Character.init("1"), atIndex: mString.startIndex.advancedBy(6))
mString.insert(Character.init("9"), atIndex: mString.startIndex.advancedBy(7)) var p = 0 let pid = (mString as NSString).UTF8String for i in 0...16 {
p += (pid[i]-48)*R[i]
} let o:Int = p%11 let string_content = String(format: "%@", sChecker[o]) mString.insert(Character.init(string_content), atIndex: mString.endIndex.advancedBy(0))
} let sProvince = carid.substringToIndex(carid.startIndex.advancedBy(2)) if !self.areaCode(sProvince) {
return false
} // 判断年月日是否有效
// 年
let strYear = (self.getStringWithRange(carid, value1: 6, value2: 4) as NSString).intValue
// 月
let strMonth = (self.getStringWithRange(carid, value1: 10, value2: 2) as NSString).intValue
// 日
let strDay = (self.getStringWithRange(carid, value1: 12, value2: 2) as NSString).intValue let localZone:NSTimeZone = NSTimeZone.localTimeZone() let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle dateFormatter.timeZone = localZone dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" print(String(format: "%d-%d-%d", strYear,strMonth,strDay)) let data = dateFormatter.dateFromString(String(format: "%d-%d-%d 12:01:01", strYear,strMonth,strDay)) if data == nil {
return false
} let PaperId:UnsafePointer<CChar> = (carid as NSString).UTF8String print(PaperId) if carid.characters.count != 18 {
return false;
}
for i in 0..<18 {
if ((isdigit(Int32(PaperId[i]))).distanceTo(1) != 0 && (!("X".characterAtIndex(0) == UInt16(PaperId[i]) || UnicodeScalar("x").value == UInt32(PaperId[i])) && 17 == i))
{
return false;
}
} for i in 0...16 {
lSumQT += (PaperId[i] - 48) * R[i]
} if (sChecker[lSumQT%11] as NSString).characterAtIndex(0) != UInt16(PaperId[17]) {
return false
}
return true
} // 私有方法 字符串的范围取值
private class func getStringWithRange(str:String,value1:Int,value2:Int)->String{
return (str as NSString).substringWithRange(NSMakeRange(value1, value2))
} // 私有方法 判断是否符合地理编码
private class func areaCode(code:String)->Bool {
var dict = [String:String]()
dict["11"] = "北京"
dict["12"] = "天津"
dict["13"] = "河北"
dict["14"] = "山西"
dict["15"] = "内蒙古"
dict["21"] = "辽宁"
dict["22"] = "吉林"
dict["23"] = "黑龙江"
dict["31"] = "上海"
dict["32"] = "江苏"
dict["33"] = "浙江"
dict["34"] = "安徽"
dict["35"] = "福建"
dict["36"] = "江西"
dict["37"] = "山东"
dict["41"] = "河南"
dict["42"] = "湖北"
dict["43"] = "湖南"
dict["44"] = "广东"
dict["45"] = "广西"
dict["46"] = "海南"
dict["50"] = "重庆"
dict["51"] = "四川"
dict["52"] = "贵州"
dict["53"] = "云南"
dict["54"] = "*"
dict["61"] = "陕西"
dict["62"] = "甘肃"
dict["63"] = "青海"
dict["64"] = "宁夏"
dict["65"] = "*"
dict["71"] = "*"
dict["81"] = "香港"
dict["82"] = "澳门"
dict["91"] = "国外"
if dict[code] == nil {
return false
}
return true
} }

ValidateTool.swift

//
// ValidateTool.swift
// swiftTest
//
// Created by napiao on 15/11/23.
// Copyright © 2015年 JINMARONG. All rights reserved.
// 条件判断 import Foundation class ValidateTool{
// 判读是否纯数字
class func validateNumber(input:String)->Bool {
let pattern:String = "[0-9]+"
return validateFirstMatch(pattern, input: input)
} // 验证是否为非零正整数
class func validatePositiveNumber(input:String)->Bool {
let pattern:String = "^\\+?[1-9][0-9]*$"
return validateFirstMatch(pattern, input: input)
} //验证是否为邮箱
class func validateEmais(input:String)->Bool {
// 两种正则表达
// let pattern:String = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
let pattern:String = "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$"
return validateFirstMatch(pattern, input: input)
} // 验证手机号码
class func validateMobile(input:String)->Bool {
let pattern:String = "^1(3[0-9]|4[57]|5[0-35-9]|8[0-9]|7[06-8])\\d{8}$"
return validateFirstMatch(pattern, input: input)
} // 验证固话
class func validateFixedLine(input:String)->Bool {
let pattern:String = "^(0[0-9]{2,3})-([2-9][0-9]{6,7})+(\\-[0-9]{1,4})?$"
return validateFirstMatch(pattern, input: input)
} // 验证URL
class func validateUrl(input:String)->Bool {
let pattern:String = "\\bhttps?://[a-zA-Z0-9\\-.]+(?::(\\d+))?(?:(?:/[a-zA-Z0-9\\-._?,'+\\&%$=~*!():@\\\\]*)+)?"
return validateNumberMatch(pattern, input: input)
} // 验证身份证是否合法
class func validate18PaperId(input:String) ->Bool{
if (input.characters.count != 15)&&(input.characters.count != 18) {
return false
} let carid:String = input var lSumQT = 0
// 加权因子
let R:[Int] = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ]
// 校验码
let sChecker:[String] = ["1","0", "X" , "9", "8", "7", "6", "5", "4", "3","2" ] var mString:String = input if input.characters.count == 15 {
mString.insert(Character.init("1"), atIndex: mString.startIndex.advancedBy(6))
mString.insert(Character.init("9"), atIndex: mString.startIndex.advancedBy(7)) var p = 0 let pid = (mString as NSString).UTF8String for i in 0...16 {
p += (pid[i]-48)*R[i]
} let o:Int = p%11 let string_content = String(format: "%@", sChecker[o]) mString.insert(Character.init(string_content), atIndex: mString.endIndex.advancedBy(0))
} let sProvince = carid.substringToIndex(carid.startIndex.advancedBy(2)) if !self.areaCode(sProvince) {
return false
} // 判断年月日是否有效
// 年
let strYear = (self.getStringWithRange(carid, value1: 6, value2: 4) as NSString).intValue
// 月
let strMonth = (self.getStringWithRange(carid, value1: 10, value2: 2) as NSString).intValue
// 日
let strDay = (self.getStringWithRange(carid, value1: 12, value2: 2) as NSString).intValue let localZone:NSTimeZone = NSTimeZone.localTimeZone() let dateFormatter = NSDateFormatter() dateFormatter.dateStyle = NSDateFormatterStyle.MediumStyle dateFormatter.timeZone = localZone dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" print(String(format: "%d-%d-%d", strYear,strMonth,strDay)) let data = dateFormatter.dateFromString(String(format: "%d-%d-%d 12:01:01", strYear,strMonth,strDay)) if data == nil {
return false
} let PaperId:UnsafePointer<CChar> = (carid as NSString).UTF8String print(PaperId) if carid.characters.count != 18 {
return false;
}
for i in 0..<18 {
if ((isdigit(Int32(PaperId[i]))).distanceTo(1) != 0 && (!("X".characterAtIndex(0) == UInt16(PaperId[i]) || UnicodeScalar("x").value == UInt32(PaperId[i])) && 17 == i))
{
return false;
}
} for i in 0...16 {
lSumQT += (PaperId[i] - 48) * R[i]
} if (sChecker[lSumQT%11] as NSString).characterAtIndex(0) != UInt16(PaperId[17]) {
return false
}
return true
} // 私有方法 字符串的范围取值
private class func getStringWithRange(str:String,value1:Int,value2:Int)->String{
return (str as NSString).substringWithRange(NSMakeRange(value1, value2))
} // 私有方法 判断是否符合地理编码
private class func areaCode(code:String)->Bool {
var dict = [String:String]()
dict["11"] = "北京"
dict["12"] = "天津"
dict["13"] = "河北"
dict["14"] = "山西"
dict["15"] = "内蒙古"
dict["21"] = "辽宁"
dict["22"] = "吉林"
dict["23"] = "黑龙江"
dict["31"] = "上海"
dict["32"] = "江苏"
dict["33"] = "浙江"
dict["34"] = "安徽"
dict["35"] = "福建"
dict["36"] = "江西"
dict["37"] = "山东"
dict["41"] = "河南"
dict["42"] = "湖北"
dict["43"] = "湖南"
dict["44"] = "广东"
dict["45"] = "广西"
dict["46"] = "海南"
dict["50"] = "重庆"
dict["51"] = "四川"
dict["52"] = "贵州"
dict["53"] = "云南"
dict["54"] = "*"
dict["61"] = "陕西"
dict["62"] = "甘肃"
dict["63"] = "青海"
dict["64"] = "宁夏"
dict["65"] = "*"
dict["71"] = "*"
dict["81"] = "香港"
dict["82"] = "澳门"
dict["91"] = "国外"
if dict[code] == nil {
return false
}
return true
} // 私有类方法 根据输入正则规则与被判断数据判断是否正确
private class func validateFirstMatch(pattern:String, input:String)->Bool {
var regex:NSRegularExpression?
do {
regex = try NSRegularExpression(pattern: pattern as String, options: .CaseInsensitive) let resultCheck: NSTextCheckingResult! = regex?.firstMatchInString(input, options: NSMatchingOptions(), range: NSMakeRange(0, input.characters.count))
if resultCheck != nil {
return true
}
return false
} catch {
return false
}
} private class func validateNumberMatch(pattern:String, input:String)->Bool {
var regex:NSRegularExpression?
do {
regex = try NSRegularExpression(pattern: pattern as String, options: .CaseInsensitive) let resultCheck:NSInteger = (regex?.numberOfMatchesInString(input, options: NSMatchingOptions(), range: NSMakeRange(0, input.characters.count)))!
if resultCheck > 0 {
return true
}
return false } catch {
return false
}
}
}

VersionTools.swift

//
// YWBVersionTools.swift
// swiftTest
//
// Created by napiao on 15/11/26.
// Copyright © 2015年 JINMARONG. All rights reserved.
// //private let VERSION_IOS_REVIEWS_URL_FORMAT = "itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=990869716" private let VERSION_IOS7_REVIEWS_URL_FORMAT = "itms-apps://itunes.apple.com/app/id990869716" private let VERSION_IOS8_REVIEWS_URL_FORMAT = "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=990869716&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8" import Foundation // 单例
class VersionTools {
private static let shareInstance = VersionTools()
class var shareManager : VersionTools {
return shareInstance
} func apenAppReviews() {
var url:NSURL if UIDevice.currentDevice().systemVersion.compare("7.0") != NSComparisonResult.OrderedDescending{
url = NSURL(string: VERSION_IOS7_REVIEWS_URL_FORMAT)!
} else {
url = NSURL(string: VERSION_IOS8_REVIEWS_URL_FORMAT)!
} UIApplication.sharedApplication().openURL(url)
} }
上一篇:React Native组件之Text


下一篇:React Native笔记整理