Error[8]: Undefined offset: 15, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

迅速列出课程属性 使用
Mirror

这是一个纯粹的Swift解决方案,但有一些限制:

protocol PropertyNames {    func propertyNames() -> [String]}extension PropertyNames{    func propertyNames() -> [String] {        return Mirror(reflecting: self).children.flatMap { 
  • 返回Objective-C对象的空数组
  • .label } }}class Person : PropertyNames { var name = "Sansa Stark" var awesome = true}Person().propertyNames() // ["name", "awesome"]

    局限性:

    您可以

    class_copyPropertyList
    根据所需的行为来解决此问题。

    使用
    var count = UInt32()let classToInspect = NSURL.selflet properties : UnsafeMutablePointer <objc_property_t> = class_copyPropertyList(classToInspect, &count)var propertyNames = [String]()let intCount = Int(count)for var i = 0; i < intCount; i++ {    let property : objc_property_t = properties[i]    guard let propertyName = NSString(UTF8String: property_getName(property)) as? String else {        debugPrint("Couldn't unwrap property name for (property)")        break    }    propertyNames.append(propertyName)}free(properties)print(propertyNames)

    如果使用的是Objective-C对象,则可以使用以下方法:

    classToInspect

    到控制台的输出是否

    NSURL
    ["pathComponents", "lastPathComponent", "pathExtension","URLByDeletingLastPathComponent", "URLByDeletingPathExtension","URLByStandardizingPath", "URLByResolvingSymlinksInPath","dataRepresentation", "absoluteString", "relativeString", "baseURL","absoluteURL", "scheme", "resourceSpecifier", "host", "port", "user","password", "path", "fragment", "parameterString", "query", "relativePath","hasDirectoryPath", "fileSystemRepresentation", "fileURL","standardizedURL", "filePathURL"]

    NSURL

    这在 *** 场上行不通。只需替换

    EachDayCell
    为[+++](或重用与扩展相同的逻辑),它就可以工作。



    )
    File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
    File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
    File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
    迅速列出课程属性_随笔_内存溢出

    迅速列出课程属性

    迅速列出课程属性,第1张

    迅速列出课程属性 使用
    Mirror

    这是一个纯粹的Swift解决方案,但有一些限制:

    protocol PropertyNames {    func propertyNames() -> [String]}extension PropertyNames{    func propertyNames() -> [String] {        return Mirror(reflecting: self).children.flatMap { 
  • 返回Objective-C对象的空数组
  • .label } }}class Person : PropertyNames { var name = "Sansa Stark" var awesome = true}Person().propertyNames() // ["name", "awesome"]

    局限性:

      var favoriteFood: String { return "Lemon Cake" }
    • 将不返回计算的属性,即:

      self
    • 如果

      class Person : PropertyNames {var name = "Bruce Wayne"
      是类的实例(相对于结构),则不会报告其超类的属性,即:


      }

      }

      class Superhero : Person {
      var hasSuperpowers = true

      superclassMirror()

      Superhero().propertyNames() // [“hasSuperpowers”] — no “name”

    您可以

    class_copyPropertyList
    根据所需的行为来解决此问题。

    使用
    var count = UInt32()let classToInspect = NSURL.selflet properties : UnsafeMutablePointer <objc_property_t> = class_copyPropertyList(classToInspect, &count)var propertyNames = [String]()let intCount = Int(count)for var i = 0; i < intCount; i++ {    let property : objc_property_t = properties[i]    guard let propertyName = NSString(UTF8String: property_getName(property)) as? String else {        debugPrint("Couldn't unwrap property name for (property)")        break    }    propertyNames.append(propertyName)}free(properties)print(propertyNames)

    如果使用的是Objective-C对象,则可以使用以下方法:

    classToInspect

    到控制台的输出是否

    NSURL
    ["pathComponents", "lastPathComponent", "pathExtension","URLByDeletingLastPathComponent", "URLByDeletingPathExtension","URLByStandardizingPath", "URLByResolvingSymlinksInPath","dataRepresentation", "absoluteString", "relativeString", "baseURL","absoluteURL", "scheme", "resourceSpecifier", "host", "port", "user","password", "path", "fragment", "parameterString", "query", "relativePath","hasDirectoryPath", "fileSystemRepresentation", "fileURL","standardizedURL", "filePathURL"]

    NSURL

    这在 *** 场上行不通。只需替换

    EachDayCell
    为(或重用与扩展相同的逻辑),它就可以工作。



    欢迎分享,转载请注明来源:内存溢出

    原文地址: http://outofmemory.cn/zaji/4916158.html

    (0)
    打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
    上一篇 2022-11-12
    下一篇 2022-11-12

    发表评论

    登录后才能评论

    评论列表(0条)

    保存