Skip to content

Commit 2981c34

Browse files
authored
Merge pull request #282 from drmohundro/docs/readme-tweaks
docs: README tweaks
2 parents 7226ebc + f3b58ca commit 2981c34

5 files changed

Lines changed: 35 additions & 44 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: |
1818
set -o pipefail
1919
xcodebuild $ACTION $WORKSPACE -scheme "SWXMLHash OSX" | xcpretty
20-
xcodebuild $ACTION $WORKSPACE -scheme "SWXMLHash iOS" -sdk iphonesimulator -destination "OS=16.2,name=iPhone 13" | xcpretty
20+
xcodebuild $ACTION $WORKSPACE -scheme "SWXMLHash iOS" -sdk iphonesimulator -destination "OS=17.2,name=iPhone 15" | xcpretty
2121
xcodebuild $ACTION $WORKSPACE -scheme "SWXMLHash tvOS" -sdk appletvsimulator -destination "name=Apple TV" | xcpretty
2222
xcodebuild build $WORKSPACE -scheme "SWXMLHash watchOS" -sdk watchsimulator | xcpretty
2323
bash <(curl -s https://codecov.io/bash) -t ${{secrets.CODECOV_TOKEN}}

README.md

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
[![Swift](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdrmohundro%2FSWXMLHash%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/drmohundro/SWXMLHash)
44
[![Platforms](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdrmohundro%2FSWXMLHash%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/drmohundro/SWXMLHash)
5+
[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)
56
[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SWXMLHash)](https://cocoapods.org/pods/SWXMLHash)
67
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
7-
[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)](https://img.shields.io/badge/Swift_Package_Manager-compatible-orange?style=flat-square)
8-
[![Join the chat at https://gitter.im/drmohundro/SWXMLHash](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/drmohundro/SWXMLHash?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
9-
[![codebeat](https://codebeat.co/badges/893cc640-c5d9-45b2-a3ff-426e6e6b7b80)](https://codebeat.co/projects/github-com-drmohundro-swxmlhash)
108

119
SWXMLHash is a relatively simple way to parse XML in Swift. If you're familiar
12-
with `NSXMLParser`, this library is a simple wrapper around it. Conceptually, it
10+
with `XMLParser` (formerly `NSXMLParser`), this library is a wrapper around it. Conceptually, it
1311
provides a translation from XML to a dictionary of arrays (aka hash).
1412

1513
The API takes a lot of inspiration from
@@ -34,16 +32,29 @@ The API takes a lot of inspiration from
3432

3533
## Installation
3634

37-
SWXMLHash can be installed using [CocoaPods](http://cocoapods.org/),
38-
[Carthage](https://github.com/Carthage/Carthage),
39-
[Swift Package Manager](https://swift.org/package-manager/), or manually.
35+
SWXMLHash can be installed using [Swift Package Manager](https://swift.org/package-manager/), [CocoaPods](http://cocoapods.org/),
36+
[Carthage](https://github.com/Carthage/Carthage), or manually.
37+
38+
### Swift Package Manager
39+
40+
The [Swift Package Manager](https://swift.org/package-manager/) is a tool built by Apple as part of [the Swift project](https://swift.org/) for integrating libraries and frameworks into your Swift apps.
41+
42+
To add SWXMLHash as a dependency, update the `dependencies` in your `Package.swift` to include a reference like so:
43+
44+
```swift
45+
dependencies: [
46+
.package(url: "https://github.com/drmohundro/SWXMLHash.git", from: "7.0.0")
47+
]
48+
```
49+
50+
`swift build` should then pull in and compile SWXMLHash to begin using.
4051

4152
### CocoaPods
4253

4354
To install CocoaPods, run:
4455

4556
```bash
46-
$ gem install cocoapods
57+
gem install cocoapods
4758
```
4859

4960
Then create a `Podfile` with the following contents:
@@ -60,16 +71,16 @@ end
6071
Finally, run the following command to install it:
6172

6273
```bash
63-
$ pod install
74+
pod install
6475
```
6576

6677
### Carthage
6778

6879
To install Carthage, run (using Homebrew):
6980

7081
```bash
71-
$ brew update
72-
$ brew install carthage
82+
brew update
83+
brew install carthage
7384
```
7485

7586
Then add the following line to your `Cartfile`:
@@ -78,19 +89,6 @@ Then add the following line to your `Cartfile`:
7889
github "drmohundro/SWXMLHash" ~> 7.0
7990
```
8091

81-
### Swift Package Manager
82-
83-
Swift Package Manager requires Swift version 4.0 or higher. First, create a
84-
`Package.swift` file. It should look like:
85-
86-
```swift
87-
dependencies: [
88-
.package(url: "https://github.com/drmohundro/SWXMLHash.git", from: "7.0.0")
89-
]
90-
```
91-
92-
`swift build` should then pull in and compile SWXMLHash for you to begin using.
93-
9492
### Manual Installation
9593

9694
To install manually, you'll need to clone the SWXMLHash repository. You can do
@@ -99,15 +97,15 @@ case, git submodules are recommended so that your repository has details about
9997
which commit of SWXMLHash you're using. Once this is done, you can just drop all
10098
of the relevant swift files into your project.
10199

102-
If you're using a workspace, though, you can just include the entire `SWXMLHash.xcodeproj`.
100+
If you're using a workspace, though, you can include the entire `SWXMLHash.xcodeproj`.
103101

104102
## Getting Started
105103

106104
If you're just getting started with SWXMLHash, I'd recommend cloning the
107105
repository down and opening the workspace. I've included a Swift playground in
108106
the workspace which makes it easy to experiment with the API and the calls.
109107

110-
<img src="https://raw.githubusercontent.com/drmohundro/SWXMLHash/assets/swift-playground@2x.png" width="600" alt="Swift Playground" />
108+
![Swift Playground](https://raw.githubusercontent.com/drmohundro/SWXMLHash/assets/swift-playground@2x.png)
111109

112110
## Configuration
113111

@@ -178,7 +176,7 @@ let xml = XMLHash.config {
178176
}.parse(xmlToParse)
179177
```
180178

181-
The above approach uses the new config method, but there is also a `lazy` method
179+
The above approach uses the config method, but there is also a `lazy` method
182180
directly off of `XMLHash`.
183181

184182
```swift
@@ -362,7 +360,7 @@ print(subIndexer.children[0].element?.text)
362360

363361
### Error Handling
364362

365-
Using Swift 2.0's new error handling feature:
363+
Using Do-Catch with Errors:
366364

367365
```swift
368366
do {
@@ -461,7 +459,7 @@ The below will return an array of `Book` structs:
461459
let books: [Book] = try xml["root"]["books"]["book"].value()
462460
```
463461

464-
<img src="https://raw.githubusercontent.com/ncreated/SWXMLHash/assets/types-conversion%402x.png" width="600" alt="Types Conversion" />
462+
![Types Conversion](https://raw.githubusercontent.com/ncreated/SWXMLHash/assets/types-conversion%402x.png)
465463

466464
You can convert any XML to your custom type by implementing
467465
`XMLObjectDeserialization` for any non-leaf node (e.g. `<book>` in the example
@@ -551,7 +549,7 @@ a string and then parsing it.
551549
No, not at the moment - SWXMLHash only supports parsing XML (via indexing,
552550
deserialization, etc.).
553551

554-
### I'm getting an "Ambiguous reference to member 'subscript'" when I call `.value()`.
552+
### I'm getting an "Ambiguous reference to member 'subscript'" when I call `.value()`
555553

556554
`.value()` is used for deserialization - you have to have something that
557555
implements `XMLObjectDeserialization` (or `XMLElementDeserializable` if it is a

Source/FullXMLParser.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,10 @@ class FullXMLParser: NSObject, SimpleXmlParser, XMLParserDelegate {
8787
}
8888

8989
func parser(_ parser: XMLParser, foundCDATA CDATABlock: Data) {
90-
if let cdataText = String(data: CDATABlock, encoding: String.Encoding.utf8) {
91-
let current = parentStack.top()
90+
let cdataText = String(decoding: CDATABlock, as: UTF8.self)
91+
let current = parentStack.top()
9292

93-
current.addText(cdataText)
94-
}
93+
current.addText(cdataText)
9594
}
9695

9796
func parser(_ parser: XMLParser, parseErrorOccurred parseError: Error) {

Source/LazyXMLParser.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ class LazyXMLParser: NSObject, SimpleXmlParser, XMLParserDelegate {
9595
return
9696
}
9797

98-
if let cdataText = String(data: CDATABlock, encoding: String.Encoding.utf8) {
99-
let current = parentStack.top()
98+
let cdataText = String(decoding: CDATABlock, as: UTF8.self)
99+
let current = parentStack.top()
100100

101-
current.addText(cdataText)
102-
}
101+
current.addText(cdataText)
103102
}
104103

105104
func parser(_ parser: XMLParser,

Source/XMLAttribute.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ import Foundation
2828
public struct XMLAttribute {
2929
public let name: String
3030
public let text: String
31-
32-
init(name: String, text: String) {
33-
self.name = name
34-
self.text = text
35-
}
3631
}
3732

3833
extension XMLAttribute: CustomStringConvertible {

0 commit comments

Comments
 (0)