久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='W2aYK'></bdo><ul id='W2aYK'></ul>

    <small id='W2aYK'></small><noframes id='W2aYK'>

  • <i id='W2aYK'><tr id='W2aYK'><dt id='W2aYK'><q id='W2aYK'><span id='W2aYK'><b id='W2aYK'><form id='W2aYK'><ins id='W2aYK'></ins><ul id='W2aYK'></ul><sub id='W2aYK'></sub></form><legend id='W2aYK'></legend><bdo id='W2aYK'><pre id='W2aYK'><center id='W2aYK'></center></pre></bdo></b><th id='W2aYK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='W2aYK'><tfoot id='W2aYK'></tfoot><dl id='W2aYK'><fieldset id='W2aYK'></fieldset></dl></div>
    <tfoot id='W2aYK'></tfoot>

        <legend id='W2aYK'><style id='W2aYK'><dir id='W2aYK'><q id='W2aYK'></q></dir></style></legend>

        Swift 擴展:兩個模塊中的相同擴展功能

        Swift Extension: same extension function in two Modules(Swift 擴展:兩個模塊中的相同擴展功能)
          <tbody id='WrXit'></tbody>

        <tfoot id='WrXit'></tfoot>

      1. <small id='WrXit'></small><noframes id='WrXit'>

              <bdo id='WrXit'></bdo><ul id='WrXit'></ul>

                • <legend id='WrXit'><style id='WrXit'><dir id='WrXit'><q id='WrXit'></q></dir></style></legend>
                  <i id='WrXit'><tr id='WrXit'><dt id='WrXit'><q id='WrXit'><span id='WrXit'><b id='WrXit'><form id='WrXit'><ins id='WrXit'></ins><ul id='WrXit'></ul><sub id='WrXit'></sub></form><legend id='WrXit'></legend><bdo id='WrXit'><pre id='WrXit'><center id='WrXit'></center></pre></bdo></b><th id='WrXit'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='WrXit'><tfoot id='WrXit'></tfoot><dl id='WrXit'><fieldset id='WrXit'></fieldset></dl></div>
                  本文介紹了Swift 擴展:兩個模塊中的相同擴展功能的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  假設(shè)我有一個名為 SwiftKit 的框架,它有一個名為 someClassMethod 的 UIView 擴展類方法和一個名為 someProperty 的屬性:

                  Say I have a Framework called SwiftKit, which has a UIView's extension class method named someClassMethod and a property named someProperty within it:

                  // SwiftKit
                  public extension UIView {
                      class func someClassMethod() {
                          print("someClassMethod from Swift Kit")
                      }
                  
                      var someProperty: Double {
                          print("someProperty from Swift Kit")
                          return 0
                      }
                  }
                  

                  我還有一個叫 SwiftFoundation 的框架,它里面還有一個 UIView 的擴展類方法叫 someClassMethod 和一個叫 someProperty 的屬性:

                  And I also have a Framework called SwiftFoundation, which also has a UIView's extension class method named someClassMethod and a property named someProperty within it:

                  // SwiftFoundation
                  public extension UIView {
                      class func someClassMethod() {
                          print("someClassMethod from Swift Foundation")
                      }
                  
                      var someProperty: Double {
                          print("someProperty from Swift Foundation")
                          return 0
                      }
                  }
                  

                  然后我創(chuàng)建了一個項目來介紹這些框架,事情是,如果我將它們都導(dǎo)入同一個 swift 文件并訪問這些擴展名,即使我指定了,我也會收到Ambiguous use of someProperty/someClassMethod()"錯誤SwiftKit.UIView.someClassMethod() 形式的調(diào)用:

                  Then I created a project introduced these Frameworks, things is, if I import both of them in the same swift file and access those extensions, I got a "Ambiguous use of someProperty/someClassMethod()" error, even if I specified the call in the form of SwiftKit.UIView.someClassMethod() :

                  import UIKit
                  import SwiftKit
                  import SwiftFoundation
                  
                  class ViewController: UIViewController {
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          // Do any additional setup after loading the view, typically from a nib.
                  
                          self.view.someProperty              // error: Ambiguous use of 'somProperty'
                          SwiftKit.UIView.someClassMethod()   // error: Ambiguous use of 'someClassMethod()'
                      }
                  }
                  

                  如果我只導(dǎo)入其中一個,模棱兩可的錯誤就會消失,但會發(fā)生更奇怪的事情:

                  If I only import one of them, the ambiguous error goes away, but more strange thing happens:

                  import UIKit
                  import SwiftKit
                  //import SwiftFoundation
                  
                  class ViewController: UIViewController {
                      override func viewDidLoad() {
                          super.viewDidLoad()
                          // Do any additional setup after loading the view, typically from a nib.
                  
                          self.view.someProperty
                          SwiftKit.UIView.someClassMethod()
                      }
                  }
                  

                  控制臺打印出來:

                  來自 Swift 基金會的 someProperty

                  someProperty from Swift Foundation

                  來自 Swift Foundation 的 someClassMethod

                  someClassMethod from Swift Foundation

                  我的問題是:我怎樣才能毫不含糊地調(diào)用這些擴展(類/實例方法、屬性)?如果我不能,是否意味著我們應(yīng)該像通常使用 Objective-C 一樣為擴展名添加前綴?

                  My question is: How can I call these extensions(both class/instance method, properties) without ambiguous? If I cannot, does it mean we should add prefix to extension names as we usually do with Objective-C?

                  推薦答案

                  詳情

                  • Swift 3、Xcode 8.1
                  • Swift 4、Xcode 9.1
                  • Swift 5.1、Xcode 11.2.1
                  • 框架 SwiftFoundation 和 SwiftKit 具有相同名稱的屬性和函數(shù)

                    frameworks SwiftFoundation and SwiftKit has the same names of the properties and functions

                    使用不同的屬性和函數(shù)名稱

                    Use different names of the properties and functions

                    // SwiftFoundation
                    public extension UIView {
                        public class func swiftFoundationSomeClassMethod() {
                            print("someClassMethod from Swift Foundation")
                        }
                    
                        public var swiftFoundationSomeProperty: Double {
                            print("someProperty from Swift Foundation")
                            return 0
                        }
                    }
                    

                    方式2

                    對屬性和函數(shù)進行分組

                    Way2

                    Group the properties and functions

                    // SwiftKit
                    public extension UIView {
                        public class SwiftKit {
                            public class func someClassMethod() {
                                print("someClassMethod from Swift Kit")
                            }
                    
                            public var someProperty: Double {
                                print("someProperty from Swift Kit")
                                return 0
                            }
                        }
                    
                        var SwiftKit: SwiftKit { return SwiftKit() }
                    }
                    

                    結(jié)果

                    import UIKit
                    import SwiftKit
                    import SwiftFoundation
                    
                    class ViewController: UIViewController {
                    
                        override func viewDidLoad() {
                            super.viewDidLoad()
                    
                            _ = view.SwiftKit.someProperty
                            UIView.SwiftKit.someClassMethod()
                    
                            _ = view.swiftFoundationSomeProperty
                            UIView.swiftFoundationSomeClassMethod()
                        }
                    }
                    

                    項目

                    SwiftFoundation.UIView.swiftFoundationSomeClassMethod()
                    

                    您使用命名空間的變體不正確,因為這兩個框架的所有 UIView 擴展都包含在您的 UIView 類中.查看下圖,您可以在 SwiftFoundation 中看到 SwiftKit 類和 swiftFoundationSomeClassMethod().這可能會使其他開發(fā)人員感到困惑.

                    Your variant of using the namespaces is not correct because all UIView extensions from both frameworks are included in you UIView class. Look at image bellow, you can see SwiftKit class and swiftFoundationSomeClassMethod() inside SwiftFoundation. This can confuse other developers.

                    這篇關(guān)于Swift 擴展:兩個模塊中的相同擴展功能的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                    【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Swift: Geofencing / geolocations near user location(Swift:用戶位置附近的地理圍欄/地理位置)
                  Are namespace collisions really an issue in Objective-C?(命名空間沖突真的是 Objective-C 中的一個問題嗎?)
                  Swift#39;s standard library and name collision(Swift 的標(biāo)準(zhǔn)庫和名稱沖突)
                  Retrieving Keys From GeoFire within Radius in Swift(在 Swift 中從 Radius 中的 GeoFire 檢索密鑰)
                  MKMapView MKCircle renders a circle with too big radius(MKMapView MKCircle 渲染一個半徑太大的圓)
                  Invalid Float value - swift 3 ios(無效的浮點值 - swift 3 ios)
                • <i id='fTZPK'><tr id='fTZPK'><dt id='fTZPK'><q id='fTZPK'><span id='fTZPK'><b id='fTZPK'><form id='fTZPK'><ins id='fTZPK'></ins><ul id='fTZPK'></ul><sub id='fTZPK'></sub></form><legend id='fTZPK'></legend><bdo id='fTZPK'><pre id='fTZPK'><center id='fTZPK'></center></pre></bdo></b><th id='fTZPK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fTZPK'><tfoot id='fTZPK'></tfoot><dl id='fTZPK'><fieldset id='fTZPK'></fieldset></dl></div>

                  <legend id='fTZPK'><style id='fTZPK'><dir id='fTZPK'><q id='fTZPK'></q></dir></style></legend>

                            <tbody id='fTZPK'></tbody>

                          <tfoot id='fTZPK'></tfoot>
                            <bdo id='fTZPK'></bdo><ul id='fTZPK'></ul>

                            <small id='fTZPK'></small><noframes id='fTZPK'>

                            主站蜘蛛池模板: 国产成人精品一区二区三区网站观看 | 一区二区三区在线 | 久久精品中文字幕 | 久久亚| 国产一级免费视频 | 中文字幕精品一区二区三区精品 | 久久这里只有精品首页 | 99re在线视频精品 | 国产一级在线 | 久久国产精品无码网站 | 草b视频 | 亚洲最色视频 | 成人精品免费视频 | 欧美激情第一区 | 亚洲欧美男人天堂 | 91日韩在线 | 国产精品一区视频 | 亚洲成人综合社区 | 亚洲 欧美 综合 | 狠狠热视频 | 99在线免费观看视频 | 999精品视频 | 精品欧美一区二区三区久久久 | 99精品国产一区二区三区 | 亚洲性爰 | 国产午夜精品一区二区三区嫩草 | 欧美一级片在线看 | 麻豆久久久久久 | 久久午夜视频 | 亚洲美女网站 | 日韩三 | 日韩av看片 | 久久一久久 | 四虎在线观看 | a级网站| 亚洲日本一区二区三区四区 | 美女福利视频 | 亚洲精品日韩在线 | 欧美国产91 | 99热精品在线观看 | 二区三区av |