swift3

Use MeasurementFormatter to display meters as feet

穿精又带淫゛_ 提交于 2019-12-12 19:17:20
问题 I'm having trouble getting the new MeasurementFormatter class to give me results in appropriate units. I have values in meters that I want to display in localized strings, either meters or feet depending on the user's locale. I have this: let meters : Double = 10 let metersMeasurement = Measurement(value: meters, unit: UnitLength.meters) let measurementFormatter = MeasurementFormatter() measurementFormatter.locale = Locale(identifier: "en_US") let localizedString = measurementFormatter.string

Alamofire and Reachability.swift not working on xCode8-beta5

末鹿安然 提交于 2019-12-12 19:03:22
问题 I have a custom CocoaPod created in swift2.3 and it has Alamofire and Reachability libraries inside the project. I mean I did integrate Alamofire and Reachability into the project manually. It still works perfectly on xCode7.3.1 and I am going to update it to swift3 on xCode8-Beta5. I tried to update it but I couldn't get it done successfully. Here is how I did for the update. Replaced Alamofire and Reachability in the project folder for swift3 from https://github.com/Alamofire/Alamofire/tree

Accessing “self” in initializing closure

北城余情 提交于 2019-12-12 18:29:03
问题 In Swift 3 the dispatch_once function was removed and the migration guide suggests to use initializing closure: let myGlobal = { … global contains initialization in a call to a closure … }() _ = myGlobal // using myGlobal will invoke the initialization code only the first time it is used. I'd like to access 'self' instance variables from within the initializing closure like so: class SomeClass { var other = SomeOtherClass() let initialize: () = { // self.other - this doesn't work, complains

Swift's memory management

▼魔方 西西 提交于 2019-12-12 18:26:47
问题 I'm a little confused regarding Swift's memory management. Can someone explain to me how come kid1 always stays at the same memory address? Even when I do kid1=kid2 or initialize a new object? 回答1: Your code prints the memory location of the kid1 variable, and that does not change if you assign a new value to the variable. If Kid is a reference type (class) then you can use ObjectIdentifier to get a unique identifier for the class instance that the variable references: var kid1 = Kid(name: "A

No such a module 'Firebase' in Tests.swift file after Converting to swift 3

北城以北 提交于 2019-12-12 18:08:14
问题 After I converted the project to swift 3 I'm getting this error in Test.swift file: No such module 'Firebase' Command/usr/bin/ditto failed with code 1 is that mean I have to update the firebase framework? Why that happened? *The application still runs though! *Here's the pod file: # Uncomment this line to define a global platform for your project # platform :ios, '9.0' use_frameworks! target 'TheTestingApp' do pod 'Firebase' pod 'Firebase/Auth' pod 'Firebase/Database' pod 'Firebase/Storage'

how to change disabled item color in TabBar in swift 3?

跟風遠走 提交于 2019-12-12 18:02:13
问题 I have a TabBar in my project and when user select item this item will disable but the color will change too! I want the color is same as other items color in TabBar I used item.isEnabled = false for disable item but this codes here won't work for this item override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.tabBar.barTintColor = UIColor.init(red: 126/255, green: 0/255, blue: 64/255, alpha: 1.0) if #available(iOS 10.0, *) { self.tabBar.unselectedItemTintColor

tableView.reloadData() Table not updating

左心房为你撑大大i 提交于 2019-12-12 17:30:00
问题 The table does not display the updated array to return to the cell. When I launch the app I get blank cells. All permissions have been given in the storyboard. I tried the tableView.reloadData() everywhere but can't seem to make it work either. If anyone can explain where Im going wrong that would really help me get better. class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { @IBOutlet weak var slider: UISlider! @IBAction func sliderSelector(_ sender: Any) {

Extending existing protocol to conform to another protocol

核能气质少年 提交于 2019-12-12 17:02:04
问题 Hello my goal here is to extend (in swift 3) a protocol I have in a framework to conform to another Protocol protocol SomeProtocol {} protocol SomeOtherProtocol {} extension SomeOtherProtocol: SomeProtocol {} The problem here is that I get an error: "Extension of protocol 'SomeOtherProtocol' cannot have an inheritance clause" If this is not possible how do I achieve such thing or what's the "swift way"? 来源: https://stackoverflow.com/questions/44425503/extending-existing-protocol-to-conform-to

Swift equivalent of Unity3d Coroutines?

好久不见. 提交于 2019-12-12 16:52:28
问题 Looking how to build something similar in Swift 3. I'm used to using this sort of architecture in Unity3d, perhaps there isn't anything similar to handle async data. I've heard of completion blocks + using protocols/delegates to pass data in Swift but I thought it'd be easier to have a public function that gets the data and then use a coroutine to wait until all the data is in the VC to start things up. Here is C# code I'd use to create them: List<Int> data = new List<Int>; private

NSToolbarFlexibleSpaceItem is constraint to NSSplitViewItem in Swift

余生长醉 提交于 2019-12-12 16:08:33
问题 Almost all macOS official apps have this toolbar's feature which the NSToolbarItem flexible space is constraint to NSSplitViewItem view. I first thought maybe there are 3 different sections on NSToolbar. But it just ONE toolbar. You can open Notes app and customize the toolbar. The first flexible space is detected and moved along with first split view item. The second flexible space is detected and moved along with the second split item. The rest will be just normal flexible spaces. If there