Tag: Swift 4
-
iOS Swift Accessing Bundle Folder And File Write
To access a file in Bundle folder: Bundle.main.url(forResource:”YourFile”, withExtension: “FileExtension”) Also to write a file with error checking: var myData: Data! func checkFile() { if let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last { let fileURL = documentsDirectory.appendingPathComponent(“TheFile.extension”) do { let fileExists = try fileURL.checkResourceIsReachable() if fileExists == true { print(“File exists”) } else {…
-
iOS Swift Save|Load Custom Class Variables As Encoded Object
By using NSKeyedArchiver.archivedData, NSKeyedUnarchiver.unarchiveObject you can actually store the data as compressed zip in the device and recall/unzip them to your class structure Model Class class User: NSObject, NSCoding { // Common var userId: Int = 0 var userFullName: String = “” var userUsername: String = “” var userBiography: String = “” var userRegisterDate: String =…
-
iOS Swift Navigation With Manuel Segue
Unwind Structure Example @IBAction func unwindToTheVC(segue: UIStoryboardSegue) { if let source = segue.source as? OtherVC { print(“From OtherVC”) } } Manuel Segue Example func gotoSegue(_ sender:Any){ guard let destination = UIStoryboard(name:”Main”, bundle:nil).instantiateViewController(withIdentifier: “TheTableViewController”) as? TheTableViewController else { print(“Could not instantiate view controller with identifier of type SecondViewController”) return } destination.variablesToSet = vars destination.unwindTo…
-
iOS Swift Find Exist Fond Families In The Project
This code showing the font families and real name of the fonts. for family: String in UIFont.familyNames { print(“\(family)”) for names: String in UIFont.fontNames(forFamilyName: family) { print(“== \(names)”) } }
-
Making iOS Swift App Without Storyboard, Just Programmatically!
Storyboard is a good thing but has some side unwanted effect. You can find many discussion about it. Personally I don’t like it so much especially when I make an application without default navigation system it is useless, slow and makes me tired. I prefer creating my UIViews separately and link them to their UIViewController’s…
-
iOS Swift Initialising XIB And Bind To The Controller Without Storyboard
It is very useful to able to initialise xib files independently from storyboard. Here is what to do with a line of code: //Calling the initializer in the ViewController convenience override init() { // ViewName is by convenience same name. // I use like: BlahV.xib BlahVC.swift self.init(nibName: “BlahV.xib”, bundle: nil) //initializing the view Controller form specified…
-
Playing YouTube Videos In iOS Device
Playing a YouTube video in the app is very easy with UIWebView Here is a snippet // YouTube video @IBOutlet weak var webView: UIWebView! // MARK: – Embed Video Player // id is like: xjr89789234 (grab this from youtube url) func loadYoutube(_ videoID:String) { guard …