Skip to content

Instantly share code, notes, and snippets.

View thepost's full-sized avatar

Mike Post thepost

View GitHub Profile
import { appTheme } from 'themes/ThemeInterface';
const Text = styled.Text`
font-family: 'AkkuratPro-Regular';
color: ${appTheme.colors.textPrimary};
font-size: 12;
`;
const H1 = styled(Text)`
font-size: 36;
const BoxRoot = styled.View<IBoxProps>`
width: ${props => props.size};
height: ${props => props.size};
padding: ${props => props.theme.lateralPadding || 0}px;
background-color: ${props => props.backgroundColor};
`;
BoxRoot.defaultProps = {
size: 200,
backgroundColor: 'transparent',
import React, { FC } from 'react';
import { ViewProps } from 'react-native';
import styled from 'styled-components/native';
import { ThemeInterface } from 'themes/ThemeInterface';
interface IBoxProps extends ViewProps {
theme: ThemeInterface;
size?: number;
borders?: boolean;
borderThickness?: number;
import React, { FC } from 'react';
import { ViewProps } from 'react-native';
import styled from 'styled-components/native';
import { ThemeInterface } from 'themes/ThemeInterface';
interface IBoxProps extends ViewProps {
theme?: ThemeInterface;
borders?: boolean;
}
@thepost
thepost / Box.tsx
Last active May 3, 2019 15:45
Gist 1 for styled-components tutorial
import React, { FC } from 'react';
import { ViewProps } from 'react-native';
import styled from 'styled-components/native';
import { ThemeInterface } from 'themes/ThemeInterface';
interface IBoxProps extends ViewProps {
theme?: ThemeInterface;
borders?: boolean;
}
extension ModelController {
func delete(by objectID: NSManagedObjectID) {
let managedObject = context.object(with: objectID)
context.delete(managedObject)
}
func delete<M: NSManagedObject>(_ type: M.Type, predicate: NSPredicate?=nil) {
extension ModelController {
func save() {
if context.hasChanges {
do {
try context.save()
} catch {
let nserror = error as NSError
fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
}
extension ModelController {
func total<M: NSManagedObject>(_ type: M.Type) -> Int {
let entityName = String(describing: type)
let request = NSFetchRequest<M>(entityName: entityName)
do {
let count = try context.count(for: request)
return count
extension ModelController {
func add<M: NSManagedObject>(_ type: M.Type) -> M? {
var modelObject: M?
if let entity = NSEntityDescription.entity(forEntityName: M.description(), in: context) {
modelObject = M(entity: entity, insertInto: context)
}
return modelObject
import CoreData
public class ModelController {
typealias VoidCompletion = () -> ()
// MARK: - Properties
private var modelName: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String ?? ""