diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.pbxproj b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.pbxproj index 08255a21..b540c05f 100644 --- a/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.pbxproj +++ b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.pbxproj @@ -193,6 +193,7 @@ TargetAttributes = { 655C4C5A1FCDCACA00EE5EF8 = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 7KXVPC4Y3C; }; 655C4C6E1FCDCACA00EE5EF8 = { CreatedOnToolsVersion = 7.3.1; @@ -209,6 +210,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -399,10 +401,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 7KXVPC4Y3C; INFOPLIST_FILE = APIJSONTest/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.apijson.APIJSONTest; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -410,10 +414,12 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 7KXVPC4Y3C; INFOPLIST_FILE = APIJSONTest/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = org.apijson.APIJSONTest; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -482,6 +488,7 @@ 655C4C851FCDCACA00EE5EF8 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 655C4C861FCDCACA00EE5EF8 /* Build configuration list for PBXNativeTarget "APIJSONTestTests" */ = { isa = XCConfigurationList; @@ -490,6 +497,7 @@ 655C4C881FCDCACA00EE5EF8 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 655C4C891FCDCACA00EE5EF8 /* Build configuration list for PBXNativeTarget "APIJSONTestUITests" */ = { isa = XCConfigurationList; @@ -498,6 +506,7 @@ 655C4C8B1FCDCACA00EE5EF8 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.xcworkspace/xcuserdata/rogerluo.xcuserdatad/UserInterfaceState.xcuserstate b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.xcworkspace/xcuserdata/rogerluo.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 00000000..0007f6fa Binary files /dev/null and b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/project.xcworkspace/xcuserdata/rogerluo.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/xcuserdata/rogerluo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/xcuserdata/rogerluo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000..4c87e6b6 --- /dev/null +++ b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/xcuserdata/rogerluo.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/xcuserdata/rogerluo.xcuserdatad/xcschemes/xcschememanagement.plist b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/xcuserdata/rogerluo.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..808e570f --- /dev/null +++ b/APIJSON-iOS/APIJSON-Swift/APIJSONTest.xcodeproj/xcuserdata/rogerluo.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,14 @@ + + + + + SchemeUserState + + APIJSONTest.xcscheme_^#shared#^_ + + orderHint + 0 + + + + diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest/Base.lproj/Main.storyboard b/APIJSON-iOS/APIJSON-Swift/APIJSONTest/Base.lproj/Main.storyboard index 3a2a49ba..2b33aa08 100644 --- a/APIJSON-iOS/APIJSON-Swift/APIJSONTest/Base.lproj/Main.storyboard +++ b/APIJSON-iOS/APIJSON-Swift/APIJSONTest/Base.lproj/Main.storyboard @@ -1,25 +1,29 @@ - - + + + - + + + - + - + - + + diff --git a/APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift b/APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift index ca341e09..fa64a6fc 100644 --- a/APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift +++ b/APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift @@ -52,10 +52,10 @@ class ViewController: UIViewController { requestLabel.numberOfLines = 6 self.view.addSubview(requestLabel) - let responseLable = UILabel(frame:CGRect(x:20, y:130, width:400, height:600)) - responseLable.text = "request..." - responseLable.numberOfLines = 100 - self.view.addSubview(responseLable) + let responseLabel = UILabel(frame:CGRect(x:20, y:130, width:400, height:600)) + responseLabel.text = "request..." + responseLabel.numberOfLines = 100 + self.view.addSubview(responseLabel) //生成UI >>>>>>>>>>>>>>>>>>>>> @@ -65,23 +65,23 @@ class ViewController: UIViewController { //请求URL - let request:NSMutableURLRequest = NSMutableURLRequest(URL: NSURL(string: url)!) + let request = NSMutableURLRequest(url: URL(string: url)!) - request.HTTPMethod = "POST" + request.httpMethod = "POST" //设置发送的数据格式为JSON request.setValue("application/json", forHTTPHeaderField: "Content-Type") do { - request.HTTPBody = try NSJSONSerialization.dataWithJSONObject(json, options: NSJSONWritingOptions.PrettyPrinted) + request.httpBody = try JSONSerialization.data(withJSONObject: json, options: JSONSerialization.WritingOptions.prettyPrinted) } catch { print("Something went wrong!") } //默认session配置 - let config = NSURLSessionConfiguration.defaultSessionConfiguration() - let session = NSURLSession(configuration: config) + let config = URLSessionConfiguration.default + let session = URLSession(configuration: config) //发起请求 - let dataTask = session.dataTaskWithRequest(request) { (data, response, error) in + let dataTask = session.dataTask(with: request as URLRequest) { (data, response, error) in print("\n\nreceived result!\n\n") @@ -90,20 +90,20 @@ class ViewController: UIViewController { print(error) //数据类型转换 - let jsonData:NSDictionary = try! NSJSONSerialization.JSONObjectWithData(data!, options: .MutableContainers) as! NSDictionary + let jsonData:NSDictionary = try! JSONSerialization.jsonObject(with: data!, options: .mutableContainers) as! NSDictionary print(jsonData) - let res:String = self.toJSONString(jsonData); + let res:String = self.toJSONString(jsonData as! [String : Any]); print("Response = \n" + res) //显示返回结果 - dispatch_async(dispatch_get_main_queue(), { + DispatchQueue.main.async { - responseLable.text = "Response:\n" + res + responseLabel.text = "Response:\n" + res print("set text end\n\n") - }); + } } @@ -111,9 +111,11 @@ class ViewController: UIViewController { dataTask.resume() } - func toJSONString(jsonData: NSDictionary!) -> String { - let data : NSData! = try? NSJSONSerialization.dataWithJSONObject(jsonData, options: [NSJSONWritingOptions.PrettyPrinted]) as NSData! - let str = String(data: data, encoding: NSUTF8StringEncoding) + func toJSONString(_ jsonData: [String: Any]!) -> String { + guard let data = try? JSONSerialization.data(withJSONObject: jsonData!, options: [JSONSerialization.WritingOptions.prettyPrinted]) else { + return "" + } + let str = String(data: data, encoding: String.Encoding.utf8) return str! }