菜鸟教程小白 发表于 2022-12-12 13:17:20

ios - 无法构建 objective-c 模块


                                            <p><p>我正在用 swift 制作一个 xcode 项目,它工作正常,但突然它开始给我这个错误。 </p>

<blockquote>
<p>Could not build Objective C Module &#39;Foundation&#39;</p>

<p>/Users/admin/Downloads/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.2.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSNotification.h:17:4: Prefix attribute must be followed by an interface or protocol</p>
</blockquote>

<p>即使我创建了一个新项目并且只构建它什么都不做,也会显示此错误。该项目未建成。当我单击错误消息时,它会将我带到此文件 <strong><em>NSNotification.h</em></strong></p>

<p>这是这个文件的内容</p>

<pre><code>/*NSNotification.h
Copyright (c) 1994-2016, Apple Inc. All rights reserved.
*/

#import &lt;Foundation/NSObject.h&gt;

typedef NSString *NSNotificationName NS_EXTENSIBLE_STRING_ENUM;

@class NSString, NSDictionary, NSOperationQueue;

NS_ASSUME_NONNULL_BEGIN

/****************   Notifications   ****************/

@interface NSNotification : NSObject &lt;NSCopying, NSCoding&gt;

id@property (nullable, readonly, retain) id object;
@property (nullable, readonly, copy) NSDictionary *userInfo;

- (instancetype)initWithName:(NSNotificationName)name object:(nullable    id)object userInfo:(nullable NSDictionary *)userInfo NS_AVAILABLE(10_6, 4_0) NS_DESIGNATED_INITIALIZER;
- (nullable instancetype)initWithCoder:(NSCoder *)aDecoder   NS_DESIGNATED_INITIALIZER;

@end

@interface NSNotification (NSNotificationCreation)

+ (instancetype)notificationWithName:(NSNotificationName)aName object:      (nullable id)anObject;
+ (instancetype)notificationWithName:(NSNotificationName)aName object:      (nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo;

- (instancetype)init /*NSUIImagePNGRepresentation_UNAVAILABLE*/;    /* do   not invoke; not a valid initializer for this class */

@end

/****************   Notification Center ****************/

@interface NSNotificationCenter : NSObject {
@package
void *_impl;
void *_callback;
void *_pad;
}

#if FOUNDATION_SWIFT_SDK_EPOCH_AT_LEAST(8)
@property (class, readonly, strong) NSNotificationCenter *defaultCenter;

- (void)addObserver:(id)observer selector:(SEL)aSelector name:(nullable      NSNotificationName)aName object:(nullable id)anObject;
#endif

- (void)postNotification:(NSNotification *)notification;
- (void)postNotificationName:(NSNotificationName)aName object:(nullableid)anObject;
- (void)postNotificationName:(NSNotificationName)aName object:(nullable id)anObject userInfo:(nullable NSDictionary *)aUserInfo;

-   (void)removeObserver:(id)observer;
- (void)removeObserver:(id)observer name:(nullable NSNotificationName)aName object:(nullable id)anObject;

- (id &lt;NSObject&gt;)addObserverForName:(nullable NSNotificationName)name object:(nullable id)obj queue:(nullable NSOperationQueue *)queue usingBlock:(void (^)(NSNotification *note))block NS_AVAILABLE(10_6, 4_0);
// The return value is retained by the system, and should be held onto by the caller in
// order to remove the observer with removeObserver: later, to stop observation.

@end

NS_ASSUME_NONNULL_END
</code></pre>

<p>请帮我解决这个问题。对此我将不胜感激。谢谢。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>NSNotification.h 中的这一行好像被修改了:</p>

<pre><code>id@property (nullable, readonly, retain) id object;
</code></pre>

<p>删除该行前面的 <code>id</code> 并尝试重新编译。那应该解决它。 </p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 无法构建 objective-c模块,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/43156855/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/43156855/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 无法构建 objective-c 模块