Map, FlatMap in swift

ref – http://sketchytech.blogspot.com.by/2015/06/swift-what-do-map-and-flatmap-really-do.html https://chrisbrandow.svbtle.com/swift-map-vs-flatmap Map Operate on the contents of the array. Maps unwraps a container ( array, dictionary…etc) , transforms value with supplied function and rewraps result.

output of each element: 1 2 3 4 5 6 Let’s apply adding 2 to each element

3 4 5 6 7 8 Let’s return […]

C function pointers are imported into Swift as closures

https://stackoverflow.com/questions/24330263/lifetime-of-retained-memory-in-swift-closures https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_13 One generally does not need to worry about how __block variables work internally. But basically, the variable is wrapped in a simplified “object” kind of thing, with the actual “variable” being a field of this “object”, which is memory-managed through reference counting. Blocks that capture them hold “strong references” to this pseudo-object thing […]

Retain Cycle in Swift 3 using ViewController and Singleton

demo Using Strong If your singleton’s block code strongs the viewcontroller, it will keep the ViewController around. 1) Your singletons starts processing data 2) You exit (cancel/pop) your ViewController. At this point ViewController will not dealloc because the block of your Singleton has stronged ViewController 3) Your function finishes processing 4) Then it executes its […]

Sorting an array in swift 3.0

Given in the doc where ComparisonResult is an Int enum, we see the following enum variables: enum ComparisonResult : Int case orderedAscending case orderedSame case orderedDescending So when given a string “Cash”, we compare it with “cash”. Capital C has a smaller value than lowercase c. Thus, it will be smaller. The ComparisonResult enum will […]

Array with nils (swift)

Non nil Arrays

Array OF optionals http://stackoverflow.com/questions/25589605/swift-shortcut-unwrapping-of-array-of-optionals Notice ‘?’ is inside of the bracket, thus, depicting it as array of optionals You can use nils in your array by using Optional types in your array. Just be reminded that you need to use flatMap to return an array of non-optionals and filter out any […]

Sort Chinese in swift

http://stackoverflow.com/questions/25685734/incorrect-chinese-number-sort-order-on-ios-using-nslocale-zh-hans-cn Han collation support: Pinyin: A B C D … Stroke: 1 2 3 … Radical-Stroke: radicals

“if let” optional binding vs “!=nil”

http://stackoverflow.com/questions/29322977/whats-the-difference-between-if-nil-optional-and-if-let-optional if let optional binding

The if let syntax is called optional binding. It takes an optional as input and gives you back a required constant if the optional is not nil. This is intended for the common code pattern where you first check to see if a value is nil, and if it’s […]

Convert Chinese to pinyin in Swift

http://stackoverflow.com/questions/4813086/how-to-convert-chinese-characters-to-pinyin

Using Charles web proxy, and viewing JSON

Hook up Charles Proxy to iOS Simulator Tutorial: Using Charles Proxy With Your iOS Development And HTTP Debugging As of Charles v3.9.3 there is an item in the Help menu, “Install Charles CA SSL Certificate in iOS Simulators”, which will automatically install Charles’s SSL CA certificate in your iOS Simulators. to view JSON text, and […]