Some functions are, essentially, only meant to be transformations of their input and–as such–do not and should not reference any variables other than those passed in. These same functions are not meant to have any effects other than the aforementioned transformation of input. Currently, Swift cannot assist the developer and confirm that any given function is one of these 'pure' functions. To facilitate this, this proposal adds syntax to signal that a function is 'pure'.
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 Equatable | |
@Equatable | |
struct SomeStruct { } | |
let a = SomeStruct() | |
let b = SomeStruct() | |
print(a == b) |
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
#!/bin/sh | |
#################################################### | |
# HEY! set SWIFT_SOURCE_PATH or nothing will work. # | |
#################################################### | |
set -e | |
if [ -z "${SWIFTPM_CONFIGURATION}" ]; then | |
SWIFTPM_CONFIGURATION=lib/swift/pm/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
import Foundation | |
extension JSONSerialization { | |
enum CastingError : Swift.Error { | |
case incompatibleType | |
} | |
static func jsonObject<T>(with data: Data, options: JSONSerialization.ReadingOptions) throws -> T { | |
let anyResult: Any = try jsonObject(with: data, options: options) | |
if let result = anyResult as? T { |
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
//----------------------------------------------------------------------------- | |
// Settings.swift | |
// SwiftInSwift | |
//----------------------------------------------------------------------------- | |
let appName = "SwiftInSwift" | |
let defBlockPrefix = "// DEF-{" | |
let defBlockSuffix = "// }-DEF" |
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
// | |
// GalacticKnight.h | |
// MoreMessage | |
// | |
// Created by TJ Usiyan on 2016/17/08. | |
// Copyright © 2016 Buttons and Lights LLC. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
#import "Person.h" |
This is loosely related to but not meant to 'compete' with the ad hoc enum proposal.
This proposal adds/creates syntax to allow ad hoc creation of enums whose members are strict subsets of explicitly defined enums.
Swift-evolution thread: Discussion thread topic for that proposal
Consider a situation where we have an enum Color
which represents the entire set of colors relevant to your application with many salient methods and operations. We have also declared an enum LCDColorModel
with only three colors, red, blue, green
.
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
struct Expression : IntegerLiteralConvertible { | |
let value: Int | |
init(integerLiteral value: Int) { | |
self.value = value | |
} | |
} | |
struct Subexpression : IntegerLiteralConvertible { | |
let value: 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
extension Int { | |
internal func divMod(other:Int) -> (quotient:Int, modulus:Int) { | |
let quotient = self / other | |
let remainder = self % other | |
if (quotient > 0) || (remainder == 0) { | |
return (quotient, remainder) | |
} else if quotient == 0 && (self > 0) && (other < 0) { | |
let div = quotient - 1 | |
let result = (div * other) - self |
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 Int { | |
internal func divMod(other:Int) -> (quotient:Int, modulus:Int) { | |
let quotient = self / other | |
let remainder = self % other | |
if (quotient > 0) || (remainder == 0) { | |
return (quotient, remainder) | |
} else if quotient == 0 && (self > 0) && (other < 0) { | |
let div = quotient - 1 | |
let result = (div * other) - self |
NewerOlder