Skip to content

Instantly share code, notes, and snippets.

import Foundation
import SwiftUI
import Charts
import os
struct DataPoint: Identifiable {
var id: UUID
var interval: Double
var iteration: Int
}
@crazytonyli
crazytonyli / main.swift
Created February 15, 2023 09:40
Update in another context
// To run this code:
// 1. Create a macOS playground from Xcode.
// 2. Copy below code into the playground.
// 3. Click the Run button to see the console output.
import Foundation
import CoreData
func createObjectModel() -> NSManagedObjectModel {
let nameAttr = NSAttributeDescription()
nameAttr.name = "username"
extension Optional where Wrapped: IntegerType {
func nilOrZero() -> Bool {
switch self {
case .None: return true
case .Some(let value): return value == 0
}
}
}
let text = "01234567890123456789012345678901234567890123456789"
let attributedText = NSMutableAttributedString(string: "\(text)😈😥😈😥😈😥😈😥")
attributedText.setAttributes([NSForegroundColorAttributeName: UIColor.blueColor()],
range: NSMakeRange(0, text.characters.count))
let label = UILabel(frame: CGRectMake(0, 0, 320, 320))
label.attributedText = attributedText
label.lineBreakMode = .ByTruncatingMiddle
label.numberOfLines = 2
label.sizeThatFits(label.bounds.size)
@crazytonyli
crazytonyli / GenericType.swift
Created September 27, 2015 13:14
Get generic type
struct Stack <Element> {
let values: [Element]
var elementType: Any {
get {
return Element.self
}
}
}
@crazytonyli
crazytonyli / ViewController.m
Created June 20, 2015 11:45
-[UICollectionView reloadSections:] does not remove displaying cells from UICollectionView
@import UIKit;
@interface ViewController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@end
@implementation ViewController
@crazytonyli
crazytonyli / EditUserWordController
Created January 25, 2015 14:33
UITextField+BlocksKit crashes this.
void -[EditUserWordController viewDidAppear:](void * self, void * _cmd, bool arg2) {
rbx = self;
var_28 = rbx;
var_20 = *0x2bd50;
LODWORD(rdx) = LOBYTE(arg2) & 0xff;
[[var_28 super] viewDidAppear:rdx];
if ([[rbx targetTextField] delegate] != rbx) {
r15 = *objc_msgSend;
rdx = [[rbx targetTextField] delegate];
[rbx setOriginalTargetDelegate:rdx];