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

hi am having this error when running simulator
2019-08-14_18-31-00-62e25400bde035f0.png
0
Become a Microsoft Certified Solutions Expert
LVL 19
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Hi All

I'm currently developing an iOS app using the Contacts Framework to add contacts into a specific Group.

The code currently checks to see if the group exists, if it doesn't, it creates it and stores the Identifier into the UserDefaults store, if not it reads the identifier ready to save the contact later on.

let defaults = UserDefaults.standard
        var groupID = defaults.string(forKey: "contactsGroupID")
        let group = CNMutableGroup()
        var newGroupNeeded = Bool()
        
        if groupID?.isEmpty ?? true {
            let groupName = "my App Contact Group"
            let groupSave = CNSaveRequest()
            let newGroupNeeded = true
            group.name = groupName
            groupSave.add(group, toContainerWithIdentifier: nil)

            do {
                try store.execute(groupSave)
               defaults.set(group.identifier, forKey: "contactsGroupID")
               defaults.set(groupName, forKey: "contactsGroupName")
                print("New Identifer saved: \(group.identifier)")
            } catch let error{
                print(error)
                print()
            }
        }
        else {
            let newGroupNeeded = false
            
            let groupName = defaults.object(forKey: "contactsGroupName")
            var predicate: NSPredicate? = nil
            if let object = [
                defaults.object(forKey: "contactsGroupID")
                ] as? [String] {
                predicate = 

Open in new window

0
The variable is empty outside the DispatchQueue.main.async and I dont know what to do exactly.
Im trying to make this work from so many days but I gave up now.

Please help...


func createData(request:Crudpb_CreateRequest) -> String {
    DispatchQueue.main.async {
        self.response = try! self.client.create(request)

        print("This is response 1: " + self.response.result) // <-------- This is priting the right response
    }
    print("This is response outside DispatchQueue: " + self.response.result) // <------- This is not printing anyvalue
    return self.response.result // <------ This is not
}

Open in new window

0
I'm following this tutorial: https://medium.com/swift2go/building-grpc-client-ios-swift-note-taking-app-6133c7d74644
The problem is I can't understand what exactly is happening in the following code:

func listNotes(completion: @escaping([Note]?, CallResult?) -> Void) {
        _ = try? client.list(Empty(), completion: { (notes, result) in
            DispatchQueue.main.async {
                completion(notes?.notes, result)
            }
        })
   }

Open in new window


I need someone to explain me the above piece of code in detail.
Can anyone please help?
0
I am looking for a way to add an identity to the "Visual Effect View With Blur" for IOS Swift.  I also want to add rounded corners to the Visual Effect View with Blur.  I dragged it onto my ViewController and I am not sure how to round the corners nor how to identify the Visual Effect with an identity.  The reason why I want this functionality is because I need to round the corners or add code to round the corners in Swift.
0
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
We are developing customized iOS app for our customer and our Customers are like organization they have their own customers.
in short we are developing iOS app for customers of our customer (B2B).

Now my question to our experts are
1. What kind of developer program I should opt for?
2. What is volume purchase program?
3. Will Volume purchase program affect me in any way?
4. What kind of precaution I should be taking in such kind app?
5. Does apple allow such apps?


Please Help Me

Thanks in advance.
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
Learn SQL Server Core 2016
LVL 19
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

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
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
>