Comments (12)
If you do create a proposal, it would be better if Swift would do this without having to use the ".then" part (or maybe it was named something else).
The reason for that is because I love to use "Promises" for any async operations (take a look at a lib like PromiseKit http://promisekit.org/ ). Promises usually use .then(), so I'm not sure if there would be conflicts when using this lib.
from then.
@adrfer Thanks for making everyone aware of each other! @devxoul Done it? Far from it, but please do contribute on the mailing list. @erica's proposal looks nearly complete but I could not find it submitted on the Swift Evolution Repo and has not been edited for a few weeks (Need some collaborators?). We each have slightly different models with different goals. Here is the Then example code in the three different styles:
Mailing List "Inline Initializer" Restricted to initializers similar to then. However it acts as an initializer compared to code after (possible advantages). Also avoids $0
and has some ideas for handling self.
let label = UILabel {
textAlignment = .Center
textColor = .blackColor()
text = "Hello, World!"
}
@erica's "Method Cascading" More comprehensive "method cascading" proposal. Applies to much more than initializers. Introduces "with" keyword. self
is the label object.
with let label = UILabel() {
textAlignment = .Center
textColor = .blackColor()
text = "Hello, World!"
}
Then Possible syntax proposal, not sure how you were envisioning it but this is similar to how you had it. Maintains self
.
let label = UILabel() then {
label.textAlignment = .Center
label.textColor = .blackColor()
label.text = "Hello, World!"
}
So can we come to an agreement, create a proposal, and submit it for review? Perhaps we can build off of the "Method Cascading" and bring in maintaining self and drop the with
keyword? Perhaps the with
is only required when self is desired?
from then.
Awesome, sounds interesting. What could I do?
from then.
Start a thread on the mailing list to see what other people think, and start writing the proposal using the swift evolution template. Best of luck
from then.
Thank you! I'll take a look soon π
from then.
@devxoul I'd suggest you to take a look at this thread https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151228/005122.html
@jyounus there's a pull request by @basvankuijck that provides an alternate syntax
from then.
@adrfer, Cool. Someone has already done it. How can I lend weight to this suggestion?
from then.
@devxoul perhaps, after reading the related threads, take a look at @erica's https://gist.github.com/erica/eb32feb22ba99629285a
Sure you guys can put together and submit a great proposal π
from then.
Then, or the concept of Inline Initializer, really looked very promising at first glance to me. Because in many projects I set properties of a UI in its lazy initialization.
However, soon I found out that compared to lazy initialization of a var, then
is almost useless in most of my use cases because you cannot reference self
in a then
block but you can do that in lazy initialization blocks.
For example, I can reference another instance var in a controller or a view, or assign the controller itself self
to be the datasource
or the delegate
of a UITableView
or UICollectionView
, when using lazy initialization blocks.
from then.
Chris Lattner asked that it be submitted as a bug report instead of advancing as a proposal. It was. https://bugs.swift.org/browse/SR-160 https://bugs.swift.org/browse/SR-160
-- E
On Jan 4, 2016, at 2:20 AM, Nicholas T. [email protected] wrote:
Then, or the concept of Inline Initializer, really looked very promising at first glance to me. Because in many projects I set properties of a UI in its lazy initialization.
However, soon I found out that compared to lazy initialization of a var, then is almost useless in most use cases because you cannot reference self in a then block but you can do that in lazy initialization blocks.
For example, I can reference another instance var in a controller or a view, or assign the controller itself self to be the datasource or the delegate of a UITableView or UICollectionView, when using lazy initialization blocks.
β
Reply to this email directly or view it on GitHub #2 (comment).
from then.
@wcatron, thanks for asking. Of course I hope it to be adopted to Swift grammar π
from then.
It would be much less a PITA to have something like Kotlin's with() plus IDE support.
from then.
Related Issues (20)
- Apple privacy manifest support HOT 2
- ERROR when upload to AppStore HOT 4
- error: The following binaries use incompatible versions of Swift: HOT 1
- Swift 4.2 support? HOT 1
- UICollectionView doesn't show cells HOT 2
- lazy code HOT 7
- No code prompt in Xcode 10.2 HOT 13
- carthage build HOT 3
- xcodeδΈθ½θͺε¨θ‘₯ε ¨ζη€Ί HOT 5
- Add extension for basic type? HOT 1
- xcode Cannot complete automatically HOT 1
- Question: Why use `then` instead of `with`? HOT 2
- Value of type 'UILabel' has no member 'then' HOT 2
- add @discardableResult HOT 3
- Is Then dead? (abandon-ware?) HOT 2
- iOS 14 Deployment Target Warning HOT 1
- [proposal] Mutating a value type HOT 1
- How to import Then global HOT 1
- Update Package.swift
- Xcode 14 code prompt error HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from then.