xcode的新变化,包括xcode8, swift3等
#Xcode8新变化
1.菜单栏window下没有了projects选项,无法删除derive data
可手动命令行删除:rm -rf ~/Library/Developer/Xcode/DerivedData
2.调试选项下,多了一个runtime
#swift3变化
在Xcode8.0上 Edit->Convert->To Current Swift Syntax,可自动把代码更新成swift2.3或3.0格式
swift2.3之前格式的代码无法在Xcode8.0上编译
1.类或属性修饰词
swift2 public, private
swift3 open, fileprivate
2.CGRect变化
swift2 CGRect(0, 0, 0, 0)
CGRectMake(0, 0, 0, 0)
swift3 CGRect(x: 0, y: 0, width: 0, height 0)
CGRect(x: 0, y: 0, width: 0, height 0)
类似的还有CGPoint
3.颜色
swift2 UIColor.grayColor()
swift3 UIColor.gray
4.枚举变化
swift2
UITableViewStyle.Plain
UIActivityIndicatorViewStyle.Gray
swift3(首字母变为了小写)
UITableViewStyle.plain
UIActivityIndicatorViewStyle.gray
5.隐藏
swift2 tableview?.hidden = true
swift3 tableview?.isHidden = true
6.方法调用的改变
swift2
dataSource.isKindOfClass(NSArray.self)
modeArray.addObjectsFromArray(dataSource as [AnyObject])
swift3
dataSource.isKind(of: NSArray.self)
modelArray.addObjects(from: dataSource as [AnyObject])
7.代理方法的改变
以UITableView为例
swift2
public func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)
swift3
open func tableView(_ tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: IndexPath)
类似的还有NSError使用Error类型代替,等
8.协议的改变
optional方法的变化
swift2
optional func requestFirstPage() -> Void
swift3
@objc optional func requestFirstPage() -> Void
9.action的改变
swift2
backBtn.addTarget(self, action: "backBtnControlEventAction", forControlEvents: .TouchUpInside)
swift3
backBtn.addTarget(self, action: #selector(CTBaseViewController.backBtnControlEventAction), for: .touchUpInside)
10.coregraphics的变化
swift2
let context: CGContextRef? = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
swift3
let context: CGContext? = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
xcode8使用中可能遇到的错误
1.convert to current swift syntax failed could not find test host
http://stackoverflow.com/questions/37847807/xcode-8-beta-convert-to-current-swift-syntax-failed-could-not-find-test-host
2.