Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
494 views
in Technique[技术] by (71.8m points)

uistoryboardsegue - Swift: programmatically enumerate outgoing segues from a UIVIewController

I want to list the outgoing segues from a UIViewController, as described in Programmatically enumerate outgoing Segues for a UIViewController, but in Swift. (Swift 2, Xcode 7, iOS8+).

I can do

override func viewDidLoad() {
    super.viewDidLoad()
    let s = valueForKey("storyboardSegueTemplates")
    print("switchingVC: segues: (s)") 
}

and that produces output like

switchingVC: segues: Optional((
    "<UIStoryboardPresentationSegueTemplate: 0x1754a130>",
    "<UIStoryboardPresentationSegueTemplate: 0x17534f60>",
    "<UIStoryboardPresentationSegueTemplate: 0x17534fc0>"
))

but I struggle to produce anything after that. I can't find any definition of the UIStoryboardPresentationSegueTemplate. How can I persuade Swift to tell me what's inside it? How can I find the segue identifier?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

this valueForKey("storyboardSegueTemplates") is UNDOCUMENTED property and UIStoryboardPresentationSegueTemplate is UNDOCUMENTED class. Beware of rejection from App Store if you are uploading application to App Store.

If you want to use this in your in-house projects, use as following

for template in (valueForKey("storyboardSegueTemplates") as? [AnyObject])! {
    if let identifier = template.valueForKey("identifier") as? String {
        print("identifier - " + identifier)
    }
    else {
        print("no identifier for (template)")
    }
}

Found from https://github.com/JaviSoto/iOS9-Runtime-Headers/blob/master/Frameworks/UIKit.framework/UIStoryboardSegueTemplate.h


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...