[Solved] Why am i getting this error (swift 2.2, dealing with func and named parameters)? [closed]

From the Swift 2.x documentation: Local and External Parameter Names for Methods Function parameters can have both a local name (for use within the function’s body) and an external name (for use when calling the function), as described in Specifying External Parameter Names. The same is true for method parameters, because methods are just functions … Read more

[Solved] Swift 2 get the number of images in main bundle [closed]

Try this EDITED let myArray = NSMutableArray() var image:UIImage! var nimages = 0 for(;;nimages++){ let nameOfImg_ = entity.attribute let imageName = String(format: “name%@number%lu.jpg”, arguments: [nameOfImg_,(nimages + 1)]) if((NSBundle.mainBundle().pathForResource(imageName, ofType: nil)) != nil){ image = UIImage(contentsOfFile: NSBundle.mainBundle().pathForResource(imageName, ofType: nil)!) myArray.addObject(image!) }else{ break } } entity.attribute must be a String 12 solved Swift 2 get the number … Read more

[Solved] How to send data to the server(api) using swift

you can send data to server by using Alamofire API. It’s documention and implemention all the stuff are mentioned in the following link. https://github.com/Alamofire/Alamofire Just install it using Pods and it’s very easy to implement. create Network Class and create following function inside it. func get_Request(currentView : UIViewController,action : NSString,completionHandler: (NSDictionary -> Void)) { print(“Url==>>>”,mainURl … Read more

[Solved] Upgrade Xcode 7.3.1 Project to Xcode 8.0

The final answer of above question is: add the code snippet in your podfile post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings[‘SWIFT_VERSION’] = ‘3.0’ end end end then check swift legacy in build settings and set it to NO for swift 3 or you can set Yes for swift 2.3 (if you are … Read more

[Solved] sendSynchronousRequest is deprecated in ios 9 [duplicate]

This is a working example, You should use NSURLSession, with Request. func testPost(sender: UIButton) { let session = NSURLSession.sharedSession() let request = NSMutableURLRequest(URL: NSURL(string: “http://localhost:8080/iOSServer/ios/helloworld/swiftCalculator”)!) request.setValue(“application/x-www-form-urlencoded”, forHTTPHeaderField: “Content-Type”) request.HTTPMethod = “POST” let d = “4” let data = “x=4&y=\(d)” request.HTTPBody = data.dataUsingEncoding(NSASCIIStringEncoding) let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in if let error = … Read more

[Solved] Default Back Button Text and Font Setting

Change your code in viewDidLoad like this. class BaseViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() } func setNavigationWithCustomBackButton() { let btnLeft:UIButton! = UIButton(frame: CGRectMake(0, 0, 20, 16)) btnLeft.setTitle(“<=|”, forState: .Normal) btnLeft.titleLabel?.font = UIFont.systemFontOfSize(19, weight: UIFontWeightLight) btnLeft!.addTarget(self, action: “handleBack:”,forControlEvents: UIControlEvents.TouchUpInside) let leftItem:UIBarButtonItem = UIBarButtonItem(customView: btnLeft!) self.navigationItem.leftBarButtonItem = leftItem } func handleBack(sender: UIButton) { self.navigationController?.popViewControllerAnimated(true) } … Read more

[Solved] Swift 2.0 String behavior

The index of a String is no more related to the number of characters (count) in Swift 2.0. It is an “opaque” struct (defined as CharacterView.Index) used only to iterate through the characters of a string. So even if it is printed as an integer, it should not be considered or used as an integer, … Read more

[Solved] Counting Vowels in Swift [closed]

You could do something like this: extension String { var numberOfVowels: Int { let vowels = “aeiou” let vowelsSet = NSCharacterSet(charactersInString: vowels) let strippedComponents = lowercaseString.componentsSeparatedByCharactersInSet(vowelsSet) let stripped = strippedComponents.joinWithSeparator(“”) return characters.count – stripped.characters.count } } “Hello”.numberOfVowels 5 solved Counting Vowels in Swift [closed]

[Solved] Update code to swift 2 [closed]

You have to use this code in try catch like below.. if let rtf = NSBundle.mainBundle().URLForResource(“rtfdoc”, withExtension: “rtf”) { do { let attributedString = try NSAttributedString(fileURL: rtf, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil) textView.attributedText = attributedString textView.editable = false print(attributedString) } catch let error as NSError { print(error.localizedDescription) } } solved Update code to swift 2 [closed]

[Solved] Swift Version 2 Bool [closed]

Boolean values in Swift are true and false, YES and NO is used in Objective C. So in your stopRunning method for instance, you should write: @IBAction func stopRunnng(sender: UIButton) { tmrRun invalidate() btnGo.userInteractionEnabled = true btnStop.userInteractionEnabled = false sliSpeed.userInteractionEnabled = true } (sidenote, you don’t need the ; in Swift either) About the void … Read more