[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

Swift Programming

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

I am very new to Swift so please forgive me if I get some terminology incorrect etc.

I have created a todo list which first lets you add a category and then you can tap into the category and add items to the category. I am using Realm as the database.

I am able to delete individual items and individual categories, but when I delete a category and there are list items still in that category, I want it to also delete the items associated with that category.

This is to delete an individual item:

        if let item = todoItems?[indexPath.row] {
            do {
            try realm.write {
                realm.delete(item)
            }
            } catch {
                
                print("error deleting item, \(error)")
            }
        }

Open in new window


And this is to delete a category:

 
       if let categoryForDeletion = self.categories?[indexPath.row] {
            
            do {
                try self.realm.write {
                    self.realm.delete(categoryForDeletion)
                    
                }

            } catch {

                print("Error deleting, \(error)")
            }
        }

Open in new window

0
Build an E-Commerce Site with Angular 5
LVL 12
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

How to animate tableview row actions when swiped for iOS 10 and below ? . i want to achieve the same  like the iOS  mail app animations bringing one view behind other
0
I need help troubleshooting a firestore query into array.

https://stackoverflow.com/questions/51433177/firestore-query-array
0
I had a problem with UITableView Lagging on Scroll when there were long non-English (Persian) text in the cell (list with more than 40000 items and text with more than 1500 chars wont lag if they are English ) so I came up with this only solution that worked for me to keep the cells in an Array (just the non-English Ones) and reuse them myself instead of dequeuing again (will use normal pattern with other cell types) it works just perfect when the data is already added for the first time , adding a new Data no matter of what type messes up the table. here's the code :

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


            if(dataIndex[indexPath.row].cell == nil)
            {
                let cell = tableView.dequeueReusableCell(withIdentifier: "ChatRightTextCell", for: indexPath) as! ChatRightTextCell


                cell.configureCell(indexPath: indexPath)
                dataIndex[indexPath.row].cell = cell
                return cell
            }
            else
            {
                let cell = dataIndex[indexPath.row].cell
                cell.configureCell(indexPath: indexPath)
                return cell
            }

        }

note that the Table and the cells are transformed by 180 degree so the cells are stacked from bottom , so adding a new Item to the table be like :

dataIndex.insert(newData,at:0)
tableview.reloadData()


at ViewController start there's a 'for' …
0
We have some IOS app developers who have made a app for IOS (IPA package). They have send the IPA file to me, and they have signed it with their own developer certificate - and say that we must sign it with our own, before we can deploy it.

We are using Intune with SCCM (hybrid) and SCCM I know very well how to deploy and stuff. But do any have some input how we should do this ?. It must be noticed, the App must not be on "app store". It is a local company app that we want to deploy to company phones etc, so outside App store

Can any give some input on this ?

Another note. I tried to put the Ipa on a phone through apple configurator 2. It install, but afterwards the icon stay "grey" - and when trying to click on it, the error comes that the application cannot be installed.  Must the app not work through apple configurationer with manual installation ? - or has this also something to do with the developer signing etc ?
0
Thanks for taking the time to read this. I'm confused on how to insert a comment using the YouTube API. I'm fairly new to using APIs, so I don't quite get what they are saying to do in their documentation.

I've authenticated the user using Google Sign-In for iOS with the scope

    "https://www.googleapis.com/auth/youtube.force-ssl"

Open in new window


which is required to insert a comment. But now, I have to actually insert the comment and (like I've said) I don't understand how to do that. I'm using Alamofire for the request and Swift 4 as my language. I would highly appreciate it if someone could help me.
0
I saved CNContact in the form of vcf in the directory using following code

func generateVCard(for list: [CNContact]) {
        guard let directoryURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first else {
            return
        }

        var filename = NSUUID().uuidString

        // Create a human friendly file name if sharing a single contact.
        if let contact = list.first, list.count == 1 {

            if let fullname = CNContactFormatter().string(from: contact) {
                filename = fullname.components(separatedBy: " ").joined(separator: "")
            }
        }

        let fileURL = directoryURL.appendingPathComponent(filename).appendingPathExtension("vcf")

        let data: Data?
        do {
            data = try CNContactVCardSerialization.data(with: list)
            let documentDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
            let fileURLInDevice = documentDirectory.appendingPathComponent(filename).appendingPathExtension("vcf")

            do {
                try data?.write(to: fileURL, options: [.atomicWrite]);

                if let cnData = data {
                    //save to directory
                    try cnData.write(to: fileURLInDevice)

Open in new window


then I used the following code the to retrieve it back

let fileManager = FileManager.default
        let nsDocumentDirectory = FileManager.SearchPathDirectory.documentDirectory
        let nsUserDomainMask = FileManager.SearchPathDomainMask.userDomainMask
        let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
        guard let dirPath = paths.first else {
            return
        }
        let filePath = "\(dirPath)/\(fileName).vcf"
        do {
            let vc = ContactListTableViewController()
            if let data = fileManager.contents(atPath: filePath) {
                vc.contactsList = try CNContactVCardSerialization.contacts(with: data)

Open in new window


in this whole process i loose the imageData of each CNContact
0
While uploading an iOS Application,Xcode Shows Application uploaded Successfully.but it is not Shown in iTunesConnect. Is there any solution?
0
I am a beginner to Xcode and Swift and I am currently creating an application where the user adds a person on the application and after that it right the amount of money they owe that person or that person owes him/her.

Note: I have used core data to store all the value

I have ViewController called PeopleTableViewController where the user adds the name of the person they owe. Then I have PersonDetailTableViewController which shows the list of details the user owes that particular person the selected in PeopleTableViewController. The problem I am facing is that if I add three people in PeopleTableViewController and when I select any one of the people then I am directed to same tableview in PersonDetailTableViewController but I want different tableviews for different person the user selects in PeopleTableViewController.

PersonDetailTableViewController:
import UIKit

class PersonDetailTableViewController: UITableViewController {

    let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext


    var totalLabel: UILabel?
    var person: People?
    var owe: Owe?

    @IBOutlet var personTable: UITableView!

    var dataInfo: [Owe] = []
    var selectedObject: [Owe] = []
    var balanceAmount = "Balance: "

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return (dataInfo.count)
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: 

Open in new window

0
I need to integrate Apple Pays decrypted Payment Token Format into a Stripe Rest API call. This does not require any Stripe SDK's or JS files. The raw apple pay token information has already been decrypted ready for stripe to process via 'Source', 'Token', 'Charge' etc. Stripe support will not disclose the solution but acknowledge its possible, why, i am not sure? Spreedly does exactly as i am describing with Stripe, passing in the information below, but how is it correctly structured?

This is the what a decrypted Apple Pay payment token format looks like:

{"applicationPrimaryAccountNumber":"4xxxxxxxxxxxxxxx","applicationExpirationDate":"211130","currencyCode":"840","transactionAmount":1000,"deviceManufacturerIdentifier":"000000000000","paymentDataType":"3DSecure","paymentData":{"onlinePaymentCryptogram":"/random+stuff=","eciIndicator":"7"}}
payment-token-reference.jpg
0
OWASP: Avoiding Hacker Tricks
LVL 12
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

When photo app is opened, I want get event so that I can launch my app. Is there a way to do that?
0
Supposing I am using an AVPlayer to play a HTTP Live Streaming (HLS) with forced WebVTT subtitle. Is it possible for the app to access the Strings displayed by the AVPlayer and for example print them in the console?
0
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
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

Swift Programming

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
>