Skip to content

Commit

Permalink
Swift_6
Browse files Browse the repository at this point in the history
Swift_6
  • Loading branch information
Hyosung committed Jul 29, 2014
1 parent cd60465 commit 4742835
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions ACCommon_Swift/ACAdditions/NSDate+ACAdditions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ extension NSDate {
}

func era() -> NSString {
return NSString(self.dateComponents().era)
}

func year() -> NSString {
Expand Down
32 changes: 32 additions & 0 deletions ACCommon_Swift/ACViews/ACTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,38 @@ struct ACSeparatorSpaces {
var right: CGFloat
}

//@infix 此关键字用于定义一个全局的运算符函数(双目运算符)
//这里只是写一个例子
@infix func +(spaces1: ACSeparatorSpaces, spaces2: ACSeparatorSpaces) -> ACSeparatorSpaces {
return ACSeparatorSpaces(left: spaces1.left + spaces2.left, right: spaces1.right + spaces2.right)
}

//@prefix 此关键字用于定义一个前置运算符函数(如:-100,+100)(单目运算符)
@prefix func -(spaces: ACSeparatorSpaces) -> ACSeparatorSpaces {
return ACSeparatorSpaces(left: -spaces.left, right: -spaces.right)
}

//@postfix 此关键字用于定义一个后置运算符函数(如:100--,100++)(单目运算符)
@postfix func --(spaces: ACSeparatorSpaces) -> ACSeparatorSpaces {
return ACSeparatorSpaces(left: spaces.left--, right: spaces.right--)
}

//@assignment 此关键字用于定义一个组合赋值运算符函数(如:100 += 100),而且需将左参数用inout修饰,inout关键字表示此参数应该传入地址进行操作
@assignment func +=(inout spaces1:ACSeparatorSpaces, spaces2: ACSeparatorSpaces) {
spaces1 = spaces1 + spaces2
}

//自定义运算符

//标准的运算符不够玩,那你可以声明一些个性的运算符,但个性的运算符只能使用这些字符 / = - + * % < >!& | ^。~。
//新的运算符声明需在全局域使用operator关键字声明,可以声明为前置,中置或后置的。
//operator prefix +++{}
//
//@prefix @assignment +++ (inout spaces1: ACSeparatorSpaces) -> ACSeparatorSpaces {
// spaces1 += spaces1
// return spaces1
//}

func ACSeparatorSpacesMake(left: CGFloat, right: CGFloat) -> ACSeparatorSpaces {
var spaces = ACSeparatorSpaces(left: left, right: right)
return spaces
Expand Down
1 change: 1 addition & 0 deletions ACCommon_Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// Override point for customization after application launch.

return true
}

Expand Down

0 comments on commit 4742835

Please sign in to comment.