w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » IOS » Page 20
add xctest framework to an old project
In Xcode 6.1.1, and also in Xcode 6.0.1, the XCTest.framework is not listed anymore as an available framework. In Xcode 5.1.1, however, the framework is listed. So something appears to have changed between Xcode 5 and 6 when it comes to testing. For instance, when you create a new project in Xcode 6 you no longer need the XCTest framework. You can simply add a new test case, build and the test ru

Categories : IOS

How to convert a double into a byte array in swift?
typealias Byte = UInt8 func toByteArray<T>(var value: T) -> [Byte] { return withUnsafePointer(&value) { Array(UnsafeBufferPointer(start: UnsafePointer<Byte>($0), count: sizeof(T))) } } toByteArray(1729.1729) toByteArray(1729.1729 as Float) toByteArray(1729) toByteArray(-1729) But the results are reversed from your expectations (because of endianness): [234,

Categories : IOS

iOS base64 encoding bug?
The problem is the value 0in your array. The value 0 is converted to char 0 which is a special character (null) used for string termination. Obviously iOS Objective-C treats this special character differently than Python and this is why you get a different result. The null character should not be found in the middle of a "normal" string. You also have the ASCII code 8 (backspace) that shouldn'

Categories : IOS

Where do I see the iOS Distribution Provision Profile expiration date with iOS 8?
In iOS 8, you can no longer see the profile expiration dates on the device. Unfortunately, Apple is assuming you'll manage the upcoming expirations through some other process. I know this isn't what you want to hear, but Apple has made a concious decision to remove the information from the device Settings app. In this years device management WWDC talk (at about 42 minutes in), the speaker confir

Categories : IOS

iOs: at Launch, segue to a specified viewcontroller
I presume you are using a storyboard. That's part of the problem here, but it is not insuperable. By the time your code in didFinishLaunching... runs, you already have a window and that window has a root view controller. Thus you can get a reference to that root view controller and do any pushing or presenting of a different view controller on top of it. And since you are doing this before the int

Categories : IOS

Is applicationWillEnterForeground always called after applicationDidEnterBackground?
Set a Boolean value in the user defaults when you enter the background. Then, when you re-enter the foreground check the value of that Boolean to determine whether or not it was set properly. Either way, always set the Boolean to false when returning to the foreground.

Categories : IOS

Restrict SKSpriteNode to Phone Screen
You can add a physicsBody to the scene restricting your bird from going out of the viewport: //In the scene: self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame] You'll need to add the appropriate category/contact bitmasks, but it seems like you can handle that.

Categories : IOS

Using auto layout with UIImageView doesn't preserve frame size
You should not set any frames when using auto layout. You need to add two more constraints for the width and height of the image view. let imageView = UIImageView() // your other code here imageView.addConstraint(NSLayoutConstraint(item: imageView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: 100)) imageView.addConstraint(NSLayoutConstr

Categories : IOS

iOS audio conversion from AVMutableComposition to AVAudioPlayer
Use AVPlayerItem & AVPlayer to make a quick preview of your audio composition AVPlayerItem* previewPlayerItem = [[AVPlayerItem alloc] initWithAsset:mutableCompositionMain automaticallyLoadedAssetKeys:@[@"tracks",@"duration"]]; previewPlayerItem.videoComposition = mutableVideoComposition; AVPlayer* previewPlayer = [[AVPlayer alloc] initWithPlayerItem

Categories : IOS

What is wrong with this code? Swift optionals
Xcode is mad because you are using optional chaining with documentArray?.count. You should use documentArray!.count to force unwrap the value. Another approach, conditional binding is sometimes an easier way to not have to worry about these sorts of things. if let documentArray = documentArray { rowCount = documentArray.count } else { rowCount = 1 }

Categories : IOS

Cannot store iBeacon RSSI values in an array
A simplistic approach that just stores rssi would be - - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { for (CLBeacon *beacon in beacons) { [self.rssiArray addObject:[NSNumber numberWithInteger:beacon.rssi]]; } } The reason that I say this is approach simplistic is that it simply s

Categories : IOS

How to make a xib subview interact with superview in Swift?
You could use addTarget:action:forControlEvents: after you load the nib to add the action methods for your buttons; the target should be self (the controller where you've added this view). The view should have IBOutlets for any buttons or other controls you need to interact with. You shouldn't have any actions for the buttons in the subview class if you use this approach. Another approach, would

Categories : IOS

Moving 2 images sequentially across the screen in IOS
Put the animation method ( animateWithDuration:delay:options:animations:completion:) in the completion block of the first animation. Add whatever delay you want (the delay will be between the end of the first animation and the start of the second).

Categories : IOS

AppleLanguages no longer returns all languages
Use +[NSLocale preferredLanguages] instead of querying NSUserDefaults. Note that as mentioned in the Xcode 6.1 release notes, there is a known bug in the iOS 8.1 simulator runtime that prevents this from working there, but this will work as expected on other simulator versions and on device. If you want a list of all supported languages rather than just the user's preferred ones, you can use +[N

Categories : IOS

Why am I required to alloc/init instances of an class before assigning values to the objects properties?
I wonder why X-Code wouldn't automatically instantiate the object in memory when it sees that I am assigning it's properties in the code. Because, what is the right way to instantiate MyCustomClass? Often it's enough to alloc and init an instance, as in your sample code. But in many cases this would result in broken, nonfunctioning objects due to not calling the designated initializer. For ex

Categories : IOS

delegate and methods aren't executing without a reason
What pbasdf is saying is that the delegate is probably nil if the code is not executed. To check this you can change the code in your Action as following and then post the result. if ([managedObjectContext save:&error]) { if (self.delegate) { NSLog(@"delegate is set"); [self.delegate changeWeekDay]; } else { NSLog(@"delegate is not set and can not execute c

Categories : IOS

Status 304 for AFNetworking is still getting data
If you want to make your client always fetch and ignore 304 status codes, you need to set the cachePolicy of your NSURLRequests to NSURLRequestReloadIgnoringLocalCacheData. More information can be found about this and other options at http://blog.originate.com/blog/2014/02/20/afimagecache-vs-nsurlcache/ and http://nshipster.com/nsurlcache/. I'd say NSHipster is a good source as Mattt wrote AFNetw

Categories : IOS

Present UIAlertController from AppDelegate
You are trying to present UIAlertController on UINavigationController, which appeared to be your rootViewController and the problem is you cannot present UIAlertController on UINavigationController, the UIAlertController needs a view controller's from which it can be presented. Can you not call as follow, [self presentViewController:alert animated:YES completion:nil]; here self refers to curre

Categories : IOS

How to organize files in Git Repository
This has been a question I have dealt with in organizing iOS files/folders. Once your project starts involving more than a few simple UIViews and images, yes, I think an organization structure is necessary. I have been a fan of folder references in XCode to keep organized. This way the XCode sidebar simply reflects your exact directory structure in Finder, as opposed to showing you all the files

Categories : IOS

Is putting variables in the AppDelegate a workaround for static variable in Swift?
That isn't entirely accurate. Swift CLASSES don't have static variables, but structs and enums do! struct Static { static var stream: XMPPStream? } And you can initialize it later in your code if you'd like. Static.stream = XMPPStream() Another approach if you need static variables for a class is to nest a struct inside: class RegularClass { struct Static { static var strea

Categories : IOS

AFNetworking: How to set Content-Type HTTP Header in request?
It's exactly what the error says: your server is sending back a webpage (HTML) for a 400 status code, when you were expecting JSON. A 400 status code is used a bad request, which is probably generated because you're sending URL-form-encoded text as application/json. What you really want is to use AFJSONRequestSerializer for your request serializer. manager.requestSerializer = [AFJSONRequestSeria

Categories : IOS

Unbalanced calls to begin/end appearance transitions for ParentViewController
This is was the completion handler is for. Try this: [some_vc dismissViewControllerAnimated:YES completion:^{ ViewController *vc = [[ViewController alloc] initWithNibName:nil bundle:nil]; vc.someData = data; [self.navigationController pushViewController:vc animated:NO]; }]; This ensures the new controller isn't presented until the previous one has finished dismissing. Another optio

Categories : IOS

How to Have Floating Title View in Scrollable Collection View Keep Its Y Position?
The answer is to use the scrollView's contentOffset in the scrollViewDidScroll method. The collectionView is a scroll view. So this method is being called by both the scroll view that handles up/down and the collectionView which handles the left to right scrolling. - (void)scrollViewDidScroll:(UIScrollView *)scrollView; { for (CVKRecipeCollectionViewCell *cell in self.collectionView.visi

Categories : IOS

Invalid Swift Support-ERROR IOS APP PIBLISHING?
I had a similar problem. To fix it and be able to push a build to iTunesConnect I had to do the following: Set the flag EMBEDDED_CONTENT_CONTAINS_SWIFT to YES in the target settings Be sure that Build Phases did not include any other weird targets Logout all Apple Developper accounts from Xcode and login with just the one you want to push the app with. Archive and submit the app with Xcode and

Categories : IOS

error "has no segue with identifier" adding split ViewController
You need to set the identifier for the segue, not the viewController. If you click on the line joining the two viewControllers, you can then set the attributes for the segue in the attributes inspector:

Categories : IOS

Table View Cells change Height when cell tapped
You're going to have to change the way you've implemented tableView:heightForRowAtIndexPath: You call dequeueReusableCellWithIdentifier: to get your Custom cell object back to find its height. That method only keeps track of the cells that are visible on your screen. When you leave that tableview it will empty itself. What you need to do is check to see if nil is returned after you call dequeueR

Categories : IOS

How do I post a story to Facebook in Swift?
As requested, here was the approach I ended up using. It doesn't use the FBOpenGraphAction, which made it a lot more simple to implement in my case. (Note: you need to use the FBLoginViewDelegate): // Initialize variables let name = "Purple Square" let link = "https://itunes.apple.com/us/app/purple-square/id942125866?ls=1&mt=8" let description = String(format: "I got %.1f. Can

Categories : IOS

Passing data with segue through navigationController
The destination view controller of the segue is the UINavigationController. You need to ask it for its top view controller to get to the real destination view controller: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) { if (segue.identifier == "showItemSegue") { let navController = segue.destinationViewController as UINavigationController let det

Categories : IOS

Fast Enumeration of a NSFetchedResult
It is an array of NSManagedObjects: for (NSManagedObject *myVacation in arraVacationResults) { // // if you need to cast it as your entity // VacationResultEntity *entity = (VacationResultEntity *) myVacation; }

Categories : IOS

NewRelic crash reporting not working for iOS?
Test Flight includes crash reporting as well. You need to turn off crash reporting for Test Flight, so that New Relic will be able to gather crash reports. In your -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method, add the following lines of code: [TestFlight setOptions:@{TFOptionReportCrashes: @NO}]; [TestFlight takeOff:@"YourTes

Categories : IOS

How to draw an infinite line at a specific degree angle (e.g. 270W) using Apple MapKit?
Since you are speaking in terms of an angle specified by degrees of a circle, it sounds like you want to do plane geometry. The easiest way to do that on a map view is with MKMapPoints. Translate the coordinate of your starting point into a map point with MKMapPointForCoordinate; now pick another MKMapPoint at some distance away and at the angle you want; and connect them with an MKPolyline that

Categories : IOS

Include ".framework" file to cocoapods
What you want is the vendored_frameworks attribute. In your case it looks like you'd want to use it like this: s.vendored_frameworks = 'Resources/Custom.framework' This automatically deals with preserving the path and linking the framework itself so you don't need either of those attributes for your custom framework.

Categories : IOS

Using Swipe Gesture and Touches Began/Moved/Ended at the same time
In this case I would create a custom UIGestureRecognizer for a new behaviour in touches began/moved/ended. Useful link here. Than I would set delegate for both swipe and custome recognizers and implement gestureRecognizer:shouldRequireFailureOfGestureRecognizer: method to fulfill requirements. Link to documentation.

Categories : IOS

Return Results from CoreData directly into Class
The compiler complains because you did not specify a return type for your function, it should be class func getAllLocations() -> [Locations] { ... } There are also some unnecessary type annotations, and all the objects can be declared as constants: class func getAllLocations() -> [Locations] { let appDel = (UIApplication.sharedApplication().delegate as AppDelegate) let context =

Categories : IOS

iOS: Navigate to certain row after didReceiveLocalNotification in SplitViewController (Swift)
There should be a segue setup from Master to Detail. Then you need to call performSegueWithIdentifier from didReceiveLocalNotification which will open Detail View. Set correct UserInfo in prepareForSegue method which will be called before Detail View opens. You may check out a simple Master Detail Sample done by me.

Categories : IOS

UIScrollView header view?
Here is a solution I provided for a header that behaves similarly to what you're describing: FixedHeaderTableView. In your case, you would pass in 0 for the visibleHeaderHeight parameter.

Categories : IOS

auto-change size of label depending on text
You can use auto layout to achieve this. You just need two constraints to center label on screen. You can put this in viewDidLoad() Here is the code: let centerXConstraint = NSLayoutConstraint(item: MessageLabel, attribute: .CenterX, relatedBy: .Equal, toItem: self.view, attribute: .CenterX, multiplier: 1.0, constant: 0.0) let centerYConstraint = NSLayoutConstraint(item: MessageLabel, attribute:

Categories : IOS

Are optional protocols from Objective-C not something that should be done in Swift?
In this Developer Forums topic: Optional methods in protocols are limited to @objc protocols only because we haven't implemented them in native protocols yet. This is something we plan to support. Although you can implement delegate pattern with optional methods in pure Swift, but it's very ugly ... protocol MyOperationDelegate:class { var operation:Optional<(MyOperation, didComple

Categories : IOS

Swift: change a variable in an other swift-file? No change?
This: @IBAction func ButtonPressed(sender: AnyObject) { HomeScreen().Score++ } You are creating a new instance of HomeScreen, incrementing it's value, and then, at the end of the method, it is going out of scope, so all changes are lost. You should be changing the values on an initialised object instead, something like instead: @IBAction func ButtonPressed(sender: AnyObject) { // ho

Categories : IOS




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.