swift2

Alamofire and SwiftyJSON for Swift 2.0

可紊 提交于 2019-12-22 13:58:12
问题 I am updating my code for Swift 2.0 for today, however the line var json = JSON(json) gives me the following error Cannot invoke intializer for type 'JSON' with an argument list of type (Result) Do you guys have any idea how should I change my code? @IBAction func changePassword(sender: UIBarButtonItem) { Alamofire.request(.POST, AppDelegate.kbaseUrl + "users/me/password", parameters: ["old_password": self.oldPasswordTextField.text!, "new_password": self.newPasswordTextField.text!, "confirm

UIActivityViewController on iPad

六眼飞鱼酱① 提交于 2019-12-22 13:58:10
问题 I have been using the code below to show a UIActivityViewController which worked fine when I was using Xcode 6, Swift 1.2 and iOS 8. However when I updated it shows the UIActivityViewController but it is completely blank without any of the sharing options. Do you have any suggestions? if UIDevice.currentDevice().userInterfaceIdiom == .Pad { let textToShare = textViewOne.text let objectsToShare = [textToShare] let activityVC = UIActivityViewController(activityItems: objectsToShare,

swift dismiss modal and push to new VC

邮差的信 提交于 2019-12-22 12:54:30
问题 I have tableview... 1 table showing a new modal window and when I press the button I want to dismiss the modal window and push to VC. My code only hide the modal view but no push is made. @IBAction func registrationBtn(sender: AnyObject) { let openNewVC = self.storyboard?.instantiateViewControllerWithIdentifier("registrationVcID") as! RegistrationVC self.dismissViewControllerAnimated(false, completion: { () -> Void in self.navigationController?.pushViewController(openNewVC, animated: true) })

How to implement AVAudioPlayer Inside Singleton Method?

爱⌒轻易说出口 提交于 2019-12-22 12:31:52
问题 This is my code : class SomeAudioManager: NSObject { class var sharedInstance: SomeAudioManager{ struct Static { static var onceToken: dispatch_once_t = 0 static var instance: SomeAudioManager? = nil } dispatch_once(&Static.onceToken) { Static.instance = SomeAudioManager() } return Static.instance! } func audioView(songname: NSString,format: NSString) { let audioPlayer:ava audioPlayer=try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(songname,

how to wake up iOS parent app with sendMessage from complicationController

好久不见. 提交于 2019-12-22 12:31:50
问题 I am trying to wake up the iOS parent app by sending a message from watchkit extension. This though does only work when below sendMessage function is called from the watchApp / ViewController. When it is called from ComplicationController, the message is sent, but the iOS parent app does now wake up. Any advice appreciated. (please any code reference in Swift) Here the simplified code: In AppDelegate and ExtensionDelegate: override init() { super.init() setupWatchConnectivity() } private func

How to implement AVAudioPlayer Inside Singleton Method?

孤街醉人 提交于 2019-12-22 12:31:33
问题 This is my code : class SomeAudioManager: NSObject { class var sharedInstance: SomeAudioManager{ struct Static { static var onceToken: dispatch_once_t = 0 static var instance: SomeAudioManager? = nil } dispatch_once(&Static.onceToken) { Static.instance = SomeAudioManager() } return Static.instance! } func audioView(songname: NSString,format: NSString) { let audioPlayer:ava audioPlayer=try AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(songname,

Check if an array contains all elements of another in Swift

别说谁变了你拦得住时间么 提交于 2019-12-22 12:23:50
问题 I want to write an extension for array to check if an array contains all the elements of another array, in my use case it's string objects but I keep get: Cannot convert value of type 'T.Generator.Element' to expected argument type '@noescape _ throws -> Bool' in the line self.contains(item) the error in about item here is my code: extension Array { func containsArray<T : SequenceType where T.Generator.Element : Equatable> (array:T) -> Bool{ for item:T.Generator.Element in array{ if !self

Collide type source error - spritekit swift game

给你一囗甜甜゛ 提交于 2019-12-22 10:59:01
问题 So I have adjusted my games ball type from a shape to an image which forced me to redo the physics of my game. I am new to swift and have struggled with fixing my collisions in my swift game. class GameScene: SKScene, GameDelegate, SKPhysicsContactDelegate { var ball: Ball! let ballSpeedX = CGFloat(500) //ball = Ball(imageNamed:"colorBall.png") enum CollisionTypes: UInt32 { case Floor = 1 case Ball = 2 } // board let boards = Boards.make(CollideType.BoardStart.rawValue) var lastBoard: SKNode?

Force a UITextField to lowercase while typing and retaining cursor position

≯℡__Kan透↙ 提交于 2019-12-22 10:37:55
问题 (programming in swift 2) I have a UITextField that when the user types into it should be automatically converted to lower case WHILE typing (so NOT after form validation). I have gotten this far: func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool { //only convert to lowercase for username field if textField == textFieldUsername { //let stringRange = NSRange(location: range.location, length: range.length) let

Issues with Swift generated header file

孤者浪人 提交于 2019-12-22 10:13:53
问题 I've got a project using Mapbox. The code base is mixed objC and Swift code. The class using Mapbox is written in Swift but is exposed to legacy objC code. I'm using !use_frameworks in my pod file to be able to use Swift pods as well. The problem I'm facing is that generated -swift.h file is wrong. This is the problematic bit: #if defined(__has_feature) && __has_feature(modules) @import ObjectiveC; @import Mapbox; @import CoreGraphics; @import Foundation; @import UIKit; #endif __has_feature