菜鸟教程小白 发表于 2022-12-13 12:56:10

ios - 无法将 socket 连接到通用类


                                            <p><p>xcode 中似乎存在一个错误,阻止它“识别”包含泛型声明的类。</p>

<p>以这个类声明为例:</p>

<pre><code>@interface ABEBaseParseQueryViewController&lt;CellType: UITableViewCell *, Object: id&gt; : UIViewController &lt;UITableViewDelegate, ABEDatasourceResponder&gt;
</code></pre>

<p>如果我要在头文件中手动输入导出声明:</p>

<pre><code>@property (weak, nonatomic) IBOutlet UITextField *titleField;
</code></pre>

<p>侧边栏中表示未连接 socket 的点不会出现。此外,当尝试在 IB 中将文件的所有者设置为此类时,我没有得到任何自动完成功能,这使得 xcode 似乎根本无法“识别”该类。即使我手动设置文件所有者,我也无法将 socket 连接到文件。</p>

<p>如果我从类中删除泛型声明,此问题将得到解决。 (侧边栏中的圆圈再次出现,我可以再次连接 socket )</p>

<p>还有其他人遇到过这个问题吗?现在我可以删除通用声明,连接 socket 并将其放回原处,但这似乎是一个糟糕的解决方法。</p>

<p>这是 xcode 7.2。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你完全正确。一旦你有了一个泛型(如本例所示):</p>

<pre><code>ABEBaseParseQueryViewController&lt;CellType: UITableViewCell *, Object: id&gt;
</code></pre>

<p>该类不再是<strong>Interface Builder</strong>中<strong>Custom Class</strong>的选项。</p>

<p>您可以通过首先创建和选择来规避此限制:</p>

<pre><code>ABEBaseParseQueryViewController
</code></pre>

<p> <a href="/image/6veHX.png" rel="noreferrer noopener nofollow"><img src="/image/6veHX.png" alt="Pick ABEBaseParseQueryViewController before using generics"/></a> </p>

<p>在 Interface Builder 中,<em>稍后</em>将您的 <code>.h</code> 更改为</p>

<pre><code>ABEBaseParseQueryViewController&lt;CellType: UITableViewCell *, Object: id&gt;
</code></pre>

<p>请注意,此时您甚至无法在 <strong>Interface Builder</strong> 中选择通用的<strong>Custom Class</strong>。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 无法将 socket 连接到通用类,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34364263/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34364263/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 无法将 socket 连接到通用类