ios - 从一个函数引用另一个函数中的常量

标签 ios swift facebook variables constants

<分区>

我正在尝试发送从 facebookSDK 收集的用户信息,并执行 HTTP POST 发送我收集的存储在常量中的详细信息。

我是快速开发的新手,虽然这个解决方案可能很简单,但我无法配置一个可行的解决方案。

我需要将 fetchProfile() 函数中的数据传递到 data_request() 函数中,以便将数据传递给 API。

The image shows the data_request function, highlighted is the line where i need to reference the data stored in constants within the fetchProfile() function

This image shows the fetchProfile() function holding the data needed to be passed to data_request()

非常感谢任何反馈或指导。

最佳答案

你的两个函数都有闭包,这意味着从异步网络调用中回调。所以你的 main 函数会先完成,然后当你的网络调用完成时,闭包被调用。所以在你的情况下,你需要等到 fetchProfile() 完成异步调用才能获取数据,然后在 data_request() 函数中使用它。所以它看起来像

func fetchProfile(){
    //...
    FBSDKGraphRequest....
        void in
        //prepare your data here
        //call data_request
}

关于ios - 从一个函数引用另一个函数中的常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44946236/

相关文章:

android - 如何让 PhoneGap Facebook Connect 插件正常工作

iOS 内存警告发送到释放的 UIViewController

ios - Swift 3 升级问题转换

ios - 在 Swift 中从属性检查器列表更改栏按钮图像

swift 面向对象 : How to encapsulate Search behavior

facebook - WhatsApp 深层链接到特定手机号码

android - 适用于 Android 的 iOS Facebook 滑动菜单

ios - 将 UITextField 设置为电话号码

ios - UITableView 滚动不流畅

iOS indexPathsForSelectedRows 和初始选择