如何在Swift中访问其他类中的枚举值?

如何在Swift中访问其他类中的枚举值?,swift,enums,scenekit,Swift,Enums,Scenekit,我正在尝试使用scenekit为swift中的粒子发射器设置属性。 我觉得自己很愚蠢,因为我不知道如何设置设置为枚举的常量。 代码如下: //Create emitter let emitter = SCNParticleSystem() //set up the emitter trying to use the enum values emitter.birthLocation = SCNParticleBirthLocation.SCNParticleBirthLocationSurfa

我正在尝试使用scenekit为swift中的粒子发射器设置属性。 我觉得自己很愚蠢,因为我不知道如何设置设置为枚举的常量。 代码如下:

//Create emitter
let emitter = SCNParticleSystem()

//set up the emitter trying to use the enum values
emitter.birthLocation = SCNParticleBirthLocation.SCNParticleBirthLocationSurface

//I have tried a few other ways including:
emitter.birthLocation = .SCNParticleBirthLocationSurface
emitter.birthLocation = SCNParticleSystem.SCNParticleBirthLocation.SCNParticleBirthLocationSurface
这不是我在不同类中使用枚举时遇到的唯一问题,因此我认为我有一些根本错误。 苹果框架参考的链接,以防任何人需要:

最后是我的全部代码,以防它完全是我做错的其他东西

import Foundation
import SceneKit

class NextLevelScene: SCNScene{

override init(){
    super.init()
    let nextLevel: SCNNode = SCNNode()
    let text: SCNGeometry = SCNText(string: "Next Level", extrusionDepth: 0.0)
    let material = UIColor.blueColor()
    text.firstMaterial!.diffuse.contents = material
    nextLevel.geometry = text

    let exp = SCNParticleSystem()
    exp.loops = true
    exp.birthRate = 5000
    exp.emissionDuration = 0.2
    exp.spreadingAngle = 180
    exp.particleDiesOnCollision = true
    exp.particleLifeSpan = 0.2
    exp.particleLifeSpanVariation = 0.05
    exp.particleVelocity = 20
    exp.particleVelocityVariation = 3
    exp.particleSize = 0.05
    exp.stretchFactor = 0.02
    exp.particleColor = UIColor.redColor()
    exp.emitterShape = text
    //Error here
    exp.birthLocation = SCNParticleBirthLocation.SCNParticleBirthLocationSurface
    self.addParticleSystem(exp, withTransform: SCNMatrix4MakeRotation(0, 0, 0, 0))


    self.rootNode.addChildNode(nextLevel)
}

required init(coder: NSCoder) {
    super.init(coder: coder)
}
}

提前谢谢

如果您使用该命令,请单击Xcode源文件中的
出生地
,以获取 属性的定义,然后命令单击
SCNParticleBirthLocation
然后你会看到它在Swift中声明为

enum SCNParticleBirthLocation : Int {

    case Surface //particles are emitted on the surface of the emitter shape.
    case Volume //particles are emitted inside the volume of the emitter shape.
    case Vertex //particles are emitted on the vertices of the emitter shape.
}
所以你只需要

emitter.birthLocation = SCNParticleBirthLocation.Surface
它可以缩短(由于自动类型推断)为


我只想补充一点,就是当我在网页右上角选择“swift”时,常数的swift名称只会出现在scenekit的文档中。出于某种原因,选择“两者”仅显示目标C。这发生在OP中链接的页面以及其他一些页面上,但不是全部。
emitter.birthLocation = .Surface