Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

There are similar questions, but none that answer my question.

I am using Swift 2.0 I am working on a project that shows longitude and latitude using CoreLocation.

I also am using the Social framework to post to twitter and facebook.

I am getting an error that says "error: linker command failed with exit code 1 " and then it tells me "(use -v to see invocation)" but I do not understand that.

I am going off an answer here on SO to write the location services portion. here is the link http://stackoverflow.com/a/24696878/6140339

here is my code:

import UIKit
import Social
import CoreLocation

@UIApplicationMain

class FirstViewController: UIViewController, CLLocationManagerDelegate, UIApplicationDelegate {


var window: UIWindow?
var locationManager: CLLocationManager!
var seenError : Bool = false
var locationFixAchieved: Bool = false
var locationStatus : NSString = "Not Started"

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
    initLocationManager();
    return true
}

func initLocationManager() {
    seenError = false
    locationFixAchieved = false
    locationManager = CLLocationManager()
    locationManager.delegate = self
    CLLocationManager.locationServicesEnabled()
    locationManager.desiredAccuracy = kCLLocationAccuracyBest

    locationManager.requestAlwaysAuthorization()
}

func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
    locationManager.stopUpdatingLocation()
    if (error == true) {
        if (seenError == false) {
            seenError = true
            print(error)
        }
    }
}

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if (locationFixAchieved == false) {
        locationFixAchieved = true
        let locationArray = locations as NSArray
        let locationObj = locationArray.lastObject as! CLLocation
        let coord = locationObj.coordinate

        print(coord.latitude)
        print(coord.longitude)
    }
}

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    var shouldIAllow = false

    switch status {
    case CLAuthorizationStatus.Restricted:
        locationStatus = "Restricted Access to location"
    case CLAuthorizationStatus.Denied:
        locationStatus = "User denied access to location"
    case CLAuthorizationStatus.NotDetermined:
        locationStatus = "Status not determined"
    default:
        locationStatus = "Allowed to location Access"
        shouldIAllow = true
    }
    NSNotificationCenter.defaultCenter().postNotificationName("LabelHasBeenUpdated", object: nil)
    if (shouldIAllow == true) {
        NSLog("Location to Allowed")
        //Start location services
        locationManager.startUpdatingLocation()
    } else {
        NSLog("Denied access: \(locationStatus)")
    }
}



@IBAction func postToFacebookButton(sender: UIButton) {
    if(SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook)){
        let socialController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        //creates post with pre-desired text
        socialController.setInitialText("")

        self.presentViewController(socialController, animated: true, completion: nil)
    }
}


@IBAction func postTweetButton(sender: UIButton) {
    if(SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter)){
        let socialController = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
        //creates post with pre-desired text
        socialController.setInitialText("")

        self.presentViewController(socialController, animated: true, completion: nil)
    }
}

override func preferredStatusBarStyle() -> UIStatusBarStyle {
    return .LightContent
}

override func viewDidLoad() {
    super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

//layer.cornerRadius layer.cornerRadius

}

share|improve this question

Your code works well in my Xcode. I think after deleting Derived data, cleaning and rebuilding will works fine. One more thing, you need to split code of AppDelegate and ViewController cause they have their own roles.

share|improve this answer
    
I cleaned, rebuilt, and didn't work. I restarted xCode, didn't work. Did you just copy paste? I am not sure whats not working. From what i can tell it has nothing to do with my social code, it has to do with my location code, i copied and pasted it into a new project and still recieved the same error – GabrielMSC 45 mins ago
    
@GabrielMSC I created new project of Single View Application. and then deleted two file, (AppDelegate.swift, ViewController.swift). then created FirstViewController.swift and copy paste. Could you copy paste the whole error displayed? There are extra information above error comment. – Paul 3 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.