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 | |
import Combine | |
private let docsDirURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! | |
@propertyWrapper | |
struct Persisted<Value: Codable> { | |
let fileName: String | |
let defaultValue: Value |
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
tell application "Xcode" | |
set workspaceFile to file of active workspace document | |
tell active workspace document | |
set res to (clean it) | |
repeat | |
if completed of res is true then | |
exit repeat | |
end if | |
delay 1.0 | |
end repeat |
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
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME | |
#define FOR_EACH_1(_what_, _separator_, X) _what_(X) | |
#define FOR_EACH_2(_what_, _separator_, X, ...) _what_(X) _separator_ FOR_EACH_1(_what_, _separator_, __VA_ARGS__) | |
#define FOR_EACH_3(_what_, _separator_, X, ...) _what_(X) _separator_ FOR_EACH_2(_what_, _separator_, __VA_ARGS__) | |
#define FOR_EACH_4(_what_, _separator_, X, ...) _what_(X) _separator_ FOR_EACH_3(_what_, _separator_, __VA_ARGS__) | |
#define FOR_EACH_SEP(_action_, _separator_, ...) GET_MACRO(__VA_ARGS__, FOR_EACH_4, FOR_EACH_3, FOR_EACH_2, FOR_EACH_1)(_action_, _separator_, __VA_ARGS__) | |
#define FOR_EACH(_action_, ...) FOR_EACH_SEP(_action_, ;, __VA_ARGS__) |
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
@interface ArchivesEasy: NSObject <NSCoding> | |
@end | |
@implementation ArchivesEasy | |
-(id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
if (self = [super init]) { | |
[self enumeratePropertiesWithBlock:^(NSString *key, id value) { | |
[self setValue:[aDecoder decodeObjectForKey:key] forKey:key]; |
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
public class AsyncOperation: NSOperation { | |
enum State { | |
case Pending | |
case Executing | |
case Finished | |
case Cancelled | |
var keyValueCodingKeys: [String] { | |
switch 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
// Setting up the stack | |
NSString* libraryDir = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject]; | |
NSString* storePath = [libraryDir stringByAppendingPathComponent:@"store.sqlite"]; | |
NSURL* storeURL = [NSURL fileURLWithPath:storePath]; | |
NSURL* momURL = [[NSBundle mainBundle] URLForResource:@"EmploymentModel" withExtension:@"momd"]; | |
NSManagedObjectModel* mom = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL]; | |
NSPersistentStoreCoordinator* psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom]; | |
NSDictionary* storeOptions = @{NSMigratePersistentStoresAutomaticallyOption: @YES, |
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
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
// insert code here... | |
NSError* error = nil; | |
NSString* textString = [NSString stringWithContentsOfFile:@"/path/to/some/file.txt" | |
encoding:NSUTF8StringEncoding | |
error:&error]; | |
if (textString == nil) { | |
NSLog(@"Something went wrong with reading the file: %@", error); | |
} |
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 Stack<T> { | |
let values: [T] | |
init(_ v: [T] = [T]()) { | |
self.values = v | |
} | |
func push(elem: T) -> Stack<T> { | |
let newValues = [elem] + self.values | |
return Stack<T>(newValues) |
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
infix operator <- { associativity right precedence 140 } | |
infix operator |? { associativity right precedence 140 } | |
func |? <S>(source: [S], predicates: [(s: S) -> Bool]) -> [S] { | |
var ps = predicates | |
return count(ps) > 0 ? (filter(source, ps.removeLast())) |? ps : source | |
} | |
func <-<S, T>(transform: (s: S) -> T, source: [S]) -> [T] { | |
return map(source, transform) |
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
@interface ArchivesEasy : NSObject | |
@end | |
@implementation ArchivesEasy | |
-(id)initWithCoder:(NSCoder *)aDecoder | |
{ | |
if (self = [super init]) { | |
[self enumeratePropertiesWithBlock:^(NSString *key, id value) { | |
[self setValue:[aDecoder decodeObjectForKey:key] forKey:key]; | |
}]; |
NewerOlder