Skip to content

Instantly share code, notes, and snippets.

View RuiAAPeres's full-sized avatar
💭
🏔🏃‍♂️

Rui Peres RuiAAPeres

💭
🏔🏃‍♂️
View GitHub Profile
Process: Xcode [91355]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 8.3 (12169)
Build Info: IDEFrameworks-12169000000000000~2
App Item ID: 497799835
App External ID: 821487965
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [91355]
Process: Xcode [50680]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 8.3 (12169)
Build Info: IDEFrameworks-12169000000000000~2
App Item ID: 497799835
App External ID: 821487965
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [50680]
Process: Xcode [50464]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 8.3 (12169)
Build Info: IDEFrameworks-12169000000000000~2
App Item ID: 497799835
App External ID: 821487965
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [50464]
//: Playground - noun: a place where people can play
import Cocoa
enum Symbol {
case MathOperator(Operator)
case MathParenthesis(Parenthesis)
init?(symbol: Character) {
@RuiAAPeres
RuiAAPeres / converter.swift
Created May 9, 2016 11:41
Quick & Dirty txt2JSON converter
#!/usr/bin/env xcrun swift
import Foundation
func buildFullPath(fileName: String) -> String {
let cwd = NSFileManager.defaultManager().currentDirectoryPath
let urlCwd = NSURL(fileURLWithPath: cwd)
if let urlPath = NSURL(string: fileName, relativeToURL: urlCwd) {

There is retain cycle between the Signal (a Signal is created when you start the producer, hence the name: SignalProducer) and the observer, when you use methods of the family start....

You have three ways to break this cycle:

  • You dispose of the SignalProducer (if you notice, you get a Disposable, when you use a start...). You should avoid doing this, as it goes against RAC best practises
  • You have a way to manipulate the SignalProducer. In your case you do have, by sending complete to the Observer.
  • You use methods like take, takeWhile, until, which will terminate the SignalProducer. This is the prefered way.

Regarding the dispatch. Try this in your viewDidLoad:

networkResult.map { $0.count }.map(String.init).startWithNext {[weak self] numberOfResults in
self?.myLabel = numberOfResults
}
myLabel.rac_text <~ networkResult.map { $0.count }.map(String.init)
class TableDataSource: UITableViewDataSource {
let viewModels: [ViewModel]
init(viewModels: [ViewModel]) {
self.viewModels = viewModels
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
1. The work should only be started when we spend more than 0.5s in the ViewController
2. Check if there is data in the cache
2.1 Success: Show it and start an internet request if the cache is outdated
2.1.1 Success: Show the data
2.1.2 Failed: Silently fail
2.2 Fail: Try to get data from the internet
2.2.1 Success: Show it
2.2.2 Fail: Show the error
3. Every 5 minutes start internet request check, if cache is outdated && ViewController is visible
3.1 Success: Show the data