swift3

How to check if two asynchronous tasks are done with success

谁说胖子不能爱 提交于 2019-12-12 09:17:48
问题 What is the best and easiest way to implement this flowchart in a function? Right now I'm using two dispatch groups but I need to check if they're both done, and not only when they finish. If they are done then: friends array will have elements nicknames array will have elements note: FB is Facebook and FIR is Firebase database 回答1: You could do this using DispatchGroup . Try the following playground; import UIKit import XCPlayground let dispatchGroup = DispatchGroup.init() for index in 0...4

How can I replace level button image with a screenshot of the level game scene?

倾然丶 夕夏残阳落幕 提交于 2019-12-12 08:41:41
问题 I know how to take and save a screenshot to the photo library. I do this using the code below. I would like to replace my level scene button images with screenshots of my gameScene. Say my image buttons are 150x150. How can I achieve this? func takeScreenShot(scene:SKScene) { let bounds = self.scene!.view?.bounds UIGraphicsBeginImageContextWithOptions(/*CGRect(x: 0, y: 0, width: 100, height: 100).size*/bounds!.size, true, UIScreen.main.scale) self.scene?.view?.drawHierarchy(in: bounds!,

How to write Application Logs to File and get them

梦想的初衷 提交于 2019-12-12 08:38:50
问题 I´m taking baby steps in iOS development and searching for a method to use logging in iOS. I found these docs about logging with swift 3 : https://developer.apple.com/documentation/os/logging#1682426 The Docs say that the logs aren´t saved on disk. What is the typical way to get the logs and process the file? 回答1: put this file to your project // // log.swift // logtest // import Foundation struct Log: TextOutputStream { func write(_ string: String) { let fm = FileManager.default let log = fm

Swift 3 - Adjust Font Size to Fit Width, Multiple Lines

心已入冬 提交于 2019-12-12 08:36:51
问题 I have a UILabel and it is set to 42.0 pt font, and the width of the label is set using autoconstraints based on factors other than the label itself (aka the things to the right and left of the label determine the label's width). I would like to auto-adjust the font size to fit the width of the label, however also break to two lines when it can. Similar to this: I know you can adjust the font size to fit the width of the label, but only when the number of lines is set to 1. How would I

SKShader to create parallax background

有些话、适合烂在心里 提交于 2019-12-12 08:13:44
问题 A parallax background with a fixed camera is easy to do, but since i'm making a topdown view 2D space exploration game, I figured that having a single SKSpriteNode filling the screen and being a child of my SKCameraNode and using a SKShader to draw a parallax starfield would be easier. I went on shadertoy and found this simple looking shader. I adapted it successfully on shadertoy to accept a vec2() for the velocity of the movement that I want to pass as an SKAttribute so it can follow the

What is import func, struct, class, and @_exported in Swift?

非 Y 不嫁゛ 提交于 2019-12-12 07:34:54
问题 In Apple's github for the Swift Package manager they use import func POSIX.isatty import func libc.strerror_r import var libc.EINVAL import var libc.ERANGE import struct PackageModel.Manifest source There is also a file where the only code in it is @_exported source @_exported import func libc.fileno Is this a Swift 3 feature? I can not find anywhere that you can import a type in the Swift documentation and nothing on @_exported . 回答1: You can import only a specific part of a module, not a

Random Alphanumeric String Linux Swift 3

不想你离开。 提交于 2019-12-12 07:27:55
问题 Im having 2 problems when trying to generate a random string in Linux with Swift 3. arc4random_uniform is not available in Linux only on BSD. SO i was able to get away with using random() function. And this worked when i was generating random numbers of a variable size (See code below) func generateRandomNumber() -> Int { var place = 1 var finalNumber = 0; #if os(Linux) for _ in 0..<5 { place *= 10 let randomNumber = Int(random() % 10) + 1 finalNumber += randomNumber * place } #else for _ in

Facebook not open page in app swift 3

大城市里の小女人 提交于 2019-12-12 07:23:17
问题 I have a link to my facebook, on my website, which opens in the phone's browser. I would like it to open in the facebook app by default, if the app is installed. I tried to put this code but it does not work. Opens the facebook page always and only via safari and not through the facebook app. If you can help me please. @IBAction func supporto(_ sender: UIBarButtonItem) { let Username = "831831923611308" let appURL = NSURL(string: "fb://profile/\(Username)")! let webURL = NSURL(string: "https:

Swift 3 convert String from isoLatin1 to utf8

假如想象 提交于 2019-12-12 06:56:35
问题 I need to convert an ISO-8859-1 (isoLatin1) encoded XML string to UTF-8. I tried some code I found on other questions, but most of them covers converting string to utf8 and vice-versa. I don't have any code, so none will be posted. Sorry, to make it clear, I tried: String(data:isoLatin1EncodedData, encoding: .uf8) is nil String(data:isoLatin1EncodedData, encoding: .isoLatin1) returns the string with the wrong encoding. String(utf8String: isoLatin1EncodedString.cString(using: String.Encoding

Display images in UITableview

送分小仙女□ 提交于 2019-12-12 06:49:15
问题 I'm trying to display images from api in the tableview but I get no images or anything. ImageTableViewCell has the outlet to the image only. import UIKit import Alamofire import SwiftyJSON import Haneke class SlideViewController: UIViewController , UITableViewDelegate , UITableViewDataSource { @IBOutlet weak var tableview : UITableView! var images = [String]() override func viewDidLoad() { super.viewDidLoad() tableview.delegate = self tableview.dataSource = self getJSON() } func