-rw-r--r-- 1.4K May 21, 2018 · 831A704 · ~2 min

JPG to HEIF converter

jpg to heif converter приложения apps macos open source

JPG to HEIF converter

Today I've decided to experiment with HEIF that was introduced by Apple with macOS 10.13 and iOS 11. They said that it has the same quality with much lower file size.

It's supported in the latest versions of macOS and iOS and last models of iPhone can take pictures in that format.

I'm thinking about compressing my home archive of photos and videos. I was experimenting with HEVC (H.265) and results were great - I had reduced the size of my videos by encoding them to HEVC with an awesome util called HandBrake.

I found the only way to convert JPG to HEIF (which has HEIC extension). It's possible with the Preview app from macOS. But it would be interesting for me if I can do it by myself in Swift. So I did :)

My folder with 64 photos from my action camera was 203 mb in JPG format. And it's only 31.3 mb in HEIC.

macOS and iOS support it from the box. And what's interesting - it's easy to add pictures in this format to the Photos library and it will appear on all your devices that use iCloud. But if you want to export this picture from the Photos library - it will be converted to JPG on the fly, so it looks like you can't export the original HEIC file.

The converter is free and open source (but it's for macOS only): https://github.com/makoni/jpg-to-heif-converter

[↵] open page jpg-to-heif-converter.md
-rw-r--r-- 2.1K Apr 21, 2018 · D5C5FA9 · ~2 min

Impressions of Assassin's Creed Chronicles: China

assassin's creed игры

Assassin's Creed Chronicles: China

[↵] open page vpechatleniya-ot-assassin-s-creed-chronicles-china.md
-rw-r--r-- 6.4K Nov 24, 2017 · 210FD78 · ~5 min

Animating the UISlider Thumb on Touch

swift ios полезное uislider

Animating the UISlider Thumb on Touch

I had a task to animate the slider in the app on touch by smoothly enlarging the thumb. Just like Apple does in the Apple Music and Podcasts player when you start scrubbing the playback position. I spent quite a lot of time looking for a way to do it with standard tools. I really did not want to write a completely custom slider; I wanted to use the system UISlider, and in the end I managed to do exactly that.

[↵] open page animatsiya-kasaniya-indikatora-v-uislider.md
-rw-r--r-- 651B Oct 24, 2017 · FBD7F97 · ~1 min

SMS Anticredit

sms антикредит ios приложения

SMS Antispam

I got tired of the SMS spam that periodically comes to me — offers for loans, mortgages, and so on. While watching one of the WWDC videos, I noticed that Apple had provided an API for filtering SMS messages. If your filter triggers, such messages arrive silently, without a sound or vibration, and go into a separate spam category in Messages.

Without much hesitation, I made this filter and uploaded it to the App Store. Hopefully it will be useful to someone besides me.

Download on the App Store

[↵] open page sms-antikredit.md
-rw-r--r-- 374B Sep 5, 2017 · E5E50B4 · ~1 min

openssl and Vapor 2

vapor swift шпаргалки

I ran into a problem where a Vapor 2 project stopped compiling on Ubuntu. More precisely, one of its dependencies, Crypto. It turned out that because of an added repository containing newer versions of some libraries, it would not compile. Writing it down here — I had to downgrade:

apt install libssl-dev=1.0.2g-1ubuntu4.10
apt install openssl=1.0.2g-1ubuntu4.10
[↵] open page openssl-i-vapor-2.md
-rw-r--r-- 919B Jun 14, 2017 · 5C60537 · ~2 min

Benchmarks: Vapor 2 vs. Vapor 1

swift backend vapor ubuntu

After migrating my pet project from Vapor 1 to Vapor 2 I've run benchmarks to compare performance. I didn't run benchmarks for the last version of Vapor 1.x which is 1.5.15 so I will compare Vapor 2.1.0 to results of Vapor 1.2.5 that I have from my last results.

My server:

  • 2 GB RAM
  • 1 CPU Core
  • SSD
  • 125 MBPS Out
  • Ubuntu 16.04.2 LTS
  • CouchDB

Benchmark from other server was launched as:

wrk -t4 -c20 -d5m https://my_url

API just gets some data from CouchDB and returns it as JSON. Vapor project has been compiled with Swift 3.1.1.

[↵] open page benchmarks-vapor-2-vs-vapor-1.md
-rw-r--r-- 1.8K May 3, 2017 · 6BC24C7 · ~2 min

Weak delegate in Swift 3

swift шпаргалки утечки памяти

Memory usage in Xcode

I was fighting memory leaks in a work project. Digging led me to the fact that after leaving a UIViewController, far from all memory gets released. If you open this UIViewController several times, go back, and open it again, memory consumption grows and does not get released very much.

The root of the problem turned out to be protocols and delegates. A classic mistake. In my UIViewController I use a UICollectionView with a custom cell that has a delegate. My UIViewController is the delegate for each cell. An example of implementing such a protocol and delegate on the internet and in a Swift book looks roughly like this:

// Protocol
protocol MyCollectionViewCellDelegate {
    func someFunc()
}

// UICollectionViewCell
final class MessageCollectionViewCell: UICollectionViewCell {
    var delegate: MyCollectionViewCellDelegate?
}

// UIViewController
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    // some code....
    cell.delegate = self
}

Inside the cell object we have a strong reference to the delegate (UIViewController), which results in a memory leak.

The solution is simple — make the reference to delegate weak. To do that, you have to specify that only a class can implement the protocol. Structures are out, but there is no need for them here anyway. It changes like this:

// Protocol
protocol MyCollectionViewCellDelegate: class {
    func someFunc()
}

// UICollectionViewCell
final class MessageCollectionViewCell: UICollectionViewCell {
    weak var delegate: MyCollectionViewCellDelegate?
}

After these simple changes everything became great — after navigating back from the UIViewController, memory usage returns to its initial level.

[↵] open page weak-delegate-v-swift-3.md
makoni@arm1:~/blog$ cd ../page-7/ // ← previous cd ./page-9/ // more posts →