Coder Social home page Coder Social logo

parksandrecreation's Introduction

ParksAndRecreation

Various Swift playgrounds, for fun and for profit.

Index

Base classes for tracking work inside OperationQueue that takes place outside of the queue, without causing a thread to hang by waiting. Includes an Operation for wrapping URLSessionTask.

Inspired by and lovingly nerd-sniped by @jaredsinclair.

A simple class for using Unicode to encircle some characters or single-digit numbers in the iOS system font, inspired by this tweet. Includes a gallery live view for demonstration.

Badge gallery

Derived from @krzyzanowskim's blog post: use a protocol extension to split any collection into a group of slices. Think flatten(), but in reverse.

Use TextKit to perform custom truncation with high performance. Also an example of creating building a drop-in UILabel backed by TextKit.

Use DispatchSource to coalesce calls that shouldn't be called more than once per runloop iteration, like UI reconfiguration.

A fast recursive-descent parser for CSVs and similarly structured data inspired by Matt Gallagher.

Based on a technique used in the iOS 10 Music app, subclasses of UICollectionView and UITableView that derive their intrinsic content size and visible bounds from their content and context, respectively, when isScrollEnabled = false. This is similar to behavior on UITextView. It enables, for instance, putting three collection views in a stack view in a scroll view with low performance impact.

Mathematical operators and idiomatic bridging for Core Graphics types.

An extension on UIViewController providing a keyboardLayoutGuide property. The layout guide normally mirrors the safe area, but automatically shrinks to avoid the keyboard. It also allows emulating the automatic content keyboard insets applied to UICollectionViewController and UITableViewController. It avoids the pitfalls of most keyboard avoidance implementations, like correctly syncing animations.

The Swift 3 version requires iOS 9.0.

Create your own sun-, time-, or light/dark-based wallpaper for macOS Mojave.

Wallpaper changing from light to dark

Playground requires Swift 4.2 beta and macOS Mojave.

Formatted localization using Swift string formatting. Introduces localize with a similar prototype to NSLocalizedString:

func localize(text: LocalizableText, tableName: String? = default, bundle: NSBundle = default, value: String = default, comment: String)

What's a LocalizableText? It's an intermediary type that deconstructs interpolation segments for use with string formatting. But that's not important, what's important is that it's literal convertible:

let filesLeft = 4
let filesTotal = 5
let labelText = localize("test-progress-\(filesLeft)-of-\(filesTotal)", comment: "Help text used for a positional description")

And in your Localizable.strings, just like in Cocoa:

/* Help text used for a positional description */
"test-progress-%@-of-%@" = "%1$@ of %2$@ remaining.";

All placeholders should be %@ on the end of the key, and be represented positionally, i.e., with %1$@, %2$@, and so on.

A helper for performing type-safe multicast callbacks. The result is a lot like using UIControl, but for weakly held objects and without unsafe selectors.

Heavily inspired by this blog post from @ole.

A simple glueing-together of Dictionary and Array into an ordered, hashed data structure. Useful if your keys are indeed already Hashable, but doesn't have great performance; insertion and removal tend towards the worst of both structures. If you have any alternative, prefer something B-Tree based instead.

"Size classes are fine, but I can't customize them!" Yeah, you can! By inspecting what Mobile Safari does, you can do the same, using override trait collections.

Emulating the calculation of UIView.readableContentGuide.

Simple Swift bridging for NSRegularExpression, as well as general patterns to go from String.UTF16View and Range<String.UTF16Index> to NSString and NSRange.

Line, paragraph, sentence, and word views for Swift.String, providing a more idiomatic take on StringProtocol.getLineStart(_:end:contentsEnd:for:) and StringProtocol.getParagraphStart(_:end:contentsEnd:for:) as Swift collections.

Array(string.lines) // -> [Substring]

Experiment adding an accessory to UITabBarController, like Now Playing in Music.​app.

Tab bar palette gallery

  • Drop-in UITabBarController with a paletteViewController property
  • Palette is forwarded appearance (i.e., viewWillAppear) and trait collection events
  • Palette supports sizing through Auto Layout and preferredContentSize and animating changes to those
  • Can animate in, out, and between palette changes
  • Detects and supports highlighting of palette background on tap
  • Supports Interface Builder, 3D Touch, and modal view controllers

Spawn and join with a pthread_t returning a result from a Swift function, inspired by the Swift stdlib. See also Thread.init(block:) from iOS 10 and up.

Conveniences for using Core Graphics types in UI programming, such as retina-friendly rounding and equation operators that account for floating point inaccuracy.

Showing off the simple power of Swift iterators by performing breadth-first travel through the trees created by UIView, UIViewController, and CALayer.

Obsoleted in Swift 4

If you're hurting for Objective-C's MyClassType<SomeProtocolType> *, try this on for size.

Obsoleted in Swift 4 by MyClass & SomeProtocol syntax.

A simple bridge to bridges concrete value types into NSCoding.

Obsoleted in Swift 4 by Codable.

Obsoleted in Swift 3

Use protocol extension to achieve simpler Core Data, like MyManagedObject(context:).

An idiomatic Data<T>, representing any buffer (contiguous or discontiguous) of numeric elements. Part NSData, part dispatch_data_t, Data is useful for low-level byte-based APIs in Swift, such as crypto and string parsing.

Create one with an array:

let data = Data<UInt8>(array: [ 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 ])

And enumerate through it in constant time:

for byte in data {
	...
}

Made with lots of help from @a2.

Even though it's been fixed in 2.1, Swift 2.0 has a rather ugly bug with wrapped dispatch_block_t types. Fix it with a C few tricks and a rational DispatchBlock type.

parksandrecreation's People

Contributors

a2 avatar cbkeur avatar zwaldowski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.