This file contains hidden or 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
# UI framework rules for SwiftUI | |
1. State Management: | |
- Use `@Observable` for reference types holding business logic and app state. | |
- Use `@Bindable` properties within @Observable classes so SwiftUI views can bind directly to them. | |
- Avoid `@State` for view model observation, rely on `let model: MyModel` instead. | |
- Pass dependencies via initialisers rather than as global singletons. | |
- Use `@Environment` for app-wide or large-scope states. | |
- `@State` is only for view-local state. | |
- Use `@Binding` only if necessary |
This file contains hidden or 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
// | |
// Regex.swift | |
// | |
extension String { | |
public var byStrippingFormatCharacters: String { | |
var result = self | |
// #H1, #H2 | |
Regex.headerRegex.matches(in: result, options: [], range: NSMakeRange(0, result.count)).forEach { |
This file contains hidden or 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
func collectionView(collectionView: NSCollectionView, draggingSession session: NSDraggingSession, willBeginAtPoint screenPoint: NSPoint, forItemsAtIndexPaths indexPaths: Set<NSIndexPath>) { | |
if let indexPath = draggingIndexPaths.first, | |
item = collectionView.itemAtIndexPath(indexPath) { | |
draggingItem = item // draggingItem is temporary instance variable of NSCollectionViewItem | |
} | |
} | |
func collectionView(collectionView: NSCollectionView, draggingSession session: NSDraggingSession, endedAtPoint screenPoint: NSPoint, dragOperation operation: NSDragOperation) { | |
draggingItem = nil |
This file contains hidden or 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
func animateView() { | |
CATransaction.begin() | |
CATransaction.setCompletionBlock { [unowned self] in | |
self.removeFromSuperview() | |
} | |
let rotationAtStart = view.layer?.valueForKeyPath("transform.rotation.x") as? NSNumber | |
let rotate = CABasicAnimation(keyPath: "transform.rotation.x") | |
rotate.duration = 0.3 |
This file contains hidden or 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
#if os(iOS) | |
import Cocoa | |
public struct HNColor { | |
public static var DarkGray: UIColor = UIColor(white: 36/255, alpha: 1) | |
public static var DeepGray: UIColor = UIColor(white: 27/255, alpha: 1) | |
} | |
#endif |
This file contains hidden or 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
#if os(OSX) | |
import Cocoa | |
#endif | |
#if os(iOS) | |
import UIKit | |
#endif |
This file contains hidden or 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
# Uncomment this line to define a global platform for your project | |
platform :osx, '10.11' | |
use_frameworks! | |
target 'AppName' do | |
end | |
target 'AppNameTests' do | |
This file contains hidden or 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
// | |
// ShiftClickGestureRecognizer.swift | |
// | |
// Created by Harry Ng on 27/1/2016. | |
// Copyright © 2016 STAY REAL. All rights reserved. | |
// | |
import Cocoa | |
class ShiftClickGestureRecognizer: NSClickGestureRecognizer { |
NewerOlder