Skip to content

update to swift 5 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@
TargetAttributes = {
655C4C5A1FCDCACA00EE5EF8 = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 7KXVPC4Y3C;
};
655C4C6E1FCDCACA00EE5EF8 = {
CreatedOnToolsVersion = 7.3.1;
Expand All @@ -209,6 +210,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -399,21 +401,25 @@
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;
};
655C4C851FCDCACA00EE5EF8 /* Release */ = {
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;
};
Expand Down Expand Up @@ -482,6 +488,7 @@
655C4C851FCDCACA00EE5EF8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
655C4C861FCDCACA00EE5EF8 /* Build configuration list for PBXNativeTarget "APIJSONTestTests" */ = {
isa = XCConfigurationList;
Expand All @@ -490,6 +497,7 @@
655C4C881FCDCACA00EE5EF8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
655C4C891FCDCACA00EE5EF8 /* Build configuration list for PBXNativeTarget "APIJSONTestUITests" */ = {
isa = XCConfigurationList;
Expand All @@ -498,6 +506,7 @@
655C4C8B1FCDCACA00EE5EF8 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "F176DF8F-D2E4-4AAD-82C4-B145D3DDB06F"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "0FD1DAD7-3631-4008-A63C-D9F9E5B3C01C"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "APIJSONTest/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "84"
endingLineNumber = "84"
landmarkName = "test()"
landmarkType = "7">
<Locations>
<Location
uuid = "0FD1DAD7-3631-4008-A63C-D9F9E5B3C01C - 336694360a88cce6"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "APIJSONTest.ViewController.test() -&gt; ()"
moduleName = "APIJSONTest"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/rogerluo/Downloads/APIJSON-Demo-master/APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "84"
endingLineNumber = "84"
offsetFromSymbolStart = "4060">
</Location>
<Location
uuid = "0FD1DAD7-3631-4008-A63C-D9F9E5B3C01C - 183bbd76298b9b95"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #1 (Swift.Optional&lt;Foundation.Data&gt;, Swift.Optional&lt;__C.NSURLResponse&gt;, Swift.Optional&lt;Swift.Error&gt;) -&gt; () in APIJSONTest.ViewController.test() -&gt; ()"
moduleName = "APIJSONTest"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/rogerluo/Downloads/APIJSON-Demo-master/APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "86"
endingLineNumber = "86"
offsetFromSymbolStart = "388">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>APIJSONTest.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
16 changes: 10 additions & 6 deletions APIJSON-iOS/APIJSON-Swift/APIJSONTest/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="6211" systemVersion="14A298i" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6204"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="APIJSONTest" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="y3c-jy-aDJ"/>
<viewControllerLayoutGuide type="bottom" id="wfy-db-euE"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="24" y="-21"/>
</scene>
</scenes>
</document>
38 changes: 20 additions & 18 deletions APIJSON-iOS/APIJSON-Swift/APIJSONTest/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 >>>>>>>>>>>>>>>>>>>>>

Expand All @@ -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")

Expand All @@ -90,30 +90,32 @@ 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")
});
}

}

//请求开始
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!
}

Expand Down