Skip to content

Commit

Permalink
convert swift 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
WangHui authored and WangHui committed Aug 12, 2015
1 parent fcea7f7 commit a62ee73
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
2 changes: 2 additions & 0 deletions Autolayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@
7BC03A7B1B63D0B00049DE32 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0640;
ORGANIZATIONNAME = Wang.Hui;
TargetAttributes = {
Expand Down
18 changes: 9 additions & 9 deletions Autolayout/AFHTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ class AFHTTPClient: AFHTTPSessionManager {

dispatch_once(&Static.onceToken, { () -> Void in

var baseURL = NSURL(string: BaseURL)
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let baseURL = NSURL(string: BaseURL)
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()

// 设置缓存大小
var cache = NSURLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 5 * 1024 * 1024, diskPath: nil)
let cache = NSURLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 5 * 1024 * 1024, diskPath: nil)
sessionConfig.URLCache = cache


Expand All @@ -50,11 +50,11 @@ class AFHTTPClient2: AFHTTPSessionManager {
}

init() {
var baseURL = NSURL(string: BaseURL)
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let baseURL = NSURL(string: BaseURL)
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()

// 设置缓存大小
var cache = NSURLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 5 * 1024 * 1024, diskPath: nil)
let cache = NSURLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 5 * 1024 * 1024, diskPath: nil)
sessionConfig.URLCache = cache

super.init(baseURL: baseURL, sessionConfiguration: sessionConfig)
Expand All @@ -80,11 +80,11 @@ class AFHTTPClient3: AFHTTPSessionManager {
}

init() {
var baseURL = NSURL(string: BaseURL)
var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
let baseURL = NSURL(string: BaseURL)
let sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()

// 设置缓存大小
var cache = NSURLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 5 * 1024 * 1024, diskPath: nil)
let cache = NSURLCache(memoryCapacity: 10 * 1024 * 1024, diskCapacity: 5 * 1024 * 1024, diskPath: nil)
sessionConfig.URLCache = cache

super.init(baseURL: baseURL, sessionConfiguration: sessionConfig)
Expand Down
2 changes: 1 addition & 1 deletion Autolayout/Extend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ let IS_IPHONE_5 = IS_IPHONE && (SCREEN_MAX_LENGTH) == 568.0
let IS_IPHONE_6 = IS_IPHONE && (SCREEN_MAX_LENGTH) == 667.0
let IS_IPHONE_6P = IS_IPHONE && (SCREEN_MAX_LENGTH) == 736.0

func getImageURLString(imageUrl: String, #width: Int, #height: Int) -> String {
func getImageURLString(imageUrl: String, width: Int, height: Int) -> String {

var exactUrl = ""
var urlArr = imageUrl.componentsSeparatedByString("/")
Expand Down
28 changes: 14 additions & 14 deletions Autolayout/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

var homeSearchBar: HomeSearchBarView = (UINib(nibName: "HomeSearchBarView", bundle: nil).instantiateWithOwner(self, options: nil).first) as! HomeSearchBarView
let homeSearchBar: HomeSearchBarView = (UINib(nibName: "HomeSearchBarView", bundle: nil).instantiateWithOwner(self, options: nil).first) as! HomeSearchBarView

self.navigationItem.titleView = homeSearchBar

Expand All @@ -41,7 +41,7 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc
func initHeaderView() {
self.getBannerDataFromServer { (result, error) -> Void in
if error == nil {
var dataArr = result as! NSArray
let dataArr = result as! NSArray
if dataArr.count > 0 {
self.initCycleScrollView(dataArr)
}
Expand All @@ -51,17 +51,17 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc

func initCycleScrollView(dataArr: NSArray) {

var scale = SCREEN_WIDTH / 320.0
let scale = SCREEN_WIDTH / 320.0
tableHeader.frame = CGRectMake(0, 0, SCREEN_WIDTH, 165.0 * scale)

var headerView = CycleScrollView(frame: CGRectMake(0, 0, SCREEN_WIDTH, 165.0 * scale), animationDuration: 2.0, style: CycleStylePage, andImageCount: dataArr.count)
let headerView = CycleScrollView(frame: CGRectMake(0, 0, SCREEN_WIDTH, 165.0 * scale), animationDuration: 2.0, style: CycleStylePage, andImageCount: dataArr.count)

var imageArr = [UIImageView]()

for dict in dataArr {

var imageUrl = (dict as! NSDictionary).valueForKey("images")?.firstObject
var imageView = UIImageView(frame:CGRectMake(0, 0, SCREEN_WIDTH, 165.0 * scale))
let imageUrl = (dict as! NSDictionary).valueForKey("images")?.firstObject
let imageView = UIImageView(frame:CGRectMake(0, 0, SCREEN_WIDTH, 165.0 * scale))

if (imageUrl != nil) && !(imageUrl is NSNull){

Expand All @@ -70,7 +70,7 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc

imageArr.append(imageView)

println(imageView)
print(imageView)
}

headerView.fetchContentViewAtIndex = {(pageIndex: Int) -> UIView in
Expand All @@ -80,17 +80,17 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc
headerView.totalPagesCount = { dataArr.count }

headerView.TapActionBlock = {(pageIndex: Int) in
var dict = dataArr[pageIndex] as! NSDictionary
var type = dict.valueForKey("type") as! Int
let dict = dataArr[pageIndex] as! NSDictionary
let type = dict.valueForKey("type") as! Int
var toid = dict.valueForKey("toid") as! Int

if type == 1 {

println("type 1 click")
print("type 1 click")

} else {

println("other type click")
print("other type click")
}
}

Expand All @@ -109,7 +109,7 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc
callBack(result: responseObject.valueForKey("data"), error: nil)

} else {
println("get banner error")
print("get banner error")
}
}

Expand Down Expand Up @@ -145,10 +145,10 @@ class ViewController: UIViewController,UITableViewDelegate, UITableViewDataSourc
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

if indexPath.row % 2 == 0 {
var cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier("homeCell", forIndexPath: indexPath)
return cell
} else {
var cell = tableView.dequeueReusableCellWithIdentifier("homeSecondCell", forIndexPath: indexPath) as! UITableViewCell
let cell = tableView.dequeueReusableCellWithIdentifier("homeSecondCell", forIndexPath: indexPath)
return cell
}

Expand Down
1 change: 1 addition & 0 deletions Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a62ee73

Please sign in to comment.