Objective c Problem with rotating clock needle

I'm a beginner in Objective-C and I'm trying to make a clock. I'm just testing at the moment and my problem is that for each loop the needle rotates from its initial position but not from the last position. So, my question is how to make the next rotation in the for loop from the last position the needle got? Help me please, i'm doing my last school year internship. Here is my code: #import "MainView.h" #include < math.h> static inline double radians (double degrees) {return degrees * M

Objective c expected specifier-qualifier-list before 'extern'

I'm trying to create a class with global constants: //Resources.h #import <Foundation/Foundation.h> @interface Resources : NSObject { extern NSString * const MY_CONST; } @end and //Resources.m #import "Resources.h" @implementation Resources NSString * const MY_CONST = @"my constant"; @end And getting this nasty error: expected specifier-qualifier-list before 'extern' What do I need to do? Thank you

Objective c Hide mouse cursor on OS X after a few seconds

For my fullscreen app, I want to hide the cursor after a few seconds if it's not moved, like the fullscreen mode in QuickTime or iTunes. Presumably I'm looking to call [NSCursor setHiddenUntilMouseMoves:YES], but how do I know when to call it? Presumably I'm looking for the same as Hide mouse cursor after an idle time but on the Mac. I couldn't find a way to get similar a "idle time". (Plus, I probably don't care about keyboard events, just mouse movement.)

Objective c What use cases are there for defining a new root class?

We know that in Objective-C there are two main root classes: NSObject and NSProxy. There are other roots (mainly for private and legacy purposes) like Object, and NSLeafProxy. Defining a new root is fairly trivial: @interface DDRoot <NSObject> @end @implementation DDRoot //implement the methods required by <NSObject> @end My question is: why would you ever want to define a new root class? Is there some use-case where it's necessary?

Objective c AI for Objective C

I'm trying to figure out if there is any existing AI tools/frameworks/Library for Objective C or Cocos [well OpenGL + Obj C] in general that's good for a person who's never done any form of AI before [other than the simple checkers or tic-tac-toe AI's]. The scenario here is I've finished the basics control of a game for the iPad and works fine for multi-player. The AI just needs to move around, similar to the classic game snakes and somehow 'trap' a human player. I now want to write an AI for t

Objective c Changes saved from one NSManagedObjectContext doesn't reflect on main NSManagedObjectContext

I have a main NSManagedObjectContext that's created in the appDelegate. Now, I'm using another NSManagedObjectContext for editing/adding new objects without affecting the main NSManagedObjectContext, until I save them. When I save the second NSManagedObjectContext, the changes are not reflected in the main NSManagedObjectContext, yet if I open the .sqlite database from simulator, the changes have been saved correctly into the .sqlite database. It doesn't matter if I fetch the data again, or ev

Objective c Releasing CGMutablePathRef from NSMutableArray

I am storing CGMutablePathRefs inside of a NSMutableArray via NSValue. Like so: CGMutablePathRef path = CreateMutablePath(); [self.myArray addObject:[NSValue valueWithPointer:path]]; In my dealloc, I have tried this: - (void)dealloc { [super dealloc]; for (int i = 0; i < self.myArray.count;) { NSValue *currentPath = [self.myArray objectAtIndex:i]; CGMutablePathRef path = (CGMutablePathRef)[currentPath pointerValue]; CGPathRelease(path); } sel

Objective c Save An Image To Application Documents Folder From UIView On IOS

I have a UIImageView that allows a user to place and hold an image until it can be saved. The problem is, I can't figure out how to actually save and retrieve the image I've placed in the view. I have retrieved and placed the image in the UIImageView like this: //Get Image - (void) getPicture:(id)sender { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = (sender == myPic) ? UIImageP

Is there a way in Objective-C to set a property value without directly invoking the setter?

Is there a way in Objective-C to set a property value of a class instance X without directly invoking the setter, but just somehow specifying the property name ? I have a NSDictionary in which the keys are the property names and the values are the values to assign. Now I just would like to iterate my NSDictionary and set the property of the instance X by just specifying the key. I hope it is clear... thanks

Objective c How to get an Answer from a web service after sending Get request in iOS

I'm a novice in iOS developing, and have some problems with understanding web service organization. I want to send a Get query to the URL. And I do it so: -(BOOL) sendLoginRequest{ NSString *getAction = [NSString stringWithFormat:@"action=%@&username=%password=%@",@"login",self.log.text, self.pass.text]; NSString *getUserName = [NSString stringWithFormat:@"username=%@",self.log.text]; NSString *getPassword = [NSString stringWithFormat:@"username=%@",self.pass.text]; NSData *getDataAction =

Objective c How to check if my IOS App support IOS 3+? And something about anonymous function

I'm new to IOS development, sometimes I use a function but ignore its Doc. So, I may use some functions are only supported on IOS 4 or even IOS 5, but I want to support IOS 3+. Does it has any way to check if my app support IOS 3+? I don't want to check line by line, thx. And BTW, anonymous function like void (^ funcName)(NSString *) is objective-c feature, right? So it is supported on all IOS version, right?

Objective c Can't save to plist

I have my own object class from inherited from NSObject @interface BlockedCell : NSObject { NSValue *gridValue; NSString *name; } @property (nonatomic, retain) NSValue *gridValue; @property (nonatomic, retain) NSString *name; @end So I try to create a few objects: NSMutableDictionary *dict = [[dict alloc] init]; for (int i = 0; i < 5; ++i) { BlockedCell *block = [[BlockedCell alloc] init]; block.gridValue = [NSValue valueWithCGPoint: CGPointMake(0.0f, 0.0f)]; block.

Objective c Accessing values of unknown Dictionary Keys

My JSON response looks like this: { "themes": [ [ "Direction des Routes Secteur de Pithiviers ", "mairies", "Morailles 45300 PITHIVIERS LE VIEIL ", "0238345744", "48.823042", "2.365907" ], [ "Crédit Mutuel Du Centre ", "banques", "agence de Pithiviers 33 r Am Gourdon 45300 PITHIVIERS", "0820834080", "48.703042", "2.14590

Objective c Why is shouldHideViewController called but not willHideViewController?

I'm trying to implement a UISplitViewController which has different UIDetailViewControllers. I've created a delegate that all the detail views implement. It only has a UIBarButtonItem which is the button used to access the master view in portrait mode. All works well with one exception: when I replace the detail view controller, the button doesn't appear. In my master view controller, which is where I implement the UISplitViewControllerDelegate, the shouldHideViewController is called but the wil

Objective c UIScrollView with UIButton : buttons appear only after scrolling

I've made my own UIScrollView. In - (void)drawRect:(CGRect)rect, I've drawn my button like that : - (void) createView { CGFloat currentY = 0; CGFloat currentX = 0; CGFloat currentH = 0; for (int i = 0; i < [images count]; i++) { UIImage *img = [images objectAtIndex:i]; CGSize cropParam = [[finalCrops objectAtIndex:i] CGSizeValue]; CGSize imgSize = [[finalSizes objectAtIndex:i] CGSizeValue]; UIImage *newImg = nil; if (imgSize.width > 0) { newImg = [img res

Objective c CATiledLayer basics: Why is CATiledLayer's drawLayer:inContext: called so often when rendering PDFs?

I'm trying to understand how CATiledLayer works when rendering a PDF page using CGContextDrawPDFPage(). My understanding was that drawLayer:inContext: is called once per tile and level of detail. Is that correct? In the delegate of my tiled layer I call CGContextDrawPDFPage(). However I noticed (by putting logs into the drawLayer:inContext:) that drawLayer:inContext: gets called more often if I make the tile size of my tiled layer smaller. This makes me wonder: Is my PDF page drawn/rendered

Objective c Change width of searchBar in a tableview

I realize there will be comments such as this is duplicate : Change the Width of UISearchBars on a TableView I think it is not. Why am I unable to change the width in the storyboard? I can write in the width field any value but as soon as I push return/enter key value 320 is restored. I've tried also to do it in view did load method : searchBar.frame = CGRectMake(0, 0, 222, 45); With zero success again, does anyone knows how to do this? I have an indexed table and the letters on the rig

Objective c Update UIButton title with string variable

I am trying to update the title of a button programmatically with an integer that has been converted to a string and having some trouble. Here is what I have... NSString *buttonText = [NSString stringWithFormat:@"%i", clickUp]; [myButton setTitle:@"%i" forState:UIControlStateNormal, buttonText]; Doing this gives me the error of "Too many arguments to method call, expected 2 have 3". If I set the title manually it works fine. Can you pass a string to a button title, if so, can someone share

Objective c tableview reloaddata in masterview from detail view

I have a master-detail application that has a tableview in the masterViewController and in the detailview you can edit and add info into textfields and so on. I have a save button as the rightBarButtonItem in the detail view. If they did not save their work and they hit back I have a UIAlertView that popsup asking them if they want to save their work. Behind the alertview the detailview is still dismissed and the masterviewcontroller is now showing. So when I hit save the tableview does not up

Objective c I want to distinguish b2Body

I have a lot of bodies in World with Box2d.(B2Body) . I want to distinguish this Bodies. For example I have b2Body *ball; b2Body *person1; b2Body *person2; b2Body *Person3; which the person I want to hit the ball? this b2body have id , name or other thing for distinguish?

Objective c SEGUE and show large image in another VC

I am new to oop and objective-c. I have a collectionView which loads photos from my phone. I want to segue to another ViewController so that my asset is displayed @ full resolution.I followed this post: set UIImageView.image in prepareForSegue by Rob Mayoff and came up with this, here is my code for the main VC : - (void)viewDidLoad { [super viewDidLoad]; void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

Objective c I cant set array with variables of my NSObject class

I'm trying to figure out how to set array with variables of other class. I have NSObject class named myObject, where I did declare variables myInt and mySecondInt of int type. Then I import myObject and tried to set an array like this: MyObject *object = [[MyObject alloc]init]; object.myInt = 50; object.mySecondInt = 15; object.array = [[NSArray alloc]initWithObjects:object.mySecondInt,object.myInt, nil]; And then I got an error: implicit conversion of 'int' to 'id' is disallo

How can I override an Objective-C Cordova class without hacking the source?

I am new to Objective-C so sorry if this is inanely simple. I am trying to alter the PhoneGap Capture Feature to add some text on the audio and video capture screens that pop up when you call capture.captureAudio and capture.captureVideo. I have found I can alter the Cordova source and change the loadView method of the CDVAudioRecorderViewController to add a text field and alter the appearance. Likewise I imagine I should be able to do the same with the CDVImagePicker class. I know hacking

Objective-C: Code Clarification

I'm having trouble understanding the code below: for (SKProduct * skProduct in skProducts){ IAPProduct * product = _products[skProduct.productIdentifier]; .h @property (nonatomic, strong) NSMutableDictionary * products; //not synthesized in .m .m - (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response { _productsRequest = nil; NSArray * skProducts = response.products; for (SKProduct * skProduct in skProducts) {

Objective c How to parse an array containing the trending topics from twitter json feed

I have already in place the method to grab the trending topics from twitter for a specified location. My question is, how do I parse this data from the JSON, so that I can then print the names and urls of the trending topics list. This is what the twitter json feed response looks like: ( { "as_of" = "2013-08-05T18:16:52Z"; "created_at" = "2013-08-05T18:06:52Z"; locations = ( { name = "San Francisco";

Objective c How to prevent file sharing with Quick Look PDF viewer

I am using the QuickLook framework to display PDFs in my app. The pdfs are downloaded and stored in my apps sandbox, in the Application_Support directory. Basically, I open the PDF in my app, no problems and then close my app. Now if I open the Adobe App on my device, the pdf I was viewing with my app is available in the Adobe app. Is there any way of preventing this sharing of my pdf between my app and the Adobe App Any help will be much appreciated j

Objective c Finding length of the array within the array in xcode

In .h file, NSString *deal_desc,*terms_cond,*merchant_desc,*locationaddress,*locationcity,*locationstate; Trying to find the length of the 'detailarray', so that it could help me to allocate the height of the cell in table. deal_desc = @"sadsad dsa dsad dsad sadsa dsad sadsad adsad sadsad adssad sad adsad sada"; terms_cond = @"sadsad adssa sad asdsad&nbsp"; merchant_desc = @"merchant description describes in detail about merchants"; locationaddress =@"42, South St"; locationcity = @"San

Objective c EXC_BAD_ACCESS when movie played the second time

I am using mpmovieplayercontroller to play a movie in my game. When the user taps the screen I run a method that replaces the current layer containing the movie with the game main menu. It works fine the first time, but when I try to play the video the second time from the main menu I get an EXC_BAD_ACCESS error on the line int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); in the main.m. Please find the relevant code below. -(void)playVideo { NSURL *url = [NSURL fileURLW

Objective c Possible to determine classes to import at runtime / Possible to ignore import errors?

QUESTION 1 I'm 99% sure that you can't determine which other classes a class imports at runtime...but just in case...is this something you can do? QUESTION 2 Is it possible to have your app ignore an import error? I.e., is there a way to make your app still compile and run even if you include #import "IrrelevantClass.h" and don't include IrrelevantClass.h/.m in your Xcode project? (WHAT I'M GETTING AT...) I've created a custom class RulesManager.h/.m with some generic methods for taking app

Objective c format numbers on ios

I'm looking for a way to format a string into number and show it on textfield For example: I have the number "1000", I want to it convert into "1.000" or 100000 into 100.000. Or 1000000 into 1.000.000. Please help me if you know solution for this Thanks

Hex to 2's complement in objective-c

I'm trying to convert a hex value e.g. 0xFAE8 to a 2's complement decimal i.e. -1304. I've tried looking at this Convert binary two's complement data into integer in objective-c but I don't really get how the byte-shifting enables the conversion to be done properly. I hope there can be an explanation or a simpler way to do it. Thanks.

Objective c how to remove Facebook login button at the top of the iOS app screen?

#import "LoginViewController.h" #import <FacebookSDK/FacebookSDK.h> #import "WelcomeViewController.h" @interface LoginViewController () @end @implementation LoginViewController - (void)viewDidLoad { [super viewDidLoad]; FBLoginView *loginView = [[FBLoginView alloc] initWithReadPermissions: @[@"public_profile", @"email", @"user_friends"]]; [self.view addSubview:loginView]; loginView.delegate = self; } - (void)loginViewFetchedUserInfo:(FBLoginView *)loginView

Objective-C PFQuery for string contained in an array?

I have a Parse table that contains a "UserIDs" column, which is an array of Strings. I want to query this table for any Row which contains a certain specified UserID in the userIDs column. For example, let there be a row that contains "0zll0s7Faz", "x62ks620", ..., "x2jdo322" in this column, how can I get this row with a PFQuery. So far, I have a PFQuery as follows: PFQuery *query=[PFQuery queryWithClassName:@"Albums"]; NSString *ide = [PFUser currentUser].objectId; [query whereKey:@"UserID

Objective c Use static framework inside a dynamic swift framework

I am creating custom dynamic framework in pure swift lang which is using a pre-compiled iOS Realm framework (downloaded from their website). I have tried various options to use this framework in an external project but it fails saying Realm was not found. Here are some of the things I have tried already Used Realm binary and headers from the framework, added them to the project and import using a plain import Realm statement Use the framework in the project ad directed by the instructions on

Objective c How to stop ARC from releasing twice an object shared by by 2 threads?

Our application experiences a double release crash in a library that we wrote that is ARC enabled. After running instrumentation, we discovered that the double release happens on an object that is accessed by 2 threads. The object in question is first allocated outside the 2 threads in an initialization method objectX = [[NSData alloc] initWithBytes:barcodeBytes length:sizeof(barcodeBytes)]; Thread A is started and it adds objectX to an NSDictionary. Thread B assignes ObjectX to a local

Objective c Can Swift.h file be imported in pch file?

I'm trying to use swift in an Objective-C based project. It seems that ProjectName-Swift.h needs to be imported in every .m file which doesn't sound good. Can it be imported in the ProjectName-Prefix.pch like UIKit/UIKit.h so that I only need to type once in the project? I've tried this way, but .pch cannot find the header file. Is there an alternative attempt?

Objective c Use BOOL as property of button

I have a boolean that I would like to set as a property of a button: int tag = (int)[sender tag]; NSString* keyPath = [NSString stringWithFormat:@"addButton%d.hidden", tag]; [self setValue:YES forKey:keyPath]; I can't do this directly as the addButton's number changes according to the sender's tag. I've already tried with: setValue:[NSNumber numberWithBool:YES] but doesn't work. Where am I wrong?

Objective c Why is detailTextLabel not visible

Here I will show you a snippet of the code, that i'm using: -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *tableIdentifier=@"system"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:tableIdentifier]; if (cell==nil) { cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableIdentifier]; } cell.textLabel.text=[peoples objectAtIndex:indexPath.r

Objective c Can IBAction return an integer?

Is it possible to make it my IBAction for a button element to return an integer that can be used in another IBAction? I want my IBAction "forward to return the integer "i" and how can I make it so that my other IBAction method accepts the integer parameter? - (IBAction)forward:(id)sender { if (i < users.count) { SiteValue* s = [users objectAtIndex: i]; NSString *website = s.website; NSString *username = s.username; NSString *password = s.password;

Objective c NSURLSession: Getting 401 HTTP error

I am getting "401 Unauthorized access to the endpoint". When I run the same call on POSTMAN (Chrome Extension), it works fine. Even it works fine in my Android app. But here, I am getting the unauthorized access even if I am sending token in headers. I have no idea what is going wrong here. The response I am getting is: {"detail":"Authentication credentials were not provided."} Here is my code: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; NSString *url=[NSString st

Why this objective-c singleton works?

I have create a singleton of Objective-C like this as find on the internet tutorial: +(id) sharedInstance{ static AdManager *manager = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ manager = [[self alloc] init]; }); return manager; } Will the static AdManager *manager be released once the holder be released? and since the *manager is defined in a method scope rather than a field variable, will it be released too? Then where will the obje

Objective-C macOS how to use PayPal getBalance NVP API?

I want to get PayPal account balance in my macOS app but still I have not found any solution. Below is my code: NSString *targetUrl = @"https://api-3t.paypal.com/nvp"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; //Make an NSDictionary that would be converted to an NSData object sent over as JSON with the request body [request setHTTPMethod:@"POST"]; [request setURL:[NSURL URLWithString:targetUrl]]; NSString *postLength = [NSString stringWithFormat:@"application/x-www-f

Objective c How to use Sox Library 'pad' command in mac os application to add silence to begining and end of audio file?

I am trying to add silence to begining and end of an audio wav file in a mac OS application(objective c). For that i am using sox library. i use prebuilt compiled framework from this repo. Dragged and dropped the libsox.a and sox.h files. I am trying to use the 'pad' command. documentation of sox can be found here Problem is that the pad command does not produce expected results when used in code. However, pad command works perfectly fine on terminal. Lets take an example Input file is like

  1    2   3   4   5   6  ... 下一页 最后一页 共 465 页