swift3

Deciphering instruments readout

浪子不回头ぞ 提交于 2019-12-14 02:15:07
问题 CPU usage at ~50% / energy usage "Very high" in my sprite kit game. I use tile sets to setup the levels. After the tile sets are in place I use clear, non-dynamic sprites with collision/contact bit masks for floors/walls/etc. I get a constant 60FPS, and my memory usage is only ~32MBs. For animations as of now I have: 3 roving (forever) enemies which are not removed from the scene unless stepped on and killed 9 vertically moving platforms (up and down forever). Each platform uses an SKaction

Type … ambiguous without more context

折月煮酒 提交于 2019-12-14 01:08:50
问题 On the process of migrating an iOS app to Swift 3.0. Here is one issue I am facing. First the relevant code: let calendar = NSCalendar.current, calendCompo = calendar.components([.Year, .Month, .Day, .Hour, .Minute, .Second], fromDate: NSDate()) Second the problem: I am getting this error message, for the second line: Type of expression is ambiguous without more context I also tried this code: let calendar = NSCalendar.current, calendCompo = calendar.components([.year, .month, .day, .hour,

cannot convert AnyHashable in swift 3

你离开我真会死。 提交于 2019-12-14 00:44:31
问题 I have following method, which written in swift (before swift 3). below is the method func application(application: UIApplication, didReceiveRemoteNotification launchOptions: [AnyHashable: Any]) -> Void { Branch.getInstance().handlePushNotification(launchOptions) } it gives and error of Use of undeclared type AnyHashable . how can I covert this to swift 3. I tried with following. func application(application: UIApplication, didReceiveRemoteNotification launchOptions: [NSObject : AnyObject]) -

Facebook FBSDKLoginButtonDelegate loginButton function syntax error

强颜欢笑 提交于 2019-12-14 00:42:54
问题 i'm using Xcode8 and swift 3. So I fully converted my project to the latest syntax and now i get the error: 'Error' is ambiguous for type lookup in this context in the function: func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { //do stuff } The function in FBSDK declared as follows: - (void) loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error; so

Is it possible to specify the object type allowed in a Dictionary?

左心房为你撑大大i 提交于 2019-12-13 23:31:36
问题 In Swift 3.x is it possible to specify the object type allowed in a Dictionary? It would be great if at declaration time we could pass a set of object types allowed. 回答1: You can achieve this via a custom protocol that is implemented only by the types you want to allow within the dictionary: protocol AllowedDictionaryValue: {} extension String: AllowedDictionaryValue {} extension Int: AllowedDictionaryValue {} extension MyClass: AllowedDictionaryValue {} extension MyEnum:

Swift 3 Unrecognized selector sent to instance UIButton

北战南征 提交于 2019-12-13 23:15:41
问题 I get this error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITouchesEvent text]: unrecognized selector sent to instance 0x6100000e9400' The button it crashes on: import UIKit import Firebase import FBSDKLoginKit class RegisterViewController: UIViewController, FBSDKLoginButtonDelegate, UITextFieldDelegate { override func viewDidLoad() { super.viewDidLoad() // Create Sign Up button let signUpButton: UIButton = { let button = UIButton() button.setImage(

How to implement auto scroll in UIScrollview using Swift 3?

∥☆過路亽.° 提交于 2019-12-13 23:08:09
问题 I want to implement auto scroll to UIScrollView in swift 3. Could any one help me. Actually I am new in iOS development. My Code : var bannerscView: UIScrollView! bannerscView = UIScrollView(frame: CGRect(x: 0, y: 50, width: Int(view.bounds.width), height: 350)) bannerscView.showsVerticalScrollIndicator = true view.addSubview(bannerscView) bannerscView.backgroundColor = UIColor.red bannerscView.translatesAutoresizingMaskIntoConstraints = false _ = Timer.scheduledTimer(timeInterval: 0.5,

how to get the particular value from Json?

≯℡__Kan透↙ 提交于 2019-12-13 22:59:14
问题 I am having the Json data as shown below in this I need to get the data that which key value pair for default is 1 then i need to get the remaining dictionaries data and need to be passed to the user to display can any one tell me how to implement this ? And my code is as shown below if let addressArray = jsonObj!.value(forKey: "address") as? NSArray{ for array in addressArray { if let addressDict = array as? NSDictionary{ if let Default = addressDict.value(forKey: "default"){ } } } }

'NSConcreteMutableAttributedString initWithString:: nil value' when using Google Nearby Messages

一个人想着一个人 提交于 2019-12-13 21:51:28
问题 I was following Google's documentation for using NearbyMessages API. I'm using Swift3. I have the following code to set up the app to publish to nearby. let messageManager = GNSMessageManager(apiKey: "someky") var publication: GNSPublication? let message = GNSMessage(content:"name".data(using: .utf8)) if let messageManager = messageManager, let message = message { publication = messageManager.publication(with:message) } I ran the app on the simulator. Then the app crashes in the 5th line (The

Protocol type cannot be instantiated

五迷三道 提交于 2019-12-13 18:31:06
问题 Consider the following code: protocol Color { var color: UIColor { get } } struct Ball : Color { var color: UIColor } let ball = Ball(color: .white) print(ball) This works, and results in: Ball(color: UIExtendedGrayColorSpace 1 1) Now, I would like to make a function in the protocol, that given an array of colors, returns an array of items (balls, or any other type that conforms to Color ) with that color: extension Color { func multipleColors(colors: [UIColor]) -> [Color] { var coloredItems