maomao
August 2, 2019, 7:42am
1
I have a question about some keyword and body
When you create a struct and you have to add them in the struct.
Does anyone know why we have to and what does some keyword mean?
Thanks
Hi @maomao ,
You might want to read up on Opaque return, this is the opposite of Generics. The easiest and simplest way to describe some is that it expects a return to be of a particular type. In SwiftUI everything is a View and therefore the return type expects that it will be a View of some type. Not specifying a Button, Text, or another specific type.
That’s the best in short explanation, I hope that helps
cheers,
1 Like
maomao
August 5, 2019, 9:25am
3
Thank jay I got it haha. What does Generics and Opaque mean?
Hi @maomao ,
No problems, here’s the proposal about Opaque Return types from Apple
# Opaque Result Types
* Proposal: [SE-0244](0244-opaque-result-types.md)
* Authors: [Doug Gregor](https://github.com/DougGregor), [Joe Groff](https://github.com/jckarter)
* Review Manager: [Ben Cohen](https://github.com/airspeedswift)
* Status: **Implemented (Swift 5.1)**
* Implementation: [apple/swift#22072](https://github.com/apple/swift/pull/22072)
* Toolchain: https://github.com/apple/swift/pull/22072#issuecomment-483495849
* Previous revisions: ([1](https://github.com/apple/swift-evolution/commit/e60bac23bf0d6f345ddb48fbf64ea8324fce79a9))
* Previous review threads: https://forums.swift.org/t/se-0244-opaque-result-types/21252
* Decision Notes: [Rationale](https://forums.swift.org/t/se-0244-opaque-result-types-reopened/22942/57)
## Introduction
This proposal is the first part of a group of changes we're considering in a [design document for improving the UI of the generics model](https://forums.swift.org/t/improving-the-ui-of-generics/22814). We'll try to make this proposal stand alone to describe opaque return types, their design, and motivation, but we also recommend reading the design document for more in-depth exploration of the relationships among other features we're considering. We'll link to relevant parts of that document throughout this proposal.
This specific proposal addresses the problem of [type-level abstraction for returns](https://forums.swift.org/t/improving-the-ui-of-generics/22814#heading--missing-type-level-abstraction). Many libraries consist of composable generic components. For example, a graphics library might provide primitive types for basic shapes:
```swift
protocol Shape {
This file has been truncated. show original
maomao
August 6, 2019, 9:47am
5
Thanks I will take a look I realised that Jay is from Melbourne as well haha and I bought Swift book here.
@maomao , cool have we met at Cocoaheads or otherwise?
maomao
August 7, 2019, 11:12am
7
not yet I think we will meet soon
uwilly
August 9, 2019, 6:51am
8
The some keyword is to say you function or property will always return the same actually type, for example if you declare a method that returns some Equatable , you won’t return Float on some calls and Int on others, without that there is no way to do an == between the result of two calls to your function because there is no way for the compiler to know if they are both of the same, since they could be any Equatable.
1 Like
system
Closed
January 15, 2020, 11:42pm
9
This topic was automatically closed after 166 days. New replies are no longer allowed.