Best way to enum NSString

前端 未结 7 695
广开言路
广开言路 2021-02-02 13:23

Im digging for ways to enum objc object such as NSString, I remember there a new feature in a version of Xcode4+ which offering a new way to enum , but not clearly. Anyone know

相关标签:
7条回答
  • 2021-02-02 13:46

    This will be validated by compiler, so you won't mix up indices accidentally.

    NSDictionary *stateStrings =
     @{
       @(MCSessionStateNotConnected) : @"MCSessionStateNotConnected",
       @(MCSessionStateConnecting) : @"MCSessionStateConnecting",
       @(MCSessionStateConnected) : @"MCSessionStateConnected",
      };
    NSString *stateString = [stateStrings objectForKey:@(state)];
    

    var stateStrings: [MCSessionState: String] = [
        MCSessionState.NotConnected : "MCSessionState.NotConnected",
        MCSessionState.Connecting : "MCSessionState.Connecting",
        MCSessionState.Connected : "MCSessionState.Connected"
    ]
    var stateString = stateStrings[MCSessionState.Connected]
    
    0 讨论(0)
提交回复
热议问题