Skip to content

Instantly share code, notes, and snippets.

View Tricertops's full-sized avatar
:octocat:

Martin Kiss Tricertops

:octocat:
View GitHub Profile
@Tricertops
Tricertops / VDM Architecture.md
Last active August 30, 2019 05:28
How we used MVVM architecture and a reactive framework to build our latest iOS app, from theory to actual code examples.

View → Design → Model

iOS applications are usually built with MVC (Model – View – Controller) architecture, which introduces very important concept of separating actual data (Model Layer) and their presentation (View Layer), while the application logic (Controller Layer) stands between them.

View ← Controller → Model

With MVC you typically write most of the code in UIViewController, which usually represents the Controller Layer. View Layer can be easily done in Interface Builder and Model Layer usually doesn’t need a lot of code. The UIViewControleler then holds strong references to both View and Model objects and is responsible for setting them up, handling actions and listening to events.

The problem is, that this middle layer tends to hold too much code and this situation is then jokingly called Massive View Controller. When a single class sets up views, formats data values, handles user input and actions, listens for a bunch of notif

@interface List : NSObject
@property (copy) NSArray *items;
@property (readonly) NSMutableArray *mutableItems;
@end
@implementation List

Values with priority in KeepLayout

Every numeric value used in KeepLayout need to have associated priority. This pair is then passed to the underlying NSLayoutConstraint of Auto Layout.

Before

The KeepValue type was an ordinary struct with .value and .priority, so it had to be created using one of the provided functions:

view.keepWidth.equal = KeepRequired(100); // value 100, priority 1000
@Tricertops
Tricertops / gist:6498d36497d0a66611cc
Created June 11, 2015 17:30
Recursive CFRelese() crash.
NSArray *foundationImmutableArray = @[];
NSArray *coreFoundationArray = (__bridge_transfer NSArray *)CFArrayCreateCopy(NULL, (__bridge_retained CFArrayRef)foundationImmutableArray);
id coreFoundationCopy = [[coreFoundationArray class] new];
coreFoundationCopy = nil; // Recursive CFRelease() crash!
@Tricertops
Tricertops / 1. Text Replacements.md
Last active December 2, 2020 23:56
All the text replacements I use on macOS and iOS.

Text Replacements

iOS: Settings ▸ General ▸ Keyboard ▸ Shortcuts
macOS: System Preferences ▸ Keyboard ▸ Text (drag them to Desktop or drag plist on the table)

Emoji

  • :) 🙂
  • :D 😄 – The most used.
  • ;) 😉
@Tricertops
Tricertops / CGColorConvert.m
Last active August 27, 2015 12:35
Converting colors on OS X between RGB color spaces without clamping their values. Will not work on iOS, because kCGBitmapFloatComponents is not supported.
// © 2015 PixelCut, provided under MIT license.
//! Inputs
CGColorSpace sourceSpace; // Display RGB, Generic RGB, sRGB, any RGB
CGFloat sourceRed; // Can be out of 0..1 range.
CGFloat sourceGreen; // Can be out of 0..1 range.
CGFloat sourceBlue; // Can be out of 0..1 range.
CGColorSpaceRef targetSpace; // Display RGB, Generic RGB, sRGB, any RGB
//! Setup all required values
@Tricertops
Tricertops / VW Test.m
Last active November 3, 2015 09:53
Volkswagen XCTAssert
#undef XCTAssert
#define XCTAssert(expression, ...) \
_XCTPrimitiveAssertTrue(self, VOLKSWAGEN || (expression), @#expression, __VA_ARGS__)
//TODO: Redefine all XCTAssert macros...
#define VOLKSWAGEN 1
- (void)testEmissions
{
@Tricertops
Tricertops / UIColor+DisplayP3HSB.swift
Last active March 31, 2017 14:40
Construct UIColor using HSB components in Display P3 color space.
extension UIColor {
convenience init(displayP3Hue hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat = 1) {
/// HSB to RGB conversion doesn’t depend on color space, so we can use default UIColor space.
let converter = UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1)
var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0
converter.getRed(&red, green: &green, blue: &blue, alpha: nil)
self.init(displayP3Red: red, green: green, blue: blue, alpha: alpha)
@Tricertops
Tricertops / gist:630fa96044b71d8083b9e397f0b84a1c
Last active November 3, 2016 13:37
How to load PaintCode Telekinesis.framework from debugger.
# This will load Telekinesis from debugger (don’t forget to use correct path).
# You can use this debugger command as breakpoint handler on UIApplicationMain.
expr (void *)dlopen("/path/to/Telekinesis.framework/Telekinesis", 0x2)
# You can also check for class "TeleHub", to make sure it’s not loaded twice:
expr (Class)NSClassFromString(@"TeleHub") == nil ? (void *)dlopen("/path/to/Telekinesis.framework/Telekinesis", 0x2) : ((void*)0)
@Tricertops
Tricertops / Appeal.md
Created May 12, 2017 16:56
Appeal to the App Review Board

I ask for repeated approval of version 4.6.1, since it was rejected for features that were previously approved in 4.6.

Version 4.6 added feature that changes app icon based on user’s location. I wrote explanation of this feature in Review Notes and this version was approved by your team. (Full text of Review Notes is embedded at the end.)

Version 4.6.1 didn’t make any changes to previously approved features, it only fixed improtant bugs and improved several UI elements. No change in app icon management was made, but this time, the app was rejected for way it approaches Alternate Icons.

This inconsistency in decisions of App Review Team is troubling for me, because I got two distinct results from submitting basically the same app. Process of reviewing new submissions should take into account previous versions of the app.
Also related, my previous submission of version 4.6.1 was rejected by asking for information which was provided in Review Notes of previous update. I don’t think that should happen. When