SWIFT – Create filled array using map

A simple trick using .map to create directly a new Int array with random numbers inside.

The function produce this output:

array[0] = 1
array[1] = 5
array[2] = 3
array[30] = 1
func generateArray() -> [Int] {
let monthDays = Calendar.current.numberOfDaysInMonthForDate(Date())

let array = (0..<monthdays).map { i -> Int in
return Int(Double(arc4random_uniform(5)))

return array

That’s all!

XCode – Debug macOS PreferencesPane applications

You need to build a System preference panel extension for your app but you’re unable to debug it from XCode due to Apple System Integrity lock?

Let’s see how!

PreferencePane macOS app extension

But how to debug this extension?

Latest macOS block the execution or the debug of all system application. Now all apps are signed and if you try to attach a debugger you’ll receive this error:

Message from debugger: cannot attach to process due to System Integrity Protection

To avoid this kind of error, I suggest a simple trick. Use it only for debugging your plugin.

  1. Go in /Applications and duplicate the “System Preferences.app”.
  2. Rename it to “SystemPreferences_nosign.app”
  3. Open terminal, go to the Application folder and use:
$ codesign -s - -f SystemPreferences_nosign.app

Well done!

Now in XCode, select as Run Process, your new “nosigned” application. Build and run (debug)!

Swift – Custom Operators

This is an argument that I like a lot, the possibility to create or to override an operator changing its functionality.

SImilar to C++ Operator Overloading (https://en.cppreference.com/w/cpp/language/operators) but in Swift.

Continue reading Swift – Custom Operators

Swift – Natural language recognizer


with iOS 12, Apple released a new framework for language recognition and other interesting stuff. Is called NLLanguageRecognizer.

Use the Natural Language framework to perform tasks like language and script identification, tokenization, lemmatization, parts-of-speech tagging, and named entity recognition. You can also use this framework with Create ML to train and deploy custom natural language models.

Continue reading Swift – Natural language recognizer