Latest 1.2.0
Homepage https://github.com/itsthejb/JCSegueUserInfo
License MIT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
Platforms ios 5.0, requires ARC
Dependencies ObjcAssociatedObjectHelpers, JRSwizzle
Authors

Build Status
Build Status

Love UIStoryboard? Love UIStoryboardSegue even more? Hate the way the don’t work as closely together as they could do? Try JCSegueUserInfo.

Imagine the common pattern where you’d like to trigger a storyboard segue programatically, but would also like to set a few properties on the destination view controller. Currently, you’d have to do something like this:

...
    self.temporaryProperty = @"foo";
    self.anotherTemporaryProperty = @(1);
    [self performSegueWithIdentifier:@"MySegue" sender:self];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqual:@"MySegue"]) {
        SegueViewController *controller = segue.destinationViewController;
        controller.someProperty = self.temporaryProperty;
        controller.anotherProperty = self.anotherTemporaryProperty;   
        self.temporaryProperty = nil;
        self.anotherTemporaryProperty = nil;
    }
}

With JCSegueUserInfo you can do:

[self jc_performSegueWithIdentifier:@"MySegue"
                            sender:self
                          userInfo:@{ @"someProperty" : @"foo",
                                      @"anotherProperty" : @(1) }];

Much better!

-[UIViewController jc_performSegueWithIdentifier:sender:userInfo: accepts an NSDictionary which is used to set arbitrary properties on the destination view controller instance using the standard -[NSDictionary setValuesForKeysWithDictionary:] method. What we do is swizzle the normal -[UIViewController performSegueWithIdentifier:sender:] to allow these values to be set on the destination controller if they have be stored using the category method.

You can also store values to set when the segue is performed in advance, with -jc_setUserInfo:forSegueWithIdentifier:], and -jc_removeUserForSegueWithIdentifier:. These allow you to use this non-programatic segues; set the values when you have them and let UIKit take care of the segue in the normal fashion. Your values will be set on the desintation view controller.

Notes

We swizzle -[UIViewController performSegueWithIdentifier:sender:] in order to deliver this feature. This makes this library problematic with any other that swizzles the same method. Consider yourself warned :wink:

Enjoy!


[email protected]

Latest podspec

{
    "name": "JCSegueUserInfo",
    "version": "1.2.0",
    "summary": "Programmatic UIStoryboardSegue - the missing (data) link.",
    "license": {
        "type": "MIT",
        "text": "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE"
    },
    "authors": {
        "Jonathan Crooke": "[email protected]"
    },
    "dependencies": {
        "ObjcAssociatedObjectHelpers": [
            "1.2.1"
        ],
        "JRSwizzle": [
            "1.0"
        ]
    },
    "homepage": "https://github.com/itsthejb/JCSegueUserInfo",
    "platforms": {
        "ios": "5.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/itsthejb/JCSegueUserInfo.git",
        "tag": "v1.2.0"
    },
    "source_files": "JCSegueUserInfo/*.{h,m}"
}

Pin It on Pinterest

Share This