修复统计数据api出错时,app崩溃的问题

This commit is contained in:
ylzheng
2015-10-28 00:50:11 +08:00
parent 3b98edfcca
commit fdc7f85fda
3 changed files with 46 additions and 40 deletions
+8
View File
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
18988A881B93641900FCB1A8 /* libiconv.2.4.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 18988A871B93641900FCB1A8 /* libiconv.2.4.0.dylib */; };
4501B6A21BDFA66F00B9D4AF /* LogupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4501B6A11BDFA66F00B9D4AF /* LogupViewController.swift */; };
450C3AAC1BC621F7006B5A5F /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 450C3AAB1BC621F7006B5A5F /* QuartzCore.framework */; };
450C3AAE1BC62201006B5A5F /* ImageIO.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 450C3AAD1BC62201006B5A5F /* ImageIO.framework */; };
450C3AB01BC62214006B5A5F /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 450C3AAF1BC62214006B5A5F /* Security.framework */; };
@@ -115,6 +116,7 @@
04DD86F873034FCDBA6CF699 /* Pods-librx.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-librx.debug.xcconfig"; path = "Pods/Target Support Files/Pods-librx/Pods-librx.debug.xcconfig"; sourceTree = "<group>"; };
18988A871B93641900FCB1A8 /* libiconv.2.4.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libiconv.2.4.0.dylib; path = usr/lib/libiconv.2.4.0.dylib; sourceTree = SDKROOT; };
3C589578C2D1AD931B429F24 /* Pods-librx.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-librx.release.xcconfig"; path = "Pods/Target Support Files/Pods-librx/Pods-librx.release.xcconfig"; sourceTree = "<group>"; };
4501B6A11BDFA66F00B9D4AF /* LogupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogupViewController.swift; sourceTree = "<group>"; };
450C3AAB1BC621F7006B5A5F /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
450C3AAD1BC62201006B5A5F /* ImageIO.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ImageIO.framework; path = System/Library/Frameworks/ImageIO.framework; sourceTree = SDKROOT; };
450C3AAF1BC62214006B5A5F /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
@@ -433,6 +435,7 @@
45517B151BCCB73D004C6D10 /* GraphsUIViewController.swift */,
4544DAD51BCD4358002B6666 /* SettingTableViewController.swift */,
45D4B1CA1BDCC55600E3FA32 /* ExploreTableViewController.swift */,
4501B6A11BDFA66F00B9D4AF /* LogupViewController.swift */,
);
name = controllers;
sourceTree = "<group>";
@@ -776,6 +779,7 @@
45D09EB01BDBD375006F91C2 /* LineChart.swift in Sources */,
45CF60481B67C3D900CA7F06 /* StorysTableViewController.swift in Sources */,
45517B161BCCB73D004C6D10 /* GraphsUIViewController.swift in Sources */,
4501B6A21BDFA66F00B9D4AF /* LogupViewController.swift in Sources */,
452DC11C1B6287E600847691 /* librx.xcdatamodeld in Sources */,
45D8E71D1B71CA6E00A33659 /* Extension.swift in Sources */,
45CE21A51BC35D7800642186 /* DateUtil.swift in Sources */,
@@ -933,6 +937,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -954,6 +959,7 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.librme.libr;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
VALID_ARCHS = "armv6 armv7 armv7s arm64";
};
name = Debug;
@@ -964,6 +970,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
ENABLE_BITCODE = NO;
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
@@ -985,6 +992,7 @@
ONLY_ACTIVE_ARCH = YES;
PRODUCT_BUNDLE_IDENTIFIER = com.librme.libr;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE = "";
VALID_ARCHS = "armv6 armv7 armv7s arm64";
};
name = Release;
+32 -39
View File
@@ -18,49 +18,19 @@ class GraphsUIViewController: UIViewController, LineChartDelegate {
LibrxService.userData(self.userId) { [weak self](json) -> () in
if let selfView = self {
var xlabels00:[String] = []
var data00:[CGFloat] = []
var data01:[CGFloat] = []
var data02:[CGFloat] = []
if let selfView = self {
if (json != nil) {
let shares = json["shares"].arrayValue
let likes = json["likes"].arrayValue
let bookmarks = json["bookmarks"].arrayValue
var views: [String: AnyObject] = [:]
selfView.label.text = "..."
selfView.label.translatesAutoresizingMaskIntoConstraints = false
selfView.label.textAlignment = NSTextAlignment.Center
selfView.label.font.fontWithSize(12)
selfView.view.addSubview(selfView.label)
views["label"] = selfView.label
selfView.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[label]-|", options: [], metrics: nil, views: views))
selfView.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-10-[label]", options: [], metrics: nil, views: views))
// simple arrays
// let data: [CGFloat] = [3, 4, -2, 11, 13, 15]
// let data2: [CGFloat] = [1, 3, 5, 13, 17, 20]
// simple line with custom x axis labels
// let xLabels: [String] = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
selfView.lineChart = LineChart()
selfView.lineChart.animation.enabled = true
selfView.lineChart.area = true
selfView.lineChart.x.labels.visible = true
selfView.lineChart.x.grid.count = 5
selfView.lineChart.x.grid.color = UIColor(red: 238/255.0, green: 238/255.0, blue: 238/255.0, alpha: 1)
selfView.lineChart.y.grid.count = 5
var xlabels00:[String] = []
var data00:[CGFloat] = []
var data01:[CGFloat] = []
var data02:[CGFloat] = []
for index in 0..<shares.count {
@@ -87,7 +57,30 @@ class GraphsUIViewController: UIViewController, LineChartDelegate {
data02.append(CGFloat(value))
}
}
var views: [String: AnyObject] = [:]
selfView.label.text = "..."
selfView.label.translatesAutoresizingMaskIntoConstraints = false
selfView.label.textAlignment = NSTextAlignment.Center
selfView.label.font.fontWithSize(12)
selfView.view.addSubview(selfView.label)
views["label"] = selfView.label
selfView.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-[label]-|", options: [], metrics: nil, views: views))
selfView.view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|-10-[label]", options: [], metrics: nil, views: views))
selfView.lineChart = LineChart()
selfView.lineChart.animation.enabled = true
selfView.lineChart.area = true
selfView.lineChart.x.labels.visible = true
selfView.lineChart.x.grid.count = 5
selfView.lineChart.x.grid.color = UIColor(red: 238/255.0, green: 238/255.0, blue: 238/255.0, alpha: 1)
selfView.lineChart.y.grid.count = 5
selfView.lineChart.x.labels.values = xlabels00
selfView.lineChart.y.labels.visible = false
+6 -1
View File
@@ -369,7 +369,12 @@ struct LibrxService {
Alamofire.request(.GET, urlString).response { (req, res, data, error) -> Void in
let json = JSON(data: data!)
response(json)
if let _ = error{
response(nil)
} else{
response(json)
}
}