9 Notes August 2020

 1.  Set Button Just one tap

button1.exclusiveTouch = true

Source: https://stackoverflow.com/a/37073845/8366535

2.  How to configure test target in Xcode


this example to configure target like call function in class

# Testing Pods
def test_pods
    pod 'Quick'
    pod 'Nimble'
end
and call in target like this

  target 'QuickNimbleUnitTestingTests' do
    inherit! :search_paths
    # Pods for testing
    test_pods
  end
- This full file in "Podfile"
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'

# Testing Pods
def test_pods
    pod 'Quick'
    pod 'Nimble'
end

target 'QuickNimbleUnitTesting' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for QuickNimbleUnitTesting

  target 'QuickNimbleUnitTestingTests' do
    inherit! :search_paths
    # Pods for testing
    test_pods
  end

  target 'QuickNimbleUnitTestingUITests' do
    inherit! :search_paths
    # Pods for testing
  end

end




3.  View Background color opacity programmatically


view.backgroundColor = UIColor.black.withAlphaComponent(0.75)
view.isOpaque = false





4.  How to print type  data or nsdata

If you have problem to check you data type you can  use this

let data: Data?
let string1 = String(data: data!, encoding: String.Encoding.utf8)
print(string1)


Or use debug area


(lldb) po String(data: data!, encoding: String.Encoding.utf8)
▿ Optional<String>
  - some : "[{\"key\":\"language.preference\",\"value\":\"en-ID\"},{\"key\":\"limit.postlogin.nopin.amount\",\"value\":\"500000\"},{\"key\":\"prelogin.check.balance\",\"value\":\"true\"}]"







5.  Ascending and Descending  

func assendingAndDesending() {
        let sortString: [String] = ["baak", "Aaak", "Cadak", "dasak"]
        // Sort Ascending
        
        print(sortString.sorted(by: { $0.uppercased() < $1.uppercased() }), "Sort Ascending ?")
        let asd = sortString.sorted(by: >)
        print(asd)
        /*
         ["Aaak", "baak", "Cadak", "dasak"] Sort Ascending ?
         A -> Z
         */
        
        // Sort Descending
        
        print(sortString.sorted(by: { $0.uppercased() > $1.uppercased() }), "Sort Descending ?")
        /*
         ["dasak", "Cadak", "baak", "Aaak"] Sort Descending ?
          Z -> A
         */
    }

6.  Bug UI in IOS 11 

In my project found UI bug IOS 11 but in IOS 13.5 is good,
after checking code and finally found that solution 

Condition from viewController add subview as (UIView)



iPhone 11 (IOS 13.5)


iPhone X (IOS 11.4)


 override func viewDidLoad() {
        super.viewDidLoad()
        
        let newSubview = SubView()
        UIView.transition(with: view, duration: 1, options: .transitionCrossDissolve, animations: { [weak self] in
            guard let `self` = self else { return }
            self.view.addSubview(newSubview.backgroundView)
    
        }, completion: nil)
        
    }

7. Put "others" in last array use "sort" and "map"

import UIKit

class SortMapViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // put others in last array use sort and map
        let array: [String] = ["Adam", "payment", "Money", "Bank", "just", "Circle", "Doom", "Kelints", "others"]
        var newArray = [String]()

        let categories = array.filter { $0 != "others" }
        let models: [String] = categories.map {
            let category = $0.lowercased()
            return category
        }
        let sorted = models.sorted(by: { (category0, category1) -> Bool in
            category0.lowercased() < category1.lowercased()
        })

        newArray.append(contentsOf: sorted)

        array.forEach { trans in
            if trans == "others" {
                let category = trans.lowercased()
                newArray.append(category)
            }
        }

        print(newArray) //["adam", "bank", "circle", "doom", "just", "kelints", "money", "payment", "others"]
    }
}

8.  Use SKOverlay (Availabilly in MacOs 11+)
https://developer.apple.com/documentation/storekit/skstoreproductviewcontroller

9. UITabelViewCell handle odd and even rows

cell.backgroundColor = indexPath.row % 2 == 0 ? UIColor.lightGray : UIColor.cyan




No comments: