Skip to content

Dynamic Member Lookup introduced in Swift 4.2, now we can use dot, in…#1132

Closed
gsmalleySDC wants to merge 1 commit intoSwiftyJSON:masterfrom
gsmalleySDC:xcode10.0
Closed

Dynamic Member Lookup introduced in Swift 4.2, now we can use dot, in…#1132
gsmalleySDC wants to merge 1 commit intoSwiftyJSON:masterfrom
gsmalleySDC:xcode10.0

Conversation

@gsmalleySDC
Copy link
Copy Markdown

…stead of brackets (#986)

  • This proposal introduces a new @dynamicMemberLookup attribute. Types that use it provide "dot" syntax for arbitrary names which are resolved at runtime - in a completely type safe way. This provides syntactic sugar that allows the user to write

[introduce-user-defined-dynamic-member-lookup-types](https://github.com/apple/swift-evolution/blob/master/proposals/0195-dynamic-member-lookup.md#introduce-user-defined-dynamic-member-lookup-types)

i've added a subscript function with dynamic member, so users can use dot instead of [],
```
let name = json.name
The same as: let name = json["name"]

 let phoneNumber = json.user.contactInfo.phoneNumber
 The same as: let name = json["user"]["contactInfo"]["phoneNumber"]

* resolve houndci-bot conversation

* update swift version to 4.2

* change travis swift version to 4.2.0

* set travis simulator ios version

* check for ios 12

* redu changes to travis.yml

* new test file added, DynamicMemberLookupTests.swift

* email address changed to some random email address

* remove a test because it was duplicate

* resolve hound comma

The PR should summarize what was changed and why. Here are some questions to
help you if you're not sure:

 - What behavior was changed?
 - What code was refactored / updated to support this change?
 - What issues are related to this PR? Or why was this change introduced?

Checklist - While not every PR needs it, new features should consider this list:

 - [ ] Does this have tests?
 - [ ] Does this have documentation?
 - [ ] Does this break the public API (Requires major version bump)?
 - [ ] Is this a new feature (Requires minor version bump)?

…stead of brackets (#986)

* This proposal introduces a new @dynamicMemberLookup attribute. Types that use it provide "dot" syntax for arbitrary names which are resolved at runtime - in a completely type safe way. This provides syntactic sugar that allows the user to write

**[introduce-user-defined-dynamic-member-lookup-types]**(https://github.com/apple/swift-evolution/blob/master/proposals/0195-dynamic-member-lookup.md#introduce-user-defined-dynamic-member-lookup-types)

i've added a subscript function with dynamic member, so users can use dot instead of [],
     ```
let name = json.name
     The same as: let name = json["name"]

     let phoneNumber = json.user.contactInfo.phoneNumber
     The same as: let name = json["user"]["contactInfo"]["phoneNumber"]

```

* resolve houndci-bot conversation

* update swift version to 4.2

* change travis swift version to 4.2.0

* set travis simulator ios version

* check for ios 12

* redu changes to travis.yml

* new test file added, DynamicMemberLookupTests.swift

* email address changed to some random email address

* remove a test because it was duplicate

* resolve hound comma
@gsmalleySDC gsmalleySDC deleted the xcode10.0 branch February 22, 2023 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants