Tag: swift

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 […]

Which optimization level should I choose for release?

I’ve read about swift assertions from here and trying to find out more about optimizations. for debug (default): compiler performs no optimizations which in turn makes debugging your code and tracing it back to the original line of source code significantly easier. for -O: the compiler will strip symbols from your code (such as variable […]

How to convert text to speech for OSX in Swift playground

I’m trying to learn how to do text to speech for OSX (not iOS) in Swift. I have a playground with code: import Cocoa let synth = NSSpeechSynthesizer() synth.startSpeaking( “Hello World” ) Which seems to run, but no sound occurs. In Xcode, there is a little blue triangle in the lower left corner, which I […]

geocoder.geocodeAddressString no longer works with swift update today

https://developer.apple.com/library/prerelease/mac/releasenotes/General/APIDiffsMacOSX10_11/Swift/CoreLocation.html shows that there were a couple of changes func geocodeAddressString(_ addressString: String!, completionHandler completionHandler: CLGeocodeCompletionHandler!) to: func geocodeAddressString(_ addressString: String, completionHandler completionHandler: CLGeocodeCompletionHandler) my code was: var geocoder = CLGeocoder() geocoder.geocodeAddressString(“\(event!.street), \(event!.city), \(event!.country)”, completionHandler: {(placemarks: [AnyObject]!, error: NSError!) -> Void in if let placemark = placemarks?[0] as? CLPlacemark { self.event!.lat = placemark.location!.coordinate.latitude self.event!.long = […]

Localizing system generated privacy alert message iOS UIAlertView Xcode

I have an app in development using Xcode Swift 1.1 and am testing it using iOS 7.1 and iOS 8.1 simulators. The app allows users to access their photos library, but before they can, iOS displays the Privacy alert message title asking for the user’s permission in English language – “App Name” Would Like to […]