【问题标题】:Multiple Xcode projects will no longer successfully compile on a real iOS device多个 Xcode 项目将不再在真实的 iOS 设备上成功编译
【发布时间】:2016-11-29 10:52:42
【问题描述】:

我可能不小心编辑了 NSAttributedString.h 类和/或相关类,现在看来我的所有 Xcode 项目,包括我创建的项目都无法在我的 iPhone 上编译(iPhone 4s iOS 版本:9.3.2)(我的部署目标是 iOS 9.0。)。

Xcode 项目将成功构建并部署到模拟 iPhone。

以下是我在尝试为 iPhone 编译应用程序时遇到的错误列表:

System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:13:2: Prefix attribute must be followed by an interface or protocol
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:16:1: Expected method body
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:23:1: Expected method body
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:26:1: Expected method body
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:30:1: Expected method body
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:32:1: Expected method body
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:40:1: Expected method body
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:42:1: '@end' must appear in an Objective-C context
AppPods/Target Support Files/Pods-App/Pods-App-dummy.m:1:9: Could not build module 'Foundation'
Semantic Issue Group
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:14:1: Missing context for method declaration
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:22:1: Missing context for method declaration
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:25:1: Missing context for method declaration
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:28:1: Missing context for method declaration
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:31:1: Missing context for method declaration
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:39:1: Missing context for method declaration
System/Library/Frameworks/Foundation.framework/Headers/NSAttributedString.h:45:40: Attempting to use the forward class 'NSAttributedString' as superclass of 'NSMutableAttributedString'

我正在使用 Xcode 8 测试版。

有谁知道导致这个错误的原因是什么?

我已尝试重新启动并重新连接 iPhone、重新启动 Xcode、重新启动我的 Mac 并删除 DerivedData 文件夹。我读到here Expected method body 可能是由代码中的“杂散字符”引起的,但我找不到杂散字符。

这里是 NSAttributedString.h 类:

/*  NSAttributedString.h
    Copyright (c) 1994-2015, Apple Inc. All rights reserved.
*/


#import <Foundation/NSString.h>
#import <Foundation/NSDictionary.h> 

NS_ASSUME_NONNULL_BEGIN 

NS_CLASS_AVAILABLE(10_0, 3_2)

@property (readonly, copy) NSString *string;
- (NSDictionary<NSString *, id> *)attributesAtIndex:(NSUInteger)location effectiveRange:(nullable NSRangePointer)range;

@end

@interface NSAttributedString (NSExtendedAttributedString)


@property (readonly) NSUInteger length;
- (nullable id)attribute:(NSString *)attrName atIndex:(NSUInteger)location effectiveRange:(nullable NSRangePointer)range;
- (NSAttributedString *)attributedSubstringFromRange:(NSRange)range;

- (NSDictionary<NSString *, id> *)attributesAtIndex:(NSUInteger)location longestEffectiveRange:(nullable NSRangePointer)range inRange:(NSRange)rangeLimit;
- (nullable id)attribute:(NSString *)attrName atIndex:(NSUInteger)location longestEffectiveRange:(nullable NSRangePointer)range inRange:(NSRange)rangeLimit;

- (BOOL)isEqualToAttributedString:(NSAttributedString *)other;

- (instancetype)initWithString:(NSString *)str;
- (instancetype)initWithString:(NSString *)str attributes:(nullable NSDictionary<NSString *, id> *)attrs;
- (instancetype)initWithAttributedString:(NSAttributedString *)attrStr;

typedef NS_OPTIONS(NSUInteger, NSAttributedStringEnumerationOptions) {
  NSAttributedStringEnumerationReverse = (1UL << 1),
  NSAttributedStringEnumerationLongestEffectiveRangeNotRequired = (1UL << 20)
};

- (void)enumerateAttributesInRange:(NSRange)enumerationRange options:(NSAttributedStringEnumerationOptions)opts usingBlock:(void (NS_NOESCAPE ^)(NSDictionary<NSString *, id> *attrs, NSRange range, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);
- (void)enumerateAttribute:(NSString *)attrName inRange:(NSRange)enumerationRange options:(NSAttributedStringEnumerationOptions)opts usingBlock:(void (NS_NOESCAPE ^)(id _Nullable value, NSRange range, BOOL *stop))block NS_AVAILABLE(10_6, 4_0);

@end

NS_CLASS_AVAILABLE(10_0, 3_2)
@interface NSMutableAttributedString : NSAttributedString

- (void)replaceCharactersInRange:(NSRange)range withString:(NSString *)str;
- (void)setAttributes:(nullable NSDictionary<NSString *, id> *)attrs range:(NSRange)range;

@end

@interface NSMutableAttributedString (NSExtendedMutableAttributedString)

@property (readonly, retain) NSMutableString *mutableString;

- (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range;
- (void)addAttributes:(NSDictionary<NSString *, id> *)attrs range:(NSRange)range;
- (void)removeAttribute:(NSString *)name range:(NSRange)range;

- (void)replaceCharactersInRange:(NSRange)range withAttributedString:(NSAttributedString *)attrString;
- (void)insertAttributedString:(NSAttributedString *)attrString atIndex:(NSUInteger)loc;
- (void)appendAttributedString:(NSAttributedString *)attrString;
- (void)deleteCharactersInRange:(NSRange)range;
- (void)setAttributedString:(NSAttributedString *)attrString;

- (void)beginEditing;
- (void)endEditing;

@end

NS_ASSUME_NONNULL_END

提前致谢

【问题讨论】:

    标签: ios objective-c swift xcode ios-simulator


    【解决方案1】:

    您删除了NS_CLASS_AVAILABLE(10_0, 3_2)下方的@interface NSAttributedString : NSObject &lt;NSCopying, NSMutableCopying, NSSecureCoding&gt;

    【讨论】:

    • 感谢您的回答
    【解决方案2】:

    我认为你错误地修改了 NSAttributedString.m。

    你可以重新安装xcode来解决。

    【讨论】:

    • 感谢您的回复。重新安装 Xcode 可能已经解决了这个问题,但是将行 @interface NSAttributedString : NSObject &lt;NSCopying, NSMutableCopying, NSSecureCoding&gt; 添加到 NSAttributedString.h 类似乎已经解决了这个问题
    猜你喜欢
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-04
    • 2012-04-29
    相关资源
    最近更新 更多