-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
-rw-r--r-- 8.5K Mar 24, 2017 · B3FBAC0 · ~7 min

Impressions of Assassin's Creed Syndicate

assassin's creed игры

Assassin's Creed Syndicate

[↵] open page vpechatleniya-ot-assassin-s-creed-syndicate.md
-rw-r--r-- 6.5K Feb 28, 2017 · 3EB5FBA · ~5 min

Impressions of Assassin's Creed Rogue

assassin's creed игры

Assassin's Creed Rogue

I finished another installment, Assassin's Creed Rogue.

[↵] open page vpechatleniya-ot-assassin-s-creed-rogue.md
makoni@arm1:~/blog$ cd ../page-8/ // ← previous cd ./page-10/ // more posts →