1

I have create one structure in swift, I want to create and use same with Objective c.

Constant.Swift

struct Segues
{
    static let SignUpToSignIn = "SignUpToSignIn"
    static let SingInToForgotPassword = "SingInToForgotPassword"
    static let MatchesToProfile = "MatchesToProfile"
}

ViewController.swift

self.performSegue(withIdentifier: Segues.MatchesToProfile, sender: nil)

I have created above structure with swift now please help me to do same with Objective C. I have tried but I can not find the way that can be done with Objective-C struct.

Is it possible using structure ? or there is any other way to achieve same.

Thanks in advance!

Aarti Oza
  • 1,134
  • 2
  • 14
  • 31

1 Answers1

0

EDIT: See Martin R's link in his comment to the OP for a great solution.

The simplest way I can think of is to make a class with only class methods to use (no instance variables or methods).

@interface Segues : NSObject

+ (NSString *)signUpToSignIn;
+ (NSString *)signInToForgotPassword;
+ (NSString *)matchesToProfile;

@end

Using them in code would look like this:

[self performSegueWithIdentifier:[Segues signUpToSignIn] sender: nil];

A simpler alternative is to use constants prefaced with Segue. This requires little code, but you lose the Segues namespace that a class gives you.

// In a .h file
extern NSString *const SeguesSignUpToSignIn;
extern NSString *const SeguesSignInToForgotPassword;
extern NSString *const SeguesMatchesToProfile;

// In a .m file
NSString *const SeguesSignUpToSignIn = @"SignUpToSignIn";
// copy for the others

// Usage
[self performSegueWithIdentifier:SeguesSignUpToSignIn];

There are a few other alternatives with enums and some methods to turn the enums into string values or using C structs, but those are a lot more work and more code for very little gain.

keithbhunter
  • 12,258
  • 4
  • 33
  • 58
  • exactly for a little thing I have to do more code. And your answer still have more code to just get segue identifire. Thanks for the help :) – Aarti Oza May 11 '17 at 13:36