将枚举值分配给Obj-C中的属性

时间:2016-05-26 00:00:14

标签: objective-c swift enums

我在Swift中有以下代码。我如何将其转换为Objective-C? (是的,Swift到Objective-C);)

import praw
import argparse

user_agent = 'PyRedditScraper v0.1 by /u/PizzaFrog'
client_id = 'HIDDEN'
client_secret = 'HIDDEN'
redirect_uri = 'HIDDEN'

parser = argparse.ArgumentParser(description = 'Scrape the specified subreddit')
parser.add_argument('subreddit', help='the subreddit')
args = parser.parse_args()

print 'Scraping /r/' + args.subreddit + '...'
r = praw.Reddit(user_agent = user_agent,
                client_id = client_id,
                client_secret = client_secret,
                redirect_uri = redirect_uri)
subreddit = r.get_subreddit(args.subreddit)
for post in subreddit.get_hot(limit = 10):
    print 'title: ' + post.title
    print 'text: ' + post.selftext
    print 'score: ' + post.score
    print '--------------------'

我在Obj-C中尝试了以下内容,我不确定如何为我的属性分配值class PopAnimator: NSObject, UIViewControllerAnimatedTransitioning { enum PopTransitionMode: Int { case Present, Dismiss } var transitionMode: PopTransitionMode = .Present } 类型。

PopTransitionMode

1 个答案:

答案 0 :(得分:2)

您可以使用枚举值。有了更好的命名,枚举如下:

typedef NS_ENUM(NSInteger, PopTransitionMode) {
    PopTransitionModePresent,
    PopTransitionModeDismiss
};

这样初始化:

// if the initializer takes a param
- (id)initWithTransitionMode:(PopTransitionMode)transitionMode {
    self = [self init];
    if (self) {
        _transitionMode = transitionMode;
    }
   return self;
}

// OR, if the initializer hard-codes a param
- (id)init {
    self = [super init];
    if (self) {
        _transitionMode = PopTransitionModeDismiss;
    }
   return self;
}