- Proposal: SE-0159
- Authors: Brian King
- Review Manager: TBD
- Status: Awaiting review
- Bug: SR-1762
This proposal disallows the final
keyword when declaring functions in protocol
This proposal disallows the final
keyword when declaring functions in protocol
Brians-MBP:SketchyCode bking$ git status | |
On branch master | |
Your branch is up-to-date with 'origin/master'. | |
Changes to be committed: | |
(use "git reset HEAD <file>..." to unstage) | |
new file: SketchyCode/SketchyCode/Info.plist | |
new file: SketchyCode/SketchyCode/JSONBuilder/SketchClass.stencil | |
new file: SketchyCode/SketchyCode/JSONBuilder/SketchTypeBuilder.swift | |
new file: SketchyCode/SketchyCode/SketchClasses+Helpers.swift |
This proposal enhances protocol implementation safety. It incorporates two keywords that cooperate with compiler checks to limit "near miss" implementation errors and accidental member overrides. This is a strictly syntactic system intended to provide greater safety at compile time, and would not affect existing compiled code bases. *** BK: Saying it does not affect implies to me that it's optional. ***
Describing dispatch scenarios is confusing, and spelling out the code is wordy. In an attempt to keep this document clear and compact, I'll use a short hand to describe the declaration scenarios.
Short hand:
T = Type (class / struct / enum)
ST = Sub Type (only applies to classes)
P = Protocol
M1.T = Type from the other module
import Foundation | |
class FooFun { | |
@objc | |
func bat() { | |
println("bat") | |
} | |
} | |
class Foo :NSObject { |
protocol AST { | |
associatedtype NodeType = Self | |
var children: [NodeType] { get } | |
} | |
extension AST where NodeType: AST, NodeType.NodeType == NodeType { | |
func traverse(check: (Self.NodeType) -> Bool) { | |
for child in children { | |
if check(child) { | |
child.traverse(check: check) |
// | |
// KSDIdlingWindow.h | |
// | |
// Created by Brian King on 4/13/10. | |
// Copyright 2010 King Software Designs. All rights reserved. | |
// | |
// Based off: | |
// http://stackoverflow.com/questions/273450/iphone-detecting-user-inactivity-idle-time-since-last-screen-touch | |
// |
(lldb) bt | |
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) | |
* frame #0: 0x000000010051d687 libswiftCore.dylib`::_swift_release_dealloc(object=0x0000000101509670) at HeapObject.cpp:558 | |
frame #1: 0x0000000100528166 libswiftCore.dylib`bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrementSlow<(this=0x0000000101509678, oldbits=(bits = 0), dec=1)0, (swift::PerformDeinit)1>(swift::RefCountBitsT<(swift::RefCountInlinedness)1>, unsigned int) at RefCount.h:1046 | |
frame #2: 0x0000000100526b8c libswiftCore.dylib`bool swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::doDecrement<(this=0x0000000101509678, dec=1)0, (swift::PerformDeinit)1>(unsigned int) at RefCount.h:1104 | |
frame #3: 0x0000000100517381 libswiftCore.dylib`::_swift_release_(swift::HeapObject *) [inlined] swift::RefCounts<swift::RefCountBitsT<(swift::RefCountInlinedness)1> >::decrementAndMaybeDeinit(this=0x0000000101509678, dec=1) at RefCount.h:907 |
// Ignore the first few unknowns: | |
struct MSAssetCollection { | |
let gradients: [<<Unknown>>] | |
let images: [<<Unknown>>] | |
let colors: [MSColor] | |
let imageCollection: MSImageCollection | |
} | |
struct MSImageCollection { |
/// Codable doesn't do a good job of Dictionaries with non-String keys. | |
/// This property wrapper fixes things. | |
/// | |
/// Context: https://oleb.net/blog/2017/12/dictionary-codable-array/ | |
/// Tests: StringKeyDictionaryTests | |
@propertyWrapper | |
public struct StringKeyDictionary<Key: RawRepresentable & Hashable & Decodable, Value: Codable>: Codable where Key.RawValue == String { | |
public var wrappedValue: [Key: Value] | |
public init(wrappedValue: [Key: Value]) { | |
self.wrappedValue = wrappedValue |