3
- (void) tapGesture: (id)sender
{
    UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender;
    NSInteger userID = gesture.view.tag;

    UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main"
                                                         bundle:nil];
    OthersProfile *vc = (OthersProfile*)[storyboard instantiateViewControllerWithIdentifier:@"othersprofile"];
    NSString *strUserID = [NSString stringWithFormat:@"%ld", (long)userID];

    vc.userID = strUserID;
    [self.viewController.navigationController pushViewController:vc
                                                        animated:YES];
}

It used to work with Xcode 8 / Swift 3 but seems like there is a problem with Xcode 9 and swift 4.

I am having property userID not found error.

In Swift file:

var userID : String = ""
override func viewDidLoad() {
    print(userID) //no value here
}

Anyone with any idea?

3
  • Are you sure this code was working in XCode8? Commented Oct 17, 2017 at 13:01
  • @PuneetSharma sorry i updated my question Commented Oct 17, 2017 at 13:07
  • Swift 4 does not expose everything to the Objective-C runtime anymore, so you may have to annotate the property with @objc Commented Oct 17, 2017 at 13:12

2 Answers 2

5

Try this instead:

@objc var userID : String = "

The rules for exposing Swift code to Objective-C have changed in Swift 4. As such, your code was okay in Swift 3 and hence the confusion you are facing ;)

The new design is fully detailed in the corresponding Swift Evolution proposal.

Sign up to request clarification or add additional context in comments.

1 Comment

@UtkuDalmaz ...this is, unfortunately, a very common issue when migrating from Swift 3 to 4 :-(
0

Addression your other question you should fix how you access controller:

This is because vc.user is nil when you are trying to set it, add a variable to swift controller and set it instead of `vc.user.text

vc.yourVariable = strUserID;
[self.viewController.navigationController pushViewController:vc
                                                    animated:YES];

then in viewDidAppear you will be able to set it with this variable

 @IBOutlet var user: UILabel!
 public var yourVariable: String = ""

 override func viewDidLoad() {
     user.text = yourVariable
     print(user.text!) //should be value

 }

4 Comments

I tried this but this time I am having Property 'userID' not found on object of type 'OthersProfile *'? error. Check my other question stackoverflow.com/questions/46754687/…
did you import your file to see this variables?
I didn't understand your question?
i did upate answer, check if setting variable public helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.