gpt4 book ai didi

macos - xcode 4 上的语义警告

转载 作者:行者123 更新时间:2023-12-03 16:01:25 24 4
gpt4 key购买 nike

我在 Xcode 4 上收到语义警告:*“struct sockaddr_in”的声明在此函数之外不可见*该结构似乎是在 netinet/in.h 中声明的

该警告在 Reachability.h 上标记,它是我从 Apple 示例下载的一个类。

#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>

typedef enum {
NotReachable = 0,
ReachableViaWiFi,
ReachableViaWWAN
} NetworkStatus;
#define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification"

@interface Reachability: NSObject
{
BOOL localWiFiRef;
SCNetworkReachabilityRef reachabilityRef;
}

//reachabilityWithHostName- Use to check the reachability of a particular host name.
+ (Reachability*) reachabilityWithHostName: (NSString*) hostName;

//reachabilityWithAddress- Use to check the reachability of a particular IP address.
+ (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress;

//reachabilityForInternetConnection- checks whether the default route is available.
// Should be used by applications that do not connect to a particular host
+ (Reachability*) reachabilityForInternetConnection;

//reachabilityForLocalWiFi- checks whether a local wifi connection is available.
+ (Reachability*) reachabilityForLocalWiFi;

//Start listening for reachability notifications on the current run loop
- (BOOL) startNotifier;
- (void) stopNotifier;

- (NetworkStatus) currentReachabilityStatus;
//WWAN may be available, but not active until a connection has been established.
//WiFi may require a connection for VPN on Demand.
- (BOOL) connectionRequired;
@end

我不明白这个警告,有人能给我解释一下吗?谢谢。

最佳答案

有人针对该行为提交了错误报告并得到了某人的回复 here 。本质上,问题在于您在方法的参数中声明了一个新的结构(就编译器所知),因此它在其他地方无法访问。

有一个快速修复方法。只需将以下行添加到 Reachability.h 中:

#import <netinet/in.h>

关于macos - xcode 4 上的语义警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6654526/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com