Tag: xcode

Using custom SKNodes in spritekit scene editor

I want to create a level using my custom subclasses of SKNode. I tried adding an SKNode to the scene editor and using the “Custom Class” tab give the class that I want it to be but that did absolutely nothing. The node would still be empty and nothing would show when I run the […]

ScrollView in SpriteKit

I have found a few other questions and answers similar to this, but none of them quite work perfect for me. My vision is to have a horizontal scrollable view at the bottom of the screen where I can scroll through what will look like cards in a hand. Ideally, I could eventually make the […]

Error: Value of type string has no member componentsSeparatedByCharactersInSet

The following code throws the following error: “Value of type string has no member componentsSeparatedByCharactersInSet” This code is from another project that worked before in swift versions 1 or 2 but no longer works. import Foundation extension String { func split() -> [String] { return self.componentsSeparatedByCharactersInSet( CharacterSet.whitespaceAndNewlineCharacterSet()) .filter({$0 != “”}); } } extension Array { […]

Send Image and Text With Whatsapp

I need to send an image from my app with a text, I know how to send just an image or just a text, but I don’t know how to combine both of them. Just an Image: let image = UIImage(named: “Image”) // replace that with your UIImage let filename = “myimage.wai” let documentsPath = […]

Swift – Integrate GameCenter to use leaderboards

I am making a game in Swift. I want to be able to post the users’ score using GameCenter, so that scores from all my users’ can be seen. However, I have spent the past day trying to figure out how to do this, but I haven’t found any helpful instructions. I am pretty new […]

updateValue not working for Dictionary

I’m creating a test app using Swift in Xcode, and I’ve run into an annoying issue. I’m writing a simple class that will act as a cache using a Dictionary object. My implementation is below: import Foundation import UIKit class ImageCache { var dict:Dictionary<String,NSData>?; init() { dict = Dictionary<String,NSData>(); } func exists(id:String) -> Bool { […]

Embedded Content Contains Swift Code with Xcode 8 Beta

I am developing a command line macOS application(with Objective-C) which uses other 3rd party Swift libraries. I am retrieving an error says “dyld: Library not loaded: @rpath/libswiftAppKit.dylib“ Previous answers recommend to set “Embedded Content Contains Swift Code” flag to true. However, this flag is missing with Xcode 8 beta. I have tried “ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES“, which i […]

Swift 2.0 'unexpected trailing closure' error with lazy var assignment

I’m converting a project to Swift 2.0 and I keep coming across this error everywhere that I’m using a lazy var. This code works perfectly in 1.2 but breaks in 2.0: lazy private var placeholderImage = UIImage(named: “theImage”) But, this code generates an ‘unexpected trailing closure’ error in 2.0. Following the Xcode’s suggestions to fix […]

Swift Constants file – class or struct?

I want to create a Constants file in my Swift project – filled with static let strings. Should I create as a struct or a class? And why?

Alamofire POST request with progress

I’m using Alamofire to do a POST request. As this POST request can take a while and I want to keep track of the progress and display it as a ProgressView. Alamofire.request(.POST, ApiLink.create_post, parameters: parameters, encoding: .JSON) .progress { (bytesRead, totalBytesRead, totalBytesExpectedToRead) -> Void in println(“ENTER .PROGRESSS”) println(“\(totalBytesRead) of \(totalBytesExpectedToRead)”) self.progressView.setProgress(Float(totalBytesRead) / Float(totalBytesExpectedToRead), animated: true) […]