[Solved] How to store array of values in NSUserDefaults in swift

let array = [1, 2, 9, 3, 22] UserDefaults.standard.set(array, forKey: “studentIDs”) //get id’s array from user defaults let studentIdsArray = UserDefaults.standard.array(forKey: “studentIDs”) There are plenty of questions/solutions, here is one: how to save and read array of array in NSUserdefaults in swift? But as another user said, please take a look at the official documentation: … Read more

[Solved] how to change the wallpaper using OC or Swift on mac [closed]

You gan get all the screens from this code: let screens = NSScreen.screens And set wallpaper By This code let newWallpaperURL = URL(/* … */) for i in screens { try! NSWorkspace.shared().setDesktopImageURL(newWallpaperURL, for: i, options: [:]) } solved how to change the wallpaper using OC or Swift on mac [closed]

[Solved] Xcode bugged project

I was going to recreate the project from scratch, but decided to start by recreating the files in the project first. I copied the code in LoginVC, deleted the file, created a new LoginVC, pasted the code back in, and the whole project runs as expected now. Breakpoints and code execute as expected throughout the … Read more

[Solved] uiview as optional parameters in swift

You can declare method like below: func test(_ myNumber: Int? = 2) { } In above function, I have provided a default value as 2. I can call the function as test() or test(5) solved uiview as optional parameters in swift

[Solved] Navigation bar with shadow & corner radius

Here is the code, // 1. Enable prefersLargeTitles and title self.navigationController?.navigationBar.prefersLargeTitles = true self.title = “Title” // 2. Add left, right bar buttons let leftBtn = UIBarButtonItem(title: “Edit”, style: .done, target: self, action: #selector(item)) let rtBtn = UIBarButtonItem(title: “Add”, style: .done, target: self, action: #selector(item)) self.navigationItem.rightBarButtonItem = rtBtn self.navigationItem.leftBarButtonItem = leftBtn //3. Change default navbar … Read more

[Solved] Swift Nested If statements do not compile

It should be like this: func getWeight() -> String { if weightLabel.text == “Weight (lbs)” { if pickerView == heightPicker { let titleRow = height[row] return titleRow } else if pickerView == weightPicker { let titleRow = weight[row] return titleRow } return “” } else if weightLabel.text == “Weight (kgs)” { if pickerView == heightPicker … Read more

[Solved] How to Create Two WkWebView

var item = WKWebView() item.frame = CGRectMake(0, 0, self.view.bounds.width, 200.) self.view.addSubview(item) item = WKWebView() item.frame = CGRectMake(0, self.view.bounds.height-200., self.view.bounds.width, 200.) self.view.addSubview(item) This code add WKWebView at the top and bottom of self.view. 9 solved How to Create Two WkWebView

[Solved] Ambiguous use of subscript compiler error

You need to tell compiler the type of item, so instead of casting info array to [AnyObject] type cast it to [[String:Any]]. if let imagesArray = info as? [[String:Any]] { for item in imagesArray { if let image = item[UIImagePickerControllerOriginalImage] as? UIImage { //Access image instance } } } 6 solved Ambiguous use of subscript … Read more

[Solved] NSBundle.mainBundle().bundleIdentifier! + “.\(self.rawValue)” in swift 3.0?

Bundle.main.bundleIdentifier! + “.\(self.rawValue)” NS prefix is omitted in swift 3 Working code examples:- let rawValue = “Testing stackoverflow” let stringValue1 = Bundle.main.bundleIdentifier! + “test” let stringValue2 = Bundle.main.bundleIdentifier! + “\(rawValue)” 2 solved NSBundle.mainBundle().bundleIdentifier! + “.\(self.rawValue)” in swift 3.0?