Could not build Objective c Module - ios

i was making a xcode project with swift and it was working fine but suddenly it started giving me this error.
Could not build Objective C Module 'Foundation'
/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
Even when i create a new project and do nothing but just build it, this error is shown. The project is not built. When i click on the error message, it leads me to this file NSNotification.h
Here are the contents of this file
/* NSNotification.h
Copyright (c) 1994-2016, Apple Inc. All rights reserved.
*/
#import <Foundation/NSObject.h>
typedef NSString *NSNotificationName NS_EXTENSIBLE_STRING_ENUM;
#class NSString, NSDictionary, NSOperationQueue;
NS_ASSUME_NONNULL_BEGIN
/**************** Notifications ****************/
#interface NSNotification : NSObject <NSCopying, NSCoding>
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[11];
}
#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:(nullable id)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 <NSObject>)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
Please help me through this. I will be very grateful for this. Thanks.

This line in NSNotification.h looks like it's been modified:
id#property (nullable, readonly, retain) id object;
Delete the id at the front of that line and try to recompile. That should fix it.

Related

Multiple Xcode projects will no longer successfully compile on a real iOS device

I might have accidentally edited the NSAttributedString.h class and/or a related class, and it now seems all my Xcode projects including projects I create will not compile on my iPhone (iPhone 4s iOS version: 9.3.2) (my deployment target is iOS 9.0.).
The Xcode projects will successfully build and deploy to a simulated iPhone.
Here is an edited list of errors I get when I try and compile the app for an 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'
I am using Xcode 8 beta.
Does anyone know what would be causing this error?
I've tried restarting and reconnecting the iPhone,restarting Xcode, re-staring my mac, and deleting the DerivedData folder. I read here that the Expected method body can be caused by a "stray character" in the code but I couldn't find a stray character.
Here is the NSAttributedString.h class:
/* 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
Thanks in advance
You deleted the #interface NSAttributedString : NSObject <NSCopying, NSMutableCopying, NSSecureCoding> below the NS_CLASS_AVAILABLE(10_0, 3_2)
I think you had modified NSAttributedString.m with mistake.
You can to reinstall the xcode to resolove.

Unknown type name UITableView

I am trying to use a library for drop down.When I copied its files in my project , I am getting weird error saying Unknown type name UITableView and also a lot of errors like Expected a type.What is wrong here?
#protocol kDropDownListViewDelegate;
#interface DropDownListView : UIView<UITableViewDataSource,UITableViewDelegate>
{
UITableView *_kTableView;
NSString *_kTitleText;
NSArray *_kDropDownOption;
CGFloat R,G,B,A;
BOOL isMultipleSelection;
}
#property(nonatomic,strong)NSMutableArray *arryData;
#property (nonatomic, assign) id<kDropDownListViewDelegate> delegate;
- (void)fadeOut;
// The options is a NSArray, contain some NSDictionaries, the NSDictionary contain 2 keys, one is "img", another is "text".
- (id)initWithTitle:(NSString *)aTitle options:(NSArray *)aOptions xy:(CGPoint)point size:(CGSize)size isMultiple:(BOOL)isMultiple;
// If animated is YES, PopListView will be appeared with FadeIn effect.
- (void)showInView:(UIView *)aView animated:(BOOL)animated;
-(void)SetBackGroundDropDwon_R:(CGFloat)r G:(CGFloat)g B:(CGFloat)b alpha:(CGFloat)alph;
#end
#protocol kDropDownListViewDelegate <NSObject>
- (void)DropDownListView:(DropDownListView *)dropdownListView didSelectedIndex:(NSInteger)anIndex;
- (void)DropDownListView:(DropDownListView *)dropdownListView Datalist:(NSMutableArray*)ArryData;
- (void)DropDownListViewDidCancel;
#end
You've missed an #import; probably:
#import <UIKit/UIKit.h>
This is normally part of the prefix file (pre-compiled header) so it's possible that is broken in some way.

Parse Issue in Xcode 4.6.3 - "Expected a type" - Can't find the error

I have a Problem with Xcode:
At the moment I am working on an application for iOS SDK 6.1. Somedays ago I was implementing some methods and tried to compile the project.
Then something strange happened:
Compilation failed and I got some errors (see picture below) in two files, which aren't related to the methods I worked on.
I searched for errors in my code but couldn't find any.
Then I closed the project and opened it again: They were still here.
Then I closed the project and Xcode and reopened both: They were still here.
Then I created a new project and copied all the code: The issue appeared again.
Now I am stuck and have no clue what to do. Do I miss something in my code?
Please help me!
---
EDIT 1:
Here are some code snippets, which should show my code after I followed the suggestions of Martin R:
// PlayingCardDeck.h
#class PlayingCard;
#interface PlayingCardDeck : NSObject
- (void) addCard: (PlayingCard *) card atTop: (BOOL) atTop;
- (PlayingCard *) drawRandomCard;
- (BOOL) containsCard: (PlayingCard *) card;
- (BOOL) isCardUsed: (PlayingCard *) card;
- (void) drawSpecificCard: (PlayingCard *) card;
- (void) reset;
#end
// PlayingCardDeck.m
#import "PlayingCardDeck.h"
#interface PlayingCardDeck()
// PlayingCard.h
#import <Foundation/Foundation.h>
#import "RobinsConstants.h"
#import "PlayingCardDeck.h"
//#class PlayingCardDeck;
#interface PlayingCard : NSObject
+ (NSArray*) suitStrings;
+ (NSArray*) rankStrings;
+ (NSUInteger) maxRank;
- (id)initCardWithRank: (NSUInteger) r andSuit: (NSString*) s;
- (NSString*) description;
- (NSUInteger) pokerEvalRankWithDeck: (PlayingCardDeck *) deck;
- (NSAttributedString *) attributedContents;
- (BOOL) isEqual:(PlayingCard*)object;
#property (strong, nonatomic) NSString *contents;
#property (nonatomic, getter = isUsed) BOOL used;
#property (nonatomic, readonly) NSInteger rank;
#property (nonatomic, readonly, strong) NSString * suit;
#end
// PlayingCard.m
#import "PlayingCard.h"
#interface PlayingCard()
That looks like a typical "import cycle":
// In PlayingCardDeck.h:
#import "PlayingCard.h"
// In PlayingCard.h:
#import "PlayingCardDeck.h"
Replacing one of the #import statements by #class should solve the problem, e.g.
// In PlayingCardDeck.h:
#class PlayingCard; // instead of #import "PlayingCard.h"
And in the implementation file you have to import the full interface:
// In PlayingCardDeck.m:
#import "PlayingCardDeck.h"
#import "PlayingCard.h" // <-- add this one
There is something wrong in PlayingCard.h. This error causes the compiler to not know what a "PlayingCard *" is.
Can you show the code from PlayingCard.h?
Make sure the PlayingCard.m is added to your applications target! I would think it isn't (click the .m file and check your apps target in the inspector window on the right side pane)

no known class method for selector confusion

I know this is a newbie question, but I am all confused. How should I call class method from another class, or shouldn't I?
Here is my ClassA and CoreDataHelper:
#import <Foundation/Foundation.h>
#interface ClassA : NSObject {
}
#property (nonatomic, retain) NSString * sessionId;
#property (nonatomic, retain) NSString * token;
#property (nonatomic, retain) NSString * userid;
+ (void) pullOfflineDataWithContext:(NSManagedObjectContext *)managedObjectContext ;
#end
#import "ClassA.h"
#import "CoreDataHelper.h"
#implementation ClassA
+ (void) pullOfflineDataWithContext:(NSManagedObjectContext *)managedObjectContext {
// get Contacts, Accounts, Meetings into Core Data
bool asd =[CoreDataHelper insertAllObjectsForEntity:#"Contact" andContext:managedObjectContext initCoreData:jsonDict];
}
#end
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#interface CoreDataHelper : NSObject
//For inserting objects
+(BOOL)insertAllObjectsForEntity:(NSString*)entityName andContext:(NSManagedObjectContext *)managedObjectContext;
#end
You are calling a class method from another in the right way except the method signature is not the same as it is declared;
bool asd =[CoreDataHelper insertAllObjectsForEntity:#"Contact"
andContext:managedObjectContext
initCoreData:jsonDict];
The declaration of +insertAllObjectsForEntity:andContext: does not have the last one in the calling code above
+(BOOL)insertAllObjectsForEntity:(NSString*)entityName
andContext:(NSManagedObjectContext *)managedObjectContext;
Like:
[ClassName method];
Instead of:
[instance method];
In your example would be then:
[ClassA pullOfflineDataWithContext];

Compiler error - iOS "expected ")" before "Question

What's wrong with the following code? Xcode 4 is saying that the two method declarations with "Question" don't compile due to an '"expected ")" before "Question"; message, as indicated in the comments in the code below. The Question class compiles and this code has been working previously. I made some changes to Questions, but backed them out to try to figure out this compile time error.
#import <Foundation/Foundation.h>
#import "Question.h"
#interface AppState : NSObject {
int chosenAnswer;
int correctAnswers;
int currentQuestionNumber;
// this will contain the hash table of question objects
NSMutableDictionary *questionHash;
}
#property (nonatomic) int chosenAnswer;
#property (nonatomic) int correctAnswers;
#property (nonatomic) int currentQuestionNumber;
#property (nonatomic, retain) NSDictionary *questionHash;
- (void) printQuestions;
- (void) printDescription;
- (void) addQuestion: (Question *) question; // <==== error
- (int) numberOfQuestions;
- (void) saveState;
- (void) resetState;
- (Question *) currentQuestion; // <===== error
#end
Here's Question.h:
#import <Foundation/Foundation.h>
#import "AppState.h"
#interface Question : NSObject {
NSString *questionTxt;
int correctAnswer;
int number;
// this will contain the hash table of questions_answer objects
NSMutableDictionary *answerHash;
}
#property (nonatomic, retain) NSString * questionTxt;
#property (nonatomic) int correctAnswer;
#property (nonatomic) int number;
#property (nonatomic, retain) NSMutableDictionary *answerHash;
-(void) addAnswer: (NSString *) answer;
- (NSMutableArray *) answerArray;
- (void) printDescription;
- (void) printAnswers;
- (NSString *) correctAnswerText;
- (Question *) currentQuestion;
#end
Circular dependency? AppState is importing Question and Question is importing AppState.
Forward-declare one of them to break the cycle, e.g. use #class Question before your AppState #interface statement, like this
#class Question;
#interface AppState : NSObject {
int chosenAnswer;
int correctAnswers;
int currentQuestionNumber;
// this will contain the hash table of question objects
NSMutableDictionary *questionHash;
}
...
Related question: #class vs. #import
When you #import "AppState.h" in Question you make a cyclic dependency.
It would be best to move #import "AppState.h" and #import "Question.h" to implementation part. In the header just leave
#class Question;
and
#class AppState;
before interface declaration.

Resources