Tag: swift

Turn sharedLoader function into a normal function

I have an imageLoader function, that loads the images while the other code keeps running. Now I want that same function to run first, before all the other code keeps running. This is the function: //calling the function ImageLoader.sharedLoader.imageForUrl(urlstring as String, completionHandler:{(image: UIImage?, url: String) in self.productImageView.image = image! }) //the function itself func imageForUrl(urlString: […]

How i can call functions from other class? Swift, Xcode

I have a class ACCreateObject. They have a function circlePhysicsDefault. I want to call this function other file by push the Button. In GameViewController i type: @IBAction func addOneCircle(sender: AnyObject) { ACCreateObject.circlePhysicsDefault(ACCreateObject) } But i have a issue: ‘(ACCreateObject).Type’ is not convertible to ‘ACCreateObject’. How can i call the function? What am doing wrong? Thanks! […]

'Can't use in/contains operator with collection'

I’m getting this error when clicking on the search bar: Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘Can’t use in/contains operator with collection Assignment_4.SearchResult(studentID: “1060”, lastName: “Squarepants”, firstName: “Spongebob”, major: “Krusty Krab Chef”, year: “Junior”, gpa: “4.0”) (not a collection)’ Getting the error on this line. let array = (results as NSArray).filtered(using: searchPredicate) This […]

How to create UnsafeMutablePointer<CGPoint> Object in swift

I need to call the UIScrollViewDelegate methods I don’t know how to create UnsafeMutablePointer object. let pointer:UnsafeMutablePointer<CGPoint> = CGPoint(x: 0, y: 1) as! UnsafeMutablePointer<CGPoint> self.scrollViewWillEndDragging(self.collectionView, withVelocity: CGPoint(x: 0, y: 1), targetContentOffset: pointer) func scrollViewWillEndDragging(scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { //Some code here }

SWIFT: I don't get notifications from my CloudKit app?

Here is my code: @IBAction func sendSweet(sender: AnyObject) { //delegate method let newSweet = CKRecord(recordType: “Extra1”) newSweet[“content”] = textField.text let publicData = CKContainer.defaultContainer().publicCloudDatabase publicData.saveRecord(newSweet, completionHandler: { (record:CKRecord?, error:NSError?) -> Void in if error == nil { dispatch_async(dispatch_get_main_queue(), { () -> Void in self.tableView.beginUpdates() self.sweets.insert(newSweet, atIndex: 0) let indexPath = NSIndexPath(forRow: 0, inSection: 0) self.tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: […]

Swift CoreData UnitTest: How to avoid EXC_BREAKPOINT

This would be common problem in CoreData unit testing using swift. EXC_BREAKPOINT exception happens due to swift’s namespace differences between normal module and test module. I’m still struggling against this issue even though some solutions are introduced. What I did and my problem is here. Create new project using the single application template with core […]

Algorithm to always sum sliders to 100% failing due to zeroes

This is (supposed to be) a function which makes sure that the the sum of a number of slider’s values always adds up to globalTotal. A slider value can be changed manually by the user to changer.value and then when applying this function to the values of the other sliders, it can determine their new […]

Split View Controller: How to connect Master View Controller to Detail View Controller?

(Xcode6-beta3, Swift, iOS8, iPad) In an iPad split-view controller, how do I link the Master View Controller to the Detail View Controller? In other words, when the user taps on an item on the left, how do I change the view on the right? I know that in didSelectRowAtIndexPath, I need to call a method… […]

.gitignore for Xcode Project

I’m always nervous to make pushes of code to a Github repo with authentication tokens and variables. I have had an issue in the past with exposed keys and since I am new to Xcode, I’m curious as to what files I should be adding to .gitignore. The main areas where I am most nervous […]

Swift – Parse – Check if username is taken

I am trying to create a function that takes a username as a parameter and checks to see if that username is taken (by comparing it to other PFUsers in the Parse database. This function is in my view controller class. (I know there are similar questions to this but they do not provide quality […]