Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Git gud!

Leo superarts

💭
Git gud!
View GitHub Profile
View .gitignore
# Xcode
*/build/*
build/
profile
*.moved-aside
DerivedData
.idea/
*.hmap
*.xcuserstate
*.xccheckout
@superarts
superarts / LFTableController
Last active Aug 29, 2015
Table controller.
View LFTableController
override func viewDidLoad() {
super.viewDidLoad()
lf_actionReload()
}
override func lf_actionReload() {
var array: Array<LTDictStrObj> = [ [
"title": "Title 1",
"desc": "Description",
], [
@superarts
superarts / MBProgress+PFObject
Last active Aug 29, 2015
MBProgressHUD+Parse
View MBProgress+PFObject
let obj = PFObject(className: "sg_text")
obj.setObject(text_view!.text, forKey: SG.const.text)
MBProgressHUD.show("Analyzing...", view:view)
obj.saveInBackgroundWithBlock({
(success: Bool?, error: NSError?) in
MBProgressHUD.hideAllHUDsForView(self.view, animated:true)
if error == nil {
LF.log("TEXT saved", obj)
} else {
MBProgressHUD.show(error!.localizedDescription, view:self.view, duration:2)
@superarts
superarts / LFTableController+SearchDisplayController
Created Apr 30, 2015
LFTableController+SearchDisplayController
View LFTableController+SearchDisplayController
class ICSearchController: LFTableController {
var source_search: LFTableDataSource!
//@IBOutlet var search_controller: UISearchDisplayController!
//@IBOutlet var search_bar: UISearchBar!
override func viewDidLoad() {
super.viewDidLoad()
reload_featured()
reload_search()
@superarts
superarts / Swift Mail Composer
Created Jun 29, 2015
Simple Mail Composer in Swift
View Swift Mail Composer
@IBAction func action_report() {
let composer = SVMailComposer()
composer.present(self, subject:SV.s.report_user_title, body:SV.s.report_user_body)
}
class SVMailComposer: MFMailComposeViewController, MFMailComposeViewControllerDelegate {
func present(controller: UIViewController, subject: String, body: String) {
if MFMailComposeViewController.canSendMail() {
mailComposeDelegate = self
setToRecipients(["leo@superarts.org"])
@superarts
superarts / ambiguous-logger.swift
Created Mar 1, 2019
Ambiguous loggers; use clogger and flogger instead
View ambiguous-logger.swift
/// TODO: is something like Loggable.Console / Loggable.File possible in Swift - single namespace inside a target?
// A console logger
protocol ConsoleLoggable {
var clogger: ConsoleLoggerProtocol { get }
}
extension ConsoleLoggable {
var clogger: ConsoleLoggerProtocol {
@superarts
superarts / extension-computed-property.swift
Created Mar 4, 2019
Extension Computed Property Behavior
View extension-computed-property.swift
// To maintain state of extension computed property, use static variable
// A console logger
protocol ConsoleLoggable {
var logger: ConsoleLoggerProtocol { get }
}
extension ConsoleLoggable {
var logger: ConsoleLoggerProtocol {
@superarts
superarts / test-target.swift
Last active Mar 4, 2019
Provide test only feature in Test target
View test-target.swift
protocol ProductionFeatureProtocol: TestFeature1, TestFeature2 {
}
struct DefaultProductionFeature: ProductionFeatureProtocol {
}
protocol TestFeature1 {
func testOnly1()
@superarts
superarts / struct-in-static-func
Created May 7, 2019
`static func` in `struct` is not pure
View struct-in-static-func
struct TestStruct {
static var staticVar = 1
static func staticFunc() {
staticVar = 2
}
}
@superarts
superarts / pure-func-in-enum
Created May 7, 2019
Pure Functions in Swift Enum
View pure-func-in-enum
protocol PureEnumProtocol {
func test()
}
enum PureEnum: PureEnumProtocol {
static var v = 1 // Still possible
//var v = 1 // Enums must not contain stored properties
func test() {
//v = 2 // Impossible