Tag: swift

How do I access variables that are inside closures in Swift?

I’m new to Swift and I’m trying to get the result from this function. I don’t know how to access variables that are inside the closure that is passed to the sendAsynchronousRequest function from outside the closure. I have read the chapter on closures in the Apple Swift guide and I didn’t find an answer […]

Swift TextField has no width

I have just started learning swift and have been trying to create a layout using the scoreboard. I have placed two textfields and set the constraints properly using the document outline. However when I run the emulator the Text Fields display wrong. I have attached a screenshot, The left is what happens in my emulator […]

Why does Xcode stop giving text prediction?

I am trying to learn how to create apps using Xcode. I usually follow tutorials on the internet as Objective-C and Swift come with built-in methods and functions usually hard to remember (at least for me at this stage). Throughout a project, I do not get predictive text any longer and have to type the […]

Delete UITable sections dynamically with commitEditingStyle in Swift

I’m dealing with an issue I can’t work around… I have a table of names, from a DB-array of customers, every customer has a name property among other data members. I can delete rows within a section successfully, but what I can’t do it’s deleting the section (when the last row within that section gets […]

Setting the Navigation and Status Bar text colour

I am trying to change the text colour of the navigation bar in my app, however I can’t figure out how it’s done. Prior to Xcode 6 beta 2 I was using: navigationController.navigationBar.titleTextAttributes = [UITextAttributeTextColor: UIColor.whiteColor()] And that worked absolutely fine but after updating to the newer versions I just get an error stating that […]

Working with SKSpritenodes and textures

I am trying to program in feature that allows the user to change the “Ghost” to a different image. Here is my code: Ghost = SKSpriteNode(imageNamed: “Ghost17”) Ghost.size = CGSize(width: 50, height: 50) Ghost.position = CGPoint(x: self.frame.width / 2 – Ghost.frame.width, y: self.frame.height / 2) Ghost.physicsBody = SKPhysicsBody(circleOfRadius: Ghost.frame.height / 1.4) Ghost.physicsBody?.categoryBitMask = PhysicsCatagory.Ghost Ghost.physicsBody?.collisionBitMask […]

Create a socket in Swift

I’m trying to write a simple echo server with swift. The examples I found are either non-functional and low-level or written in objective-c. I failed at a lot of things, I will start from the top. I cannot manage to create a simple socket using higher-level functions like CFSocketCreate. This is what I ended up […]

Getting Decibels from AVAudioRecorder

I’m trying to get a decibel value from an AVAudio Recorder. This is my code currently. I have a method to start the recorder, then a method to read the decibel values. var recorder: AVAudioRecorder! Recorder defined globally, then used here: func init_recorder() -> Void { let recordersettings = [ AVFormatIDKey: Int(kAudioFormatAppleIMA4), AVSampleRateKey: 44100, AVNumberOfChannelsKey: […]

PageViewController showing a black screen

In storyboard I have a UIPageViewController and this is my code class ReservedTimesViewController: UIPageViewController { override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } } extension ReservedTimesViewController: UIPageViewControllerDataSource { func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { let controller = UIStoryboard(name: “Main”, bundle: nil).instantiateViewController(withIdentifier: “ReservedTimesTableViewController”) print(controller) return controller } func […]

XCode 8 strange Playground error, Couldn't Lookup Symbols

I was trying to use auto layout in a Playground on Xcode 8. However, as soon as I added the line, I started receiving this error: Playground execution failed: error: Couldn’t lookup symbols: __TWPCSo6UIView17PlaygroundSupport22PlaygroundLiveViewableS0_ __swift_FORCE_LOAD_$_swiftCoreGraphics __swift_FORCE_LOAD_$_swiftDarwin __TMaC17PlaygroundSupport14PlaygroundPage __swift_FORCE_LOAD_$_swiftObjectiveC __swift_FORCE_LOAD_$_swiftUIKit _playground_log_hidden _playground_logger_initialize __swift_FORCE_LOAD_$_swiftCoreImage __swift_FORCE_LOAD_$_swiftDispatch __TFC17PlaygroundSupport14PlaygroundPageau7currentS0_ __swift_FORCE_LOAD_$_swiftFoundation __TFC17PlaygroundSupport14PlaygroundPages8liveViewGSqPS_22PlaygroundLiveViewable__ * thread #1: tid = 0x14b6b4, 0x000000010f2f43c0 MyPlayground`executePlayground, queue […]