Swift Programming

1K

Solutions

4

Articles & Videos

2K

Contributors

Swift is a compiled programming language created for iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products. Swift is intended to be more resilient to erroneous code ("safer") than Objective-C and also more concise. It is built with the LLVM compiler framework included in Xcode 6 and later and uses the Objective-C runtime, which allows C, Objective-C, C++ and Swift code to run within a single program. A second free implementation of Swift targets Microsoft's Common Language Infrastructure (a.k.a. .NET) and the Java/Android platform.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi, I have a UIPickerView with 2 images in each row, I would like to animate one of the images when it is selected ...I have been able to animate the whole pickerview when the selection changes (in didSelectRow), but I want to just animate one of the images

with the code below ...in the didSelectRow function how would I reference the selected "firstImage" image to apply the animation?

Instead of memoryPicker.transform I've tried...

pickerView.firstImage.transform -  which gives error: Value of type 'UIPickerView' has no member 'firstImage'
And
view.firstimage.transform -  gives error: Value of type 'UIView' has no member 'firstImage'
Thanks

[code]@IBOutlet weak var memoryPicker: UIPickerView!

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

// The number of rows of data
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {

    return objectsToRemember.count
}

func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
    return 100
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

    let view = UIView(frame: CGRect(x: 0, y:0, width: 250, height: 100))

    let firstImage = UIImageView()
        firstImage.image = UIImage(named:objectsToRemember[row])
        firstImage.frame = CGRect(x: 0, y: 0, width: 100, height: 100)

    let secondImage = …
0
Free Tool: Port Scanner
LVL 8
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

11
 
LVL 6

Expert Comment

by:Brian Matis
@Brandon: You're forgetting the market of people that don't want Amazon and Google listening to everything they say all the time :-)
2
 
LVL 9

Expert Comment

by:Brandon Lyon
Apple does have a slight advantage there with it's anonymous encrypted IDs.

I fully agree with not wanting unknown companies listening all the time. On the spectrum of who is listening when, Microsoft is the worst with Windows 10, Cortana, and being actively hostile towards privacy issues. After that comes Google who does everything mysteriously, doesn't document much of what they do or give you many controls, and has an interest in gathering as much data as possible to sell to advertisers.

On the other hand Amazon Alexa doesn't listen all the time. They have very clear documentation on exactly what they do when and they let you view or delete your complete voice history at any time. Furthermore there is a physical switch to turn the microphones off. They also have a fully open SDK for both hardware and software. Their main interest is getting you to buy stuff, just like Apple.
2
This is so cool! I've already gone through some of the sections in Apple's Swift Playgrounds app and loved it, but this new support for programming robotic toys looks even more amazing and fun. Great way to get kids learning programming at an early age. (Ok, who am I kidding... I want this for myself!)

Any of you check out the Swift Playgrounds app or have any of these robots? Are you teaching your kids to program?
8
 
LVL 1

Expert Comment

by:Juana Villa
That is awesome! I did not know about it. I will definitely learn more about it to show it to my nephews and nieces.
2
I am very new to writing iOS apps - in fact this is the first app I am writing.  In general it is working, but on first load it is very slow to load the data (which is gets from a web service).  I added some timers to sections of the script and believe I have narrowed down the area that is slow.

Briefly the process is:
  1. Get the article data (in JSON) and save it to an Article object and update table cell
  2. For each article check if it has an image, if so access the image JSON to get the URL
  3. Download the image and save to Article Object and update table cell
  4. Display table and use placeholder image if article does not contain an image

It appears to be point 3 that causes the 'freeze'.  In subsequent uses of the app it checks the saved array of Article Objects and loads data from there, and then only adds new / updated articles and deletes old articles and therefore is much quicker.

While it is useable I would like to load the table with the text as soon as it is available and then load images in the background, save it to the object and refresh the cell once it is available.  While there are articles online with code I cannot seem to get them to work.  Either I am left with the app waiting for all the images to load, or just getting the placeholder image for all articles.

My code (for this) is currently in a couple of places.  Loading the JSON is in the TableViewController viewDidLoad() and the image …
0
Hello,
Are there any good products, sites or services that can be used to basically develop a prototype app for planning purposes and relaying information to others like graphics, dev etc.? Something that can be used as a kind of project manager to build a app.

So lets say you have a idea for a app but want to do a rough, not flashy, draft of the layout and mock actions for buttons etc. So if you tap here then this screen pops up type of thing so not actually coding the app but just some type of WYSIWYG interface to help test out the flow of the design before spending time and money on the actual coding and graphics etc.
0
Good morning fellow Apple Geeks!

If you own a first generation Apple Watch, and its battery starts to swell for some reason, Apple has extended out the warranty for you. Despite this being a flaw in the batteries, I get excited when Apple does things like this. To me, it shows the obvious business smarts they have onboard, and that they are willing to do what we call in the military, "the hard right over the easy wrong."

In short, Apple doesn't need to extend the warranty to keep people purchasing their products. However, by doing this they are fortifying the loyalty among their base, and shocking the newcomers who are stepping into the realm of Apple for the first time. That's what happens when you own up to your faults and then try to correct them.

Good on you Apple!
5
 
LVL 6

Expert Comment

by:Brian Matis
Always nice when a company does the right thing!
1
Hello:

I'm considering taking an online class to learn Swift programming for creating iPhone apps.

But, my laptop has Microsoft Windows 7--not Mac's OCX operating system.

Is it possible to install some sort of "runtime" version of OCX on a Windows laptop?  Also, is it possible to do so without cost?  :)

Thank you!

John
0
Is it possible to send an In-App email from iOS Swift 3 app without it opening a new email message window that the user needs to click 'Send'

I've tried using MessageUI and MFMailComposeViewController but it opens an email message window.

The from and To address will always be the same in my app and I just ned the message to be sent without user intevention
1
Is there a way to do Xcode development and maintain the projects in such a way that if I have to switch between 2 - 3 macs I still have access to my projects.  Right now doing a course on Swift and that would be helpful

Thanks
0
Hi all,

I'm new to both VS and Cordova so be gentle :)
I'm trying to lock my cordova app into landscape orientation only. I went into the config.xml and set orientation to Landscape which ends up doing this:
<preference name="Orientation" value="landscape" />

Open in new window

But when i run/debug the project in browser emulator, the device is still portrait.
I tried using net.yoik.cordova.plugins.screenorientation plugin with following code nad it didn't work either (alert worked)
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    window.screen.lockOrientation("landscape");
    alert("123");
}

Open in new window

Can anyone please point me in the right direction on how to lock entire app into landscape permanently. Google has not helped me.
Thanks,
Primoz
0
[Webinar] Learn How Hackers Steal Your Credentials
LVL 8
[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Is Windows Xamarin the next great tool for Cross platform mobile development? What are the alternative tools available and their advantages?

Is jquery mobile another great tool for Cross platform mobile development?
http://jquerymobile.com/
0
What's the requirements to develop current latest Apple App?

Can you provide details in terms of recommended Models, OS versions, Development tools, etc?

I need to draft a spec to purchase one for office use.
0
Hello:

Although I have many skills outlined on my resume, I want to add another practical skill, in case my current skills become obsolete.

So, I have been toying with the idea of teaching myself Swift or some other iOS programming language in order to be able to create apps for the iPhone.

Out of the many new business skills a professional could learn, would this be the best?  

If so, how long does it take to learn and is it extraordinarily difficult?  Are there are good and free tutorials online that will successfully teach the lay person such a programming language?

Thanks!

John
0
I am a rookie with programming but wanted to delve into programming for Androids.  What language should i use?  or what development program.?  also, does this language translate to coding pretty well if i wanted to create the same app for ios.
any commentary would be greatly appreciated
0
As all "great" projects start, my wife asked me to build an app for their small teacher organisation. I'm new to development of IOS, but have worked in java, so I've made progress in getting up to speed with Swift and building up the framework of the app and getting it operational.

However, it dawned on me that I don't have an understanding of do's and don'ts when building a secure app. The books I've read focused on the UI more than the data itself. With the current project, I don't have risk that I need to worry about. But would like to use this app as a ginnie pig.  I'd like to know what are things I should be doing or adding into a iOS app to ensure it's secure and protected. I am not asking from a UI Pov (Apples KB documents provided me with that), but more on the lines of protecting the data if I was sending secure data from the app to a cloud DB (I.e. Firebase) or storing user profile or credentials in the apple "Core Data".
0
Hi

I received a $0.99 bill for iCloud today. I was infuriated! I got it for me and my mom's massive web-space needs

Nah, I just need to know how to turn billing off. It wasn't in App Store. ?

Thanks
0
I have a swift 3 app that uses Alamofire to connect to a web service and get data.  All working but once I am done with the data (inserted into Core Data) and exit the Alamofire closure, the memory held by the variable holding the data is not released.  See code below:  The json variable below will hold to 25MB of memory.  The JSON type is Freddy JSON.  How do i identify why this memory is not being released

            Alamofire.request("\(URLServer().ipUrl)\(urlMethodWithParameters!)") .responseJSON  {
                (response) -> Void in
                
                if response.result.isSuccess {
                    do{
                        let json =  try JSON(data: response.data!)
                        
                        print("JSON retrieval success!")
                        self.processCustomerSyncData(json)
                        CustomersAssociationsSync().performCustomerAssociationsDataSync()
                    }catch{
                        print("error")
                        let netWorkError = AppDelegate.sharedInstance().progressViewController
                        SyncherBase.synchError(sender: netWorkError!)
                    }
                }else if response.result.isFailure {
                    print("User authentication failed!")
                    let netWorkError = AppDelegate.sharedInstance().progressViewController
                    SyncherBase.synchError(sender: netWorkError!)
                }
                
 

Open in new window

0
I am trying to run code in swift when a textField (in macOS) changes. I have tried:

    override func viewDidLoad() {
        super.viewDidLoad()

        let name = "NSNotificationTextFieldChanged"
        NotificationCenter.default.addObserver(self, selector: Selector(fieldTextDidChange),
            Notification(name: Notification.Name(rawValue: name)), object: nil)
       
    }
   
    func fieldTextDidChange(notification: NSNotification) {
        errorMessage.stringValue = ""
        errorMessage.isHidden = true
    }

but I get the error "Cannot convert value of type '(NSNotification) -> ()' to expected argument type 'String'

Any ideas?
0
So I am going to write an app in swift for iPhone.  It is going to have a lot of multimedia, many gigs that will be written to it.
Right now I am thinking of storing the data as files, and syncing them to the cloud.  But what about using  DB?  can a DB handle large multimedia files?  Should I?
I have never written an app before, so any general direction before I start to avoid long term issues would be appreciated.
0
Free Tool: ZipGrep
LVL 8
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

When working with reverse geocoding some address could be ambiguous for given location and the returned array of placemarks can contain multiple values (address gets multiple hits). This happens very rarely. Usually practice is to take first or last object from given array. So, I want to know why is this common practice. I've looked in Apple documentation and they also took object at index 0. Does the first object contains the most accurate address if the array of placemarks contains more than one object for given location (lat, long)? Thanks for your answers.
0
I m looking for somethg to post in our corporate IT security 'current banking breaches events': last one I  wrote was the Bangladesh banks Swift funds theft in Feb.  Think last May  another bank fell victim to a Swift funds fraud too.

Any other banking breaches to share n watch out for?
0
I am creating an iOS app in Swift. I have a table view with two cells, and want to navigate to another view controller when the user clicks on one of the cells. In storyboard, to create a new segue, I control + dragged from Prototype Cell to the destination view controller. This automatically created the segue, and everything is working fine.

The problem is that I have two cells in the table (Repeat and Snooze). When the user clicks Repeat, it should take them to the Repeat View Controller, when the user clicks the Snooze cell, it should take them to the Snooze View Controller. So to handle this, in addition to the above mentioned "automatic" segue, I am also manually handling firing of Segue in didSelectRowAtIndexPath().
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        if (indexPath.item == 0)
        {
            performSegueWithIdentifier("repeatDaysSegue", sender: indexPath.item)
        }
        else if (indexPath.item == 1)
        {
            performSegueWithIdentifier("snoozeSegue", sender: indexPath.item)
        }
    }

Open in new window

It seems to be working OK, but now when the user clicks on the Repeat cell, you can see two Segues happen in the UI. Also, prepareForSegue() gets fired twice. First time the sender is a UITableViewCell, second time sender is Int.

The class code is below, what am I doing wrong?

class AddEditAlarmViewController: UIViewController, UITableViewDelegate, 

Open in new window

0
I am fairly new to iOS programming in Swift and have been unable to figure out how to set simple scene transitions. I have created a segue from a button on one scene to another but the transition is (by default) the scene loading in coming up from the bottom of the screen. I would like to set it to have the scene loading in coming from the right side of the screen to the left. How do I do this? I have found a few other answers to this question but they all seem to be from Swift 1 or Objective C and no longer work in Xcode 7 or Swift 2.
0
I have an app that is loading a JSON file from a remote server, it parses the JSON and add the records to various arrays, this piece is working just fine.  However, I cannot get the tableview to reload the data.

I'm pretty sure I need to use a dispatch at some point but I'm not sure where the following code should go, or even if it's correct?

   
dispatch_async(dispatch_get_main_queue(), { () -> Void in
      self.tableView.reloadData()
    })

Open in new window


Here is the code where I am loading the JSON:

func getData(){
    // Retrieve the JSON file and parse into the tableview
    let filePath = <my URL here>
    let requestURL: NSURL = NSURL(string: filePath)!
    let urlRequest: NSMutableURLRequest = NSMutableURLRequest(URL: requestURL)
    let session = NSURLSession.sharedSession()
    let task = session.dataTaskWithRequest(urlRequest) {
      (data, response, error) -> Void in
      
      let httpResponse = response as! NSHTTPURLResponse
      let statusCode = httpResponse.statusCode
      
      if (statusCode == 200) {
        print("File downloaded successfully.")
        
        do{
          let json = try NSJSONSerialization.JSONObjectWithData(data!, options:.AllowFragments)
          
          if let requests = json["requests"] as? [[String: AnyObject]] {
            for request in requests{
              let customer = request["CustomerName"] as! String
              let theRequest = request["Request"] as! String
              let formName = 

Open in new window

0
Hi, I'm looking for a video tutorial series for Cocoa and Swift 2. I've searched high and low, but none that are current with Xcode 7.x and Swift 2. I've found a couple that are great, but most are Xcode 6 and Objective-C or iOS with Swift 1, but my question is specific - Xcode 7.x and Swift 2.

Does anyone have a link to a good tutorial series that meets those requirements?

Yes...I know that iOS is very similar to Cocoa, but I'd really like to find a tutorial set for Cocoa and not iOS.

Thanks,
Fulano
0

Swift Programming

1K

Solutions

4

Articles & Videos

2K

Contributors

Swift is a compiled programming language created for iOS, OS X, watchOS, tvOS and Linux development by Apple Inc. Swift is designed to work with Apple's Cocoa and Cocoa Touch frameworks and the large body of existing Objective-C code written for Apple products. Swift is intended to be more resilient to erroneous code ("safer") than Objective-C and also more concise. It is built with the LLVM compiler framework included in Xcode 6 and later and uses the Objective-C runtime, which allows C, Objective-C, C++ and Swift code to run within a single program. A second free implementation of Swift targets Microsoft's Common Language Infrastructure (a.k.a. .NET) and the Java/Android platform.

Top Experts In
Swift Programming
<
Monthly
>