我可能不小心編輯了NSAttributedString.h類和/或相關類,現在看起來我的所有Xcode項目(包括我創建的項目都不會編譯) iPhone(iPhone 4s iOS版本:9.3.2)(我的部署目標是iOS 9.0)。多個Xcode項目將不能在真實的iOS設備上成功編譯
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
在此先感謝
感謝您的回答 –