title | synopsis | tags | share_image | episode | book | collection | author |
---|---|---|---|---|---|---|---|
Swift Tip: Protocols vs. Values |
Extensible in different ways |
news |
/images/blog/2019-05-13-protocols-vs-functions.png |
19 |
advanced-swift |
networking |
chriseidhof |
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 ContentView: View { | |
@State var color: Color = .Pastel.random() | |
var body: some View { | |
Rectangle() | |
.foregroundColor(color) | |
.onTapGesture { | |
color = .Pastel.random() | |
} | |
} |
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 SwiftUI | |
let colors = [ | |
Color.pink, | |
Color.blue, | |
Color.green, | |
Color.orange, | |
Color.purple, | |
Color.black, | |
] |
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 URLRequest { | |
private func quote(_ string: String) -> String { | |
// handle all the regular escape sequences | |
var text = string.replacingOccurrences(of: "\\", with: "\\\\") | |
text = text.replacingOccurrences(of: "\"", with: "\\\"") | |
text = text.replacingOccurrences(of: "\n", with: "\\\n") | |
text = text.replacingOccurrences(of: "\r", with: "\\\r") | |
text = text.replacingOccurrences(of: "\t", with: "\\\t") | |
return "\"\(text)\"" | |
} |
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
/* | |
* CFArray+Sequence.swift | |
* Alexis Aubry Radanovic | |
*/ | |
import Foundation | |
import CoreFoundation | |
extension CFArray: Sequence { | |
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
We're working on supporting Bitcode in PSPDFKit but hit a blocking issue with OpenSSL (latest 1.0.2d). | |
We're using a script that downloads and builds OpenSSL into fat static libraries for both Mac and iOS. I've put the gist here: | |
https://gist.github.com/steipete/ce09ba176a4b8ef66b2d/bf053eab1c0f8494dcd3748079543c4ed4367b9c | |
Enabling Bitcode should be as easy as adding `-fembed-bitcode` as clang flag according to this entry. That's exactly what I did. | |
Now things build, but the script eventually stops with this error: | |
ld: could not open bitcode temp file: ../libcrypto.a(aes-x86_64.o) for architecture x86_64 |
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
// | |
// CollectionViewDataSource.swift | |
// Khan Academy | |
// | |
// Created by Andy Matuschak on 10/14/14. | |
// Copyright (c) 2014 Khan Academy. All rights reserved. | |
// | |
import UIKit |
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/bash | |
# | |
# Usage: script/sort-xcodeproj to sort all root-level Xcode projects. | |
# This helps keep the Xcode project layout neat and consistent while | |
# aiding in the prevention of [merge conflicts][mc]. | |
# | |
# [mc]: http://danieltull.co.uk/blog/2013/09/05/easier-merging-of-xcode-project-files/ | |
SCRIPT_DIR=$(dirname "$0") | |
cd "$SCRIPT_DIR/.." |
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
NSManagedObjectContext *contextOne = ...; | |
NSArray *objects = ...<result of fetch request on contextOne... | |
NSManagedObjectID *objectID = objects[0].objectID; | |
NSManagedObjectContext *contextTwo = ...; | |
id object = [contextTwo existingObjectWithID:objectID error:nil]; // returns the right object | |
NSAssert(![object.objectID isTemporaryID]); // passes | |
id otherObject = [contextTwo objectWithID:objectID]; // always returns an object, should be the right object | |
NSAssert(![otherObject.objectID isTemporaryID]); // fails! |
NewerOlder