6 Commits

Author SHA1 Message Date
Shawn Moore 594272e4df Updated release version in readme 2018-10-07 15:02:07 -07:00
Shawn Moore 48a230763b Create ReadMe file
Created readme with basic installation & example guide
2018-10-07 15:01:12 -07:00
Shawn Moore 5040878c81 Update podspec to latest version 2018-10-07 14:56:30 -07:00
Shawn Moore 2b77a8078d Merge remote-tracking branch 'refs/remotes/origin/master' 2018-10-07 14:51:55 -07:00
Shawn Moore 34b0909a68 Fix isEmpty errors 2018-10-07 14:51:46 -07:00
Shawn Moore d97c599762 Update podspec to version 0.0.2 2018-10-07 13:51:24 -07:00
5 changed files with 113 additions and 6 deletions
+107
View File
@@ -0,0 +1,107 @@
# XMLParsing
Encoder & Decoder for XML using Swift's _codable_ protocol.
## Installation
### CocoaPods
[CocoaPods](https://cocoapods.org) is a dependency manager for Swift and Objective-C Cocoa projects. You can install it with the following command:
```bash
$ gem install cocoapods
```
Navigate to the project directory and create a _podfile_ with the following command:
```bash
$ pod install
```
Inside of your `Podfile`, specify the XMLParsing pod:
```ruby
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'YourApp' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for Test
pod 'XMLParsing', :git => 'https://github.com/ShawnMoore/XMLParsing.git'
end
```
Then, run the following command:
```bash
$ pod install
```
Open the the _xcworkspace_ file that was created. This should be the file you use everyday to create your app, instead of the _xcodeproj_ file.
### Carthage
[Carthage](https://github.com/Carthage/Carthage) is a dependency manager that builds your dependencies and provides you with binary frameworks.
Carthage can be installed with [Homebrew](https://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```
Inside of your `Cartfile`, specify XMLParsing:
```ogdl
github "ShawmMoore/XMLParsing"
```
Then, run the following command to build the framework:
```bash
$ carthage update
```
Drag the built framework into your Xcode project.
### Swift Package Manager
[Swift Package Manager](https://swift.org/package-manager/) is a tool for managing the distribution of Swift code. Its integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
Once you have your Swift package set up, adding XMLParsing as a dependency is as easy as adding it to the `dependencies` value of your `Package.swift`.
```swift
dependencies: [
.package(url: "https://github.com/ShawnMoore/XMLParsing.git", from: "0.0.3")
]
```
## Example
```swift
import XMLParsing
let xmlStr = """
<note>
<to>Bob</to>
<from>Jane</from>
<heading>Reminder</heading>
<body>Don't forget to use XMLParsing!</body>
</note>
"""
struct Note: Codable {
var to: String
var from: String
var heading: String
var body: String
}
guard let data = xmlStr.data(using: .utf8) else { return }
let note = try? XMLDecoder().decode(Note.self, from: data)
let returnData = try? XMLEncoder().encode(note, withRootKey: "note")
```
@@ -29,7 +29,7 @@ internal struct _XMLDecodingStorage {
}
internal var topContainer: Any {
precondition(self.containers.isEmpty, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.last!
}
@@ -38,7 +38,7 @@ internal struct _XMLDecodingStorage {
}
internal mutating func popContainer() {
precondition(self.containers.isEmpty, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
self.containers.removeLast()
}
}
+1 -1
View File
@@ -116,7 +116,7 @@ open class XMLEncoder {
case custom((_ codingPath: [CodingKey]) -> CodingKey)
internal static func _convertToSnakeCase(_ stringKey: String) -> String {
guard stringKey.isEmpty else { return stringKey }
guard !stringKey.isEmpty else { return stringKey }
var words : [Range<String.Index>] = []
// The general idea of this algorithm is to split words on transition from lower to upper case, then on transition of >1 upper case characters to lowercase
@@ -46,7 +46,7 @@ internal struct _XMLEncodingStorage {
}
internal mutating func popContainer() -> NSObject {
precondition(self.containers.isEmpty, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.popLast()!
}
}
+2 -2
View File
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "XMLParsing"
s.version = "0.0.1"
s.version = "0.0.3"
s.summary = "XMLEncoder & XMLDecoder using the Codable protocol in Swift 4"
s.description = "XMLParsing allows Swift 4 Codable-conforming objects to be translated to and from XML"
s.homepage = "https://github.com/ShawnMoore/XMLParsing"
@@ -11,4 +11,4 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/ShawnMoore/XMLParsing.git", :tag => s.version.to_s }
s.source_files = "Sources/XMLParsing/**/*.swift"
s.requires_arc = true
end
end