-rw-r--r-- 2.4K Apr 25, 2016 · 430F62F · ~2 min

Carthage vs. CocoaPods

carthage cocoapods xcode

A couple of thoughts on Carthage compared to CocoaPods.

What Carthage has in common with CocoaPods:

  • You create a Podfile for CocoaPods. For Carthage, you need to create a Cartfile.
  • In both cases, you can specify an exact dependency version and a specific git repository.
  • After installing dependencies, CocoaPods creates Podfile.lock and Carthage creates Cartfile.resolved so that exact dependency/library versions can be installed.
  • Both CocoaPods and Carthage are quite easy to install with a single console command.

Cons:

  • All dependencies have to be added manually to the project and the Build Phases section. You only do it once, but it is still manual, unlike CocoaPods, which generates the workspace on its own. On the one hand this is inconvenient, on the other, CocoaPods has simply spoiled us. For example, in the Node.js world it is not enough to do npm install package, you still have to include the dependency where needed via require.
  • Less choice. Less popularity. CocoaPods is older, more popular, and many libraries were distributed through CocoaPods. Many are still distributed only through it, including, for example, SDKs from Google. With Carthage it is easier to find something relatively fresh. On the plus side, it is usually available via CocoaPods, Carthage, and even Swift Package Manager.

Pros:

  • Dependencies are built once. On any project build, the libraries and dependencies are not rebuilt, even if you clear all caches and do all the cleans. As a result, every build is faster.
  • No extra .xcworkspace file is created, and the project file remains untouched. Workspace creation in recent CocoaPods versions has been buggy for almost half a year already and creates that workspace in a way that makes the project fail to build, so you have to go in manually and fix something. For example, the header search path.
  • When updating a dependency to the latest version, again, the project file is not touched. The dependencies are simply rebuilt; they are already added to the project.
  • You can build a dependency for all platforms at once, or for a specific one, for example tvOS.
  • CocoaPods has a central repository. If it goes down, nothing will work. Carthage does not have that; it just pulls dependencies from GitHub. On the one hand that is still a kind of central repository, but without the middle layer, and the chances of it withstanding load are higher.
[↵] open page carthage-vs-cocoapods.md
-rw-r--r-- 307B Apr 22, 2016 · 4E22F08 · ~1 min

Converting a UTC date with milliseconds from String to NSDate in Swift

swift шпаргалки

To convert a date from text into NSDate from a slightly non-standard format with milliseconds:

let dateString = "2016-04-22T17:42:46.762+03:00"

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"

let myDate = dateFormatter.dateFromString(dateString) 
[↵] open page konvertirovanie-utc-daty-s-millisekundami-iz-string-v-nsdate.md
-rw-r--r-- 731B Apr 19, 2016 · 553E35F · ~1 min

CompareShots v1.1

compareshots ios приложения

CompareShots version 1.1 has been released.

What is new: transparency now changes simply by dragging your finger horizontally. One of the users actually asked for this feature in an email. It also makes the transparency change more smoothly.

Besides that, I completely rewrote the app in Swift. So now I have as many as one released project written in it :) But this is only the beginning.

What is surprising is that I submitted the App Store update yesterday, and in less than a day it had already passed Review and been released. I do not remember Apple ever approving an app that fast.

Download

[↵] open page compareshots-v1-1.md
-rw-r--r-- 810B Apr 18, 2016 · E93D4A7 · ~1 min

A log function for Swift that outputs file, method, and line

шпаргалки swift полезное

A cheat-sheet function for logging in Swift:

import Foundation

/**
 A log function that outputs the file, method, and line it was called from. 
 Example usage: DLog("hello")

 - parameter messages: text/objects to print
 - parameter fullPath: path to the calling file
 - parameter line: line number in the file
 - parameter functionName: name of the calling method/function
*/
func DLog(messages: Any..., fullPath: String = #file, line: Int = #line, functionName: String = #function) {
     let file = NSURL.fileURLWithPath(fullPath)
     for message in messages {
          print("\(file.pathComponents!.last!):\(line) -> \(functionName) \(message)")
     }
}

// Example:
DLog("message 1", "message 2")
// YourClass.swift:42 -> someMethod() message 1
// YourClass.swift:42 -> someMethod() message 2
[↵] open page log-funktsiya-dlya-swift-s-vyvodom-fajla-metoda-i-stroki.md
-rw-r--r-- 4.6K Apr 12, 2016 · 6E14506 · ~4 min

Impressions of Assassin's Creed III Liberation

assassin's creed игры

Assassin's Creed III Liberation

[↵] open page vpechatleniya-ot-assassin-s-creed-liberation.md
-rw-r--r-- 1.5K Apr 6, 2016 · EF30922 · ~1 min

A simple console.log with file and line number output in Node.js

node.js javascript полезное шпаргалки

While coding in Node.js, I constantly need to print something to the console. Errors, for example. But for better information it is more convenient to know exactly where the output is coming from. Especially since when I was coding for iOS, I always had such a handy macro at hand, but with Node.js I had to google and dig around, because many examples from Stack Overflow simply crashed on the latest Node.js 5.10.0. They crashed because they used Error.captureStackTrace(err, arguments.callee), and now you need to use NFE.

In the end I made what I wanted. Leaving it here as a cheat sheet.

npm install colors --save

File logger.js:

'use strict';

let colors = require('colors');
colors.enabled = true;

exports.p = function logger(somethingForPrint) {
    somethingForPrint = somethingForPrint || '';
    const originalPrepareStackTrace = Error.prepareStackTrace;

    Error.prepareStackTrace = (error, stack) => { return stack; };

    let e = new Error;
    Error.captureStackTrace(e, logger);

    const stack = e.stack;
    const filename = stack[0].getFileName().split('/').reverse()[0];
    const trace = filename + ':' + stack[0].getLineNumber() + " " + colors.bold.black('%s') + "\n";

    Error.prepareStackTrace = originalPrepareStackTrace;

    console.log(trace, somethingForPrint);
}; 

Use:

const logger = require('../utils/logger');
logger.p('something happened');
// file.js:401 something happened 
[↵] open page prostoj-console-log-s-vyvodom-fajla-i-nomera-stroki-v-node-js.md
makoni@arm1:~/blog$ cd ../page-12/ // ← previous cd ./page-14/ // more posts →