[Solved] Save an Object into User Defaults [duplicate]

The UserDefaults class provides convenience methods for accessing common types such as floats, doubles, integers, Boolean values, and URLs. A default object must be a property list—that is, an instance of (or for collections, a combination of instances of) NSData, NSString, NSNumber, NSDate, NSArray, or NSDictionary. If you want to store any other type of … Read more

[Solved] How do I programmatically pull up a different storyboard when a button is clicked in Swift 4? [duplicate]

You can do it programatically this way: Swift 3+ let storyboard = UIStoryboard(name: “StoryboardName”, bundle: nil) let vc = storyboard.instantiateViewController(withIdentifier: “ViewControllerID”) as UIViewController present(vc, animated: true, completion: nil) 2 solved How do I programmatically pull up a different storyboard when a button is clicked in Swift 4? [duplicate]

[Solved] Regular Expression generation in Swift [duplicate]

You could do something like this : let str = “_h Hello _h _h World _h” let range = NSRange(str.startIndex…, in: str) let regex = try! NSRegularExpression(pattern: “(?<=_h).+?(?=_h)”) let matches = regex.matches(in: str, range: range) let results: [String] = matches.compactMap { match in let subStr = String(str[Range(match.range, in: str)!]).trimmingCharacters(in: .whitespacesAndNewlines) return subStr.isEmpty ? nil : … Read more

[Solved] Picker View uncaught exception SWIFT

The first problem is that you don’t store the created picker view instance. You instantiate it inside of a function, assign the delegate and dataSource and then you don’t store it in your class. So the ARC (Automatic Reference Counting) releases it, because it thinks the instance is not longer needed. Just create a variable … Read more

[Solved] How to implement below code in swift

Do like this, let startingViewController: PageContentViewController? = viewController(at: 0) let viewControllers: [UIViewController] = [startingViewController] pageViewController.setViewControllers(viewControllers, direction: .forward, animated: false) { _ in } 3 solved How to implement below code in swift

[Solved] How to not repeat code in Swift for attributes of button? [closed]

Your answer really isn’t ideal for stackoverflow since it’s not a direct problem your looking for help with, but instead a question of best practice. Check the code of conduct again. However you can do the following: (If you need those buttons to be instanced/complete right away) a) Create a private static function in your … Read more

[Solved] Swift NStask function

Try this: func commmand(argument: String) -> String { let task:NSTask = NSTask() let pipe:NSPipe = NSPipe() task.launchPath = “/bin/menubar” task.arguments = [argument] task.standardOutput = pipe task.launch() let handle = pipe.fileHandleForReading let data = handle.readDataToEndOfFile() let result_s = String(data: data, encoding: NSUTF8StringEncoding)! return result_s } print(commmand(“getip”)) 2 solved Swift NStask function

[Solved] Using UIColor with CAShapeLayer

First of all the parameters red,green, blue and alpha must be in range from 0.0 to 1.0 Secondly, you must pass the cgColor to CGLayer, e.g. let color = UIColor(red: 57.0/255.0, green: 65.0/255.0, blue: 101.0/255.0, alpha: 1) shapeLayer.fillColor = color.cgColor shapeLayer.strokeColor = color.cgColor solved Using UIColor with CAShapeLayer