9 Notes for me in March Swift 4.2

1. Create Rest API your own in GitHub

-- create a new repo
-- create new file restful API format JSON
-- open file  https://api.github.com/repos/username/yourrepo/contents/filename
-- select "download_url" and you get like below
https://raw.githubusercontent.com/YourUserName/yourRepo/master/namefile

example:
https://api.github.com/repos/user21/project1/contents/apiFoods

use this link in your app:
https://raw.githubusercontent.com/jerrypm/nextproject/master/apiFoods

for a test, you can run in Postman  or in your GitHub click "Raw" in a file in repo and copy the link




2.  If you found an error  "Instance will be immediately deallocated because property 'dataSource' is 'weak'"

use this solution, for example:

--- from this



-- to this




3. NotificationCenter use UIApplication swift 4.2 change

https://stackoverflow.com/a/51470183/8366535

forName: Notification.Name.UIApplicationDidEnterBackground
to
forName: UIApplication.didEnterBackgroundNotification





4.  "iPhone has denied the launch request." Xcode 10.2 




The Error You may have seen a question on the cause of this error before:
iPhone has denied the launch request. Cannot launch app, because is a new rule from apple

so this solution for you:  got to tab Product -> Scheme -> EditScheme. remove checklist debug executable.







5.  NavigationBar prefersLargeTitles Change Color

--- use  largeTitleTextAttributestitleTextAttributes set in viewdidload

navigationController?.navigationBar.prefersLargeTitles = true
navigationController?.navigationItem.largeTitleDisplayMode = .never

navigationController?.navigationBar.prefersLargeTitles = true
        navigationController?.navigationItem.largeTitleDisplayMode = .never
        navigationController?.navigationBar.barTintColor = UIColor.gray
        navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white]

UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.white]


6.  UITabBarController hide navigation bar in special pages

extension MainViewController: UITabBarControllerDelegate {
    public func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
        if viewController.tabBarItem.tag == 0 {
            self.navigationItem.title = "Food"
            self.navigationController?.setNavigationBarHidden(true, animated: false)
     
        } else if viewController.tabBarItem.tag == 1 {
            self.navigationItem.title = "Search"
            self.navigationController?.setNavigationBarHidden(false, animated: false)
     
        } else {
            self.navigationItem.title = "Library"
            self.navigationController?.setNavigationBarHidden(false, animated: false)
        }
        return true
    }
}

7. Custom UITabbar Bottom

        self.tabBar.backgroundColor = UIColor.white
        self.tabBar.tintColor = UIColor.gray
        self.tabBar.layer.masksToBounds = true
        self.tabBar.isTranslucent = true
        self.tabBar.barStyle = .blackOpaque . // style tab bar
        self.tabBar.layer.cornerRadius = 20
        self.tabBar.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner] // special for tabbar


8. New Rounded function will be available for iOS 11 and up

// Detail rounded
.topLeft = layerMinXMinYCorner
.bottomLeft = layerMaxXMaxYCorner

.topRight = .layerMaxXMinYCorner
.bottomLeft = layerMinXMaxYCorner

Example:

layer.cornerRadius = 10
layer.maskedCorners = [.layerMaxXMinYCorner, .layerMinXMaxYCorner]


https://medium.com/swiftworld/swift-world-whats-new-in-ios-11-make-corner-round-cc70728c9a7


9.  How to pdf as file image in swift 4

To try it out, drop a PDF file into your asset catalog, then change its Scales property Individual scale to Single scale like this below. this has the effect of making Xcode convert it to @2x and @3x at build time.







No comments: