Showing posts with label XCode. Show all posts
Showing posts with label XCode. Show all posts

Thursday, March 30, 2017

PomodoroTimer

Recently I heard about Pomodoro technique and decided to try it out. Basically it's a method for increasing productivity by focusing on work for 25 minutes, having a break, and then repeating.

There is a ton of different ways to measure those 25 mins and breaks. If you type "25 min timer" in Google, you will see countdown above search results. So thoughtful.

I wanted a light and discrete timer but noticeable when it dings. Something like Thyme + ding. I'm sure that there are plenty of nice timers on Internet but till I find the right one, I can make my own and learn something in the process.

Few tomatoes later, and there it is, ticking in navigation bar: PomodoroTimer


When time reaches zero, a short sound plays and notification pops up:


The timer starts when the app is open (cmd + space > PomodoroTimer). And it's killed when tapped on it.

In first tomato I created a new Xcode project from macOS > Cocoa Application template. By default, template app shows blank app window. One way of hiding it is to just delete it from MainMenu.xib. Standard app menu is also unwanted. To disable app menu, new entry Application is agent (UIElement) = YES must be added to Info.plist.

"Blow" is one of sounds located in /System/Library/Sounds.The rest of the code is pretty self explanatory:
import Cocoa

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
    
    private var timer: Timer?
    private let statusItem = NSStatusBar.system().statusItem(withLength: 42)

    func applicationDidFinishLaunching(_ aNotification: Notification) {
        statusItem.action = #selector(terminate)
        
        let startDate = Date()
        let pomodoroInterval: Double = 25 * 60
        
        self.statusItem.title = formatTime(seconds: pomodoroInterval)
        
        timer = Timer.scheduledTimer(withTimeInterval: 0.5,
                                     repeats: true,
                                     block: { [weak self] timer in
            guard let `self` = self else { return }
                                        
            let elapsedTime = Date().timeIntervalSince(startDate)
            let remainingTime = pomodoroInterval - elapsedTime
            
            if remainingTime < 0 {
                timer.invalidate()
                let notification = NSUserNotification()
                notification.title = "Pomodoro!"
                notification.soundName = "Blow"
                NSUserNotificationCenter.default.deliver(notification)
            }
            else {
                self.statusItem.title = self.formatTime(seconds: remainingTime)
            }
        })
    }
    
    func formatTime(seconds: TimeInterval) -> String {
        let minutes = Int(seconds / 60)
        let remainingSeconds = Int(seconds) % 60
        return String(format:"%02d:%02d", minutes, remainingSeconds)
    }

    func terminate() {
        timer?.invalidate()
        NSApp.terminate(self)
    }
}
github   -   binary

Monday, February 16, 2015

dotSwift

dotSwift is a Swift conference, held this year on February 6th. With my colleagues from FIVE, I had the honour to attend this event in gorgeous Théâtre des Variétés in Paris. With the promises given on their website and a sound list of lecturers, expectations were high.

Taken at dotSwift in Paris on November 6th, 2015 by Nicolas Ravelli

One of dotSwift's mottos is "Made by developers, for developers". At the very start of the conference, director Sylvain instructed audience to shake hands and introduce with people around. Interaction between developers was additionally encouraged at coffee breaks. The conference consisted of three blocks of lectures with coffee breaks between blocks.
There were 8 lectures capped on 20 minutes and 5 mini lectures caped on 5 minutes. Twenty minutes is short enough for keeping concentration but barely enough for deeper insight into a topic, not to mention five minute ones. Though, it all depends on lecturer and how he's prepared and there were noticeable differences in quality between lecturers.

Main theme of the conference was state and maturity of the language and accompanying tools like XCode and comparison with its ancestor Objective C. Overall conclusion is that language is mature enough for production but XCode is trailing behind and still has some frustrating bugs. All lectures were recorded and are available on dotSwift's website. I advise watching lectures from Ash Furrow on Swift in production, Daniel Steinberg on comparison between Objective C and Swift, Dimitri Dupuis-Latour on Optionals in Swift and Kyle Fuller on Functional programming.
After the conference, main sponsor BlaBlaCar paid a round in nearby French Beer Factory and socializing continued till late hours.
Next day, there was a workshop organized on a subject of building frameworks with Swift. It was available only to first 30 people who registered via external page and a lot of people ended on a waiting list.

This was a first dotSwift conference and there is a space for improvements. Inspiration should be WWDC. Themes should be more distinct. Specific lectures like Core Bluetooth can't be fitted in just five minutes. It would be nice to have more than one workshop. Updates and news should be visible on official website, not just on Twitter. With all that said, it was an interesting conference with several great lecturers that I mentioned above. I recommend it.