Skip to content

Commit

Permalink
Merge pull request #718 from skyline75489/master
Browse files Browse the repository at this point in the history
Fix 'AnyObject' in comment and README.md
  • Loading branch information
zhigang1992 committed Nov 16, 2016
2 parents 6d6c0f3 + ac6f5cf commit e98ac1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ Take the Twitter API for example. Say we want to retrieve a user's "name" value
The code would look like this:

```swift
if let statusesArray = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: AnyObject]],
let user = statusesArray[0]["user"] as? [String: AnyObject],
if let statusesArray = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [[String: Any]],
let user = statusesArray[0]["user"] as? [String: Any],
let username = user["name"] as? String {
// Finally we got the username
}
Expand All @@ -45,8 +45,8 @@ It's not good.
Even if we use optional chaining, it would be messy:

```swift
if let JSONObject = try JSONSerialization.jsonObject(with: data,, options: .allowFragments) as? [[String: AnyObject]],
let username = (JSONObject[0]["user"] as? [String: AnyObject])?["name"] as? String {
if let JSONObject = try JSONSerialization.jsonObject(with: data,, options: .allowFragments) as? [[String: Any]],
let username = (JSONObject[0]["user"] as? [String: Any])?["name"] as? String {
// There's our username
}
```
Expand Down Expand Up @@ -340,11 +340,11 @@ json.dictionaryObject = ["name":"Jack", "age":25]
#### Raw object

```swift
let jsonObject: AnyObject = json.object
let jsonObject: Any = json.object
```

```swift
if let jsonObject: AnyObject = json.rawValue
if let jsonObject: Any = json.rawValue
```

```swift
Expand Down
5 changes: 3 additions & 2 deletions Source/SwiftyJSON.swift
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ extension JSON {
}
}

//Optional [AnyObject]
//Optional [Any]
public var arrayObject: [Any]? {
get {
switch self.type {
Expand Down Expand Up @@ -696,7 +696,8 @@ extension JSON {
return self.dictionary ?? [:]
}

//Optional [String : AnyObject]
//Optional [String : Any]

public var dictionaryObject: [String : Any]? {
get {
switch self.type {
Expand Down

0 comments on commit e98ac1a

Please sign in to comment.