We propose to enable Swift code to retrieve the memory location of any directly addressable stored property in a class instance as an UnsafeMutablePointer
value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//: Playground - noun: a place where people can play | |
import UIKit | |
protocol MagicProtocol { | |
} | |
extension MagicProtocol { | |
mutating func magic(xyzzy: Self) { | |
// Mutating methods defined in a protocol extension can mutate `self` even if | |
// the protocol is implemented by a class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public func <<(num: Double, exp: Int) -> Double { | |
return num * Double(1 << exp) | |
} | |
let s = (0.5 << 5) - 1 | |
print(s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array where Element: Comparable { | |
func clamp(from lowerBound: Element, to upperBound: Element) -> Array { | |
return self.map { min(upperBound, max(lowerBound, $0)) } | |
} | |
} | |
let clamped = [0, 1, 2, 3, 4, 5, 6].clamp(from: 2, to: 4)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am lorentey on github. | |
* I am lorentey (https://keybase.io/lorentey) on keybase. | |
* I have a public key whose fingerprint is 086D 2046 8C31 E936 754F C0C7 E9EA 32A8 0FB2 7A3F | |
To claim this, I am signing this object: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Sink { | |
func receive() | |
} | |
protocol Source { | |
associatedtype Value | |
func subscribe(_ sink: Sink) -> Int | |
func unsubscribe(_ token: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Sink { | |
associatedtype Value | |
func receive(_ value: Value) | |
} | |
// This assumes Generalized Existentials are a thing | |
// https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generalized-existentials | |
typealias AnySink<Value> = Any<Sink where .Value == Value> | |
protocol Source { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@objc class Person: NSObject { | |
var _firstName: String = "John" | |
var _lastName: String = "Smith" | |
dynamic var firstName: String { get { return _firstName } set { _firstName = newValue } } | |
dynamic var lastName: String { get { return _lastName } set { _lastName = newValue } } | |
dynamic var name: String { return "\(firstName) \(lastName)" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hello | |
This sample file contains examples of all kinds of data that can be stored in a pile. | |
All text up to the first line that consists of a #pile version directive is ignored by the parser. | |
Feel free to write anything here. | |
This is how all text piles start: (The "1" is the version number of the file format.) | |
#pile:1 |
- Author: Karoy Lorentey
- Version: 2020-04-13/1
- Document URL: https://gist.github.com/lorentey/cf8703b5974ebe8f85cfb92a6628880d
- Forum Thread: https://forums.swift.org/t/low-level-atomic-operations/34683
- Implementation:
- [swiftlang/swift#30553][implementation] (Atomic operations)
- [swiftlang/swift#26969][constantPR] (Constant-constrained ordering arguments)
OlderNewer